[antlr-interest] very simple doubt about EXPR grammar
Leonardo K. Shikida
shikida at gmail.com
Wed Oct 13 10:29:07 PDT 2010
Hi
This is something stupid, I guess. I have a grammar like this below
and I would like to know why
"1+1-1" works
and
"1-1+1" does not work (NoViableAltException)
Thanks
Leo K.
>>>>>>>>>>>>>>>>>
grammar Expr;
@header {
}
@members {
}
prog: stat+ ;
stat: comp NEWLINE
| NEWLINE
;
comp
: e=expr
( '>' expr
| '<' expr
| '=' expr
)*
;
expr
: e=multExpr
( '+' multExpr
| '-' multExpr
| '*' multExpr
| '/' multExpr
)*
;
multExpr
: atom
( atom
)*
;
atom
: INT
| ID
| '(' comp ')'
;
ID : ('a'..'z'|'_')+ ;
INT : '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS : (' '|'\t')+ ;
[]
Leonardo K. Shikida
More information about the antlr-interest
mailing list