[antlr-interest] Help with simple parser?
Chris Bergstresser
chris at subtlety.com
Sat Jan 25 20:36:41 PST 2003
Hi all --
I've got a very simple grammar, but I keep getting recursion errors. I
don't know enough to fix it. My rules look like:
expr : LPAREN! sumExpr RPAREN! ;
sumExpr : prodExpr ((PLUS^|MINUS^) prodExpr)* ;
prodExpr : minMaxExpr ((MUL^|DIV^|MOD^) minMaxExpr)* ;
minMaxExpr: ((MIN^|MAX^) LPAREN! minMaxExpr COMMA! minMaxExpr RPAREN!) |
ifExp;
ifExp : (IF^ LPAREN! ifExp COMMA! atom COMMA! atom RPAREN!) | atom;
atom : INT | STAT | expr;
...but I don't want the parentheses around expr to be mandatory. I'd
also like to enforce the same number of opening as closing parentheses. As
it stands now equations like "(if(1, 2+3, 4))" won't parse, because the
"2+3" need wrapping parenthesis. Obviously, I'd like "if(1, 2+3, 4)" to be
valid, as well. I've wandered -- rather uselessly -- through most of the
examples. Could someone help?
-- Chris
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list