Hi there I have been trying to write a simple expression parser, here is the grammar.
grammar extremelysimplgrammar ;
stat : expr ;
expr : sub ;
sub : add ( '-' add )* ;
add : VAL ( '+' VAL )*
| VAL
;
VAL : [0-9]+ ;
[ \t\n\r]+ -> skip ;
It matches these expressions
1 + 1
0 + 3
4
But I do not want it to match single occurrence of VAL
. I want it to match 1 + 1
but not 4
. How do I do that ?