[antlr-interest] Parse trees
Adrian Sandor
aditsu at yahoo.com
Sat May 17 14:59:32 PDT 2008
Hi, I'm using antlr 3 and trying to get a parse tree.
I followed the instructions from http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760 and I have some questions:
- in the example from that page, why does the parser accept a statement ending in a semicolon? ("i=4;")
- I modified the grammar to this:
grammar P;
prog: decl* stat* ;
decl: type ID (',' ID)* ';' ;
type: 'int' | 'float' ;
stat: ID '=' expr;
expr: OP* simple (OP+ simple)* OP*;
simple: INT;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
OP: '+'|'-';
WS : (' '|'\n')+ {$channel=HIDDEN;} ;
and the input to this:
int i;
i=1+ -2+3
This time it complained about a semicolon in the statement, so I removed it. But the problem is that the resulting parse tree looks like this:
(<grammar prog> (prog (decl (type int) i ;) (stat i = (expr (simple 1) + - 2 + - (simple 2) + 3 + (simple 3)))))
What's going on? Is this a bug?
Thanks
Adrian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080517/9a70eb20/attachment.html
More information about the antlr-interest
mailing list