[antlr-interest] Tree parser eats up DOWN node when navigating optional child node

Gerald Rosenberg gerald at certiv.net
Thu Aug 5 11:17:19 PDT 2010


  Indeed.  We should have pointed that out in response to the OP's 
initial post.

Best,
Gerald

------ Original Message (Thursday, August 05, 2010 9:11:07 AM) From: Jim 
Idle ------
Subject: Re: [antlr-interest] Tree parser eats up DOWN node when navigating
optional child node
> The root node of any tree needs to have a type, so ^( ^( makes no sense as
> what is the first root supposed to be?
>
> Jim
>
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of Gerald Rosenberg
>> Sent: Wednesday, August 04, 2010 10:09 PM
>> To: Junkman
>> Cc: antlr-interest at antlr.org
>> Subject: Re: [antlr-interest] Tree parser eats up DOWN node when
>> navigating optional child node
>>
>>    ------ Original Message (Wednesday, August 04, 2010 5:21:33
>> PM) From: Junkman ------
>> Subject: Re: [antlr-interest] Tree parser eats up DOWN node when
>> navigating optional child node
>>> You wrote "AST ^( ^( PARENT A ) B )".  Can you describe the tree this
>>> notates?  I can see it as a node sequence, but I don't know what tree
>>> structure it is describing.
>>>
>>> Thanks for the reply.
>>>
>>> Jay
>>>
>> The AST
>>
>> ^( ^( PARENT A? ) B? )
>>
>> should implement as
>>
>> ( ( PARENT Token.DOWN A? Token.UP ) Token.DOWN B? Token.UP )
>>
>> but is actually
>>
>> ( PARENT Token.DOWN A? B? Token.UP )
>>
>> Because parent_a is the root of parent, the parser is (for some reason)
> not
>> actually generating the middle Token.UP Token.DOWN sequence.  That
>> explains why P and PA work, but PB and PAB do not - after matching for A?,
>> the tree parser is looking for UP, but finding B.  Not sure why Antlr is
> doing
>> this - not expected.
>>
>> Changing A and/or B to non-optional does not change this behavior.
>>
>> If, however, you change the parent rule to
>>
>> parent : parent_a B? ->  ^( M parent_a B? )  ;
>>
>> where M is an imaginary token (and make the corresponding change to the
>> tree grammar), all four patterns will parse and match as expected:
>>
>> AST:
>>
>> ^( M ^(PARENT A? ) B? )
>>
>> properly implements as
>>
>> ( ( M Token.DOWN PARENT A? Token.UP ) Token.DOWN B? Token.UP )
>>
>>
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
>> email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list