[antlr-interest] question about tree parsing (2.x)
Bryan Ewbank
ewbank at gmail.com
Fri Jun 3 02:17:12 PDT 2005
Yes; you can do this; you are probably seeing ambiguity warnings about
the loop because both "ID4" and "." will match an ID4 node. The trick
is a syntactic predicate. Change this:
> bottomNode
> : #(
> ID3
> (
> ID4
> | . // catch all for ID5 | ID6
> ) // '+' volontary removed, exit should get 1 level up, no?
> )
> ;
To this:
> bottomNode
> : #(
> ID3
> (
> (ID4) => ID4
> | . // catch all for ID5 | ID6
> )+
> )
> ;
The "(ID4) => ID4" tells ANTLR to use that selection if an ID4 is seen.
I don't see why you removed the "+" unless you only want to match the
first child of ID3. To match all ID4 children of ID3, you need the
"+".
More information about the antlr-interest
mailing list