[antlr-interest] Removing nil nodes from tree

Todd Nine tnine at apigee.com
Sat Mar 17 12:23:41 PDT 2012


Hi Eric,
  It was an ID10T error on my part!  In my subclassing of CommonTree, I
accidentally forgot to pass the token to the parent class via "super(t)".
 As a result, all boolean and equality expression nodes were returning true
when "node.isNil()" was invoked.  Hence they were not properly replacing
nil nodes as the tree was constructed.  After fixing this, everything is
working properly.  Once I'm done, I think I'm going to create a blog post.
 Even with all the reading I've done and the examples, I find there's no
complete example that's larger than trivial.  This has been a great
learning experience, and I'd like to contribute what I've learned back to
the community to make it easier for others to learn how to create basic
grammers and visiti their own ASTs.

Thanks,
Todd

On Sat, Mar 17, 2012 at 12:04 PM, Eric <researcher0x00 at gmail.com> wrote:

> Hi Todd,
>
> If you can make either all or enough of the code available to recreate the
> problem, including the driver I will see if I can prune out the nil nodes
> for using API calls. I can't promise an answer only help.
>
> Eric
>
> On Sat, Mar 17, 2012 at 1:13 PM, Todd Nine <tnine at apigee.com> wrote:
>
>> Hi Eric,
>>   Mostly a problem. They are remnants from the grammar tree where
>> operator precedence has occurred.  Or->and->not->equality operand.
>>
>> I've subclassed CommonTree for my nodes, and I'm using the visitor
>> pattern to walk the AST and perform the logic to query our Cassandra
>> indexes and return results.  With the nil nodes present, I have to create
>> my own CommonTreeAdapter as well as a nil class for visitor implementation
>> and traversal. If I can just remove them via an option, I won't have to add
>> this extra code.
>>
>> Thanks again for all the help!
>>
>> Todd
>>
>> On Mar 17, 2012, at 7:48 AM, Eric <researcher0x00 at gmail.com> wrote:
>>
>> Hi Todd,
>>
>> Are the nil nodes causing you a problem or are they just astetically
>> unpleasing?
>>
>> Eric
>>
>> On Sat, Mar 17, 2012 at 1:38 AM, Todd Nine <tnine at apigee.com> wrote:
>>
>>> Hi all,
>>>  I now have my AST generating node classes for my tree.  However, I have
>>> one final issue.  nil nodes are included in my tree after parsing is
>>> complete.  They appear in trees due to operator precedence.  Is it
>>> possible
>>> to remove nil nodes as the tree is generated?
>>>
>>> Thanks,
>>> Todd
>>>
>>> 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