[antlr-interest] How to write parenthesized expression grammar??
rmsanjivp <rmsanjivp at yahoo.com>
rmsanjivp at yahoo.com
Thu Jan 30 11:52:57 PST 2003
Hi for the following grammar:
topLevel : expr;
expr : mult_expr ( (PLUS | MINUS) mult_expr)*;
mult_expr : pow_expr ((MULT | DIV) pow_expr)*;
pow_expr: primary_expr ( POWER pow_expr)?;
primary_expr: ID | (LPAREN! expr RPAREN!) | NUM
;
If I give input as (1+2)) then it is taken as a legal input and ast
gives nodes for 1, 2, and +. This is wrong as there is unmatched
right paranthesis. The problem is happening because of RPAREN being a
valid look ahead in method pow_expr() in the generated file after
method primary_expr().
What grammar should I write for paranthesized expression That can
support (1+2)*(3+4 - (4*5))+4
Please help.
Thanks,
Sanjiv
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list