[antlr-interest] question about tree parsing (2.x)
Monty Zukowski
monty at codetransform.com
Fri Jun 3 06:32:07 PDT 2005
Bryan Ewbank wrote:
> 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
> "+".
Instead of a syntactic predicate you could replace '.' with ~(ID4)
Monty
More information about the antlr-interest
mailing list