Home | History | Annotate | Download | only in mexpr
      1 grammar MExpr;
      2 
      3 options {
      4   language = Perl5;
      5 }
      6 
      7 prog:   stat+ ;
      8                 
      9 stat:   expr NEWLINE { print "$expr.value\n"; }
     10     |   NEWLINE
     11     ;
     12 
     13 expr returns [value]
     14     :   e=atom { $value = $e.value; }
     15         (   '+' e=atom { $value += $e.value; }
     16         |   '-' e=atom { $value -= $e.value; }
     17         )*
     18     ;
     19 
     20 atom returns [value]
     21     :   INT { $value = $INT.text; }
     22     |   '(' expr ')' { $value = $expr.value; }
     23     ;
     24 
     25 ID  :   ('a'..'z'|'A'..'Z')+ ;
     26 INT :   '0'..'9'+ ;
     27 NEWLINE:'\r'? '\n' ;
     28 WS  :   (' '|'\t')+ { $self->skip(); } ;
     29