You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
548 B
29 lines
548 B
grammar MExpr;
|
|
|
|
options {
|
|
language = Perl5;
|
|
}
|
|
|
|
prog: stat+ ;
|
|
|
|
stat: expr NEWLINE { print "$expr.value\n"; }
|
|
| NEWLINE
|
|
;
|
|
|
|
expr returns [value]
|
|
: e=atom { $value = $e.value; }
|
|
( '+' e=atom { $value += $e.value; }
|
|
| '-' e=atom { $value -= $e.value; }
|
|
)*
|
|
;
|
|
|
|
atom returns [value]
|
|
: INT { $value = $INT.text; }
|
|
| '(' expr ')' { $value = $expr.value; }
|
|
;
|
|
|
|
ID : ('a'..'z'|'A'..'Z')+ ;
|
|
INT : '0'..'9'+ ;
|
|
NEWLINE:'\r'? '\n' ;
|
|
WS : (' '|'\t')+ { $self->skip(); } ;
|