Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar Calc;
- eval returns[value]
- : SPACE? expr SPACE? {$value = $expr.value;}
- ;
- expr returns[value]
- : me1=multExpr {$value = $me1.value;}
- (SPACE? '+' SPACE? me2=multExpr {$value += $me2.value;}
- |SPACE? '-' SPACE? me2=multExpr {$value -= $me2.value;})*
- ;
- multExpr returns[value]
- : a1=atom {$value = $a1.value;}
- (SPACE? '*' SPACE? a2=atom {$value *= $a2.value;}
- |SPACE? '/' SPACE? a2=atom {$value /= $a2.value;})*
- ;
- atom returns[value]
- : INT {$value = Number.parseInt($INT.text);}
- | '(' SPACE? expr SPACE? ')' {$value = $expr.value;}
- ;
- SPACE: [ \t]+;
- INT: [0-9]+;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement