[antlr-interest] Strange bug in ANTLR version higher than 3.1.2

Sam Harwell sharwell at pixelminegames.com
Wed Nov 4 17:08:25 PST 2009


Hi Franklin,

You didn't say exactly what the bug was. That said, here's my feedback,
lots of it just my opinion not rules:

* Replace your call to {skip();} with {$channel = HIDDEN;}
* Replace ^(PHO[i, "pho"] $i) with just PHO[i, "pho"]. When you
construct the PHO token from i, it takes on the text and the token
start/stop positions of i, so the child node is redundant.
* In your @after blocks, if you reference a parameter like it, you
should use $it instead of just it.
* I think TIER[c.tree.getToken(), "TIER"] should be
TIER[$c.tree.getToken(), "TIER"]
* I'm pretty sure mainTier can initialize the wordList like this:
mainTier returns [ArrayList<CommonTree> wordList = new
ArrayList<CommonTree>()] and then leave out the @init block.
* When you're using a tree parser, try to move as much logic as possible
to the tree parser instead of the parser. If possible, you should shoot
for having a parser with no actions, parameters, or @init{} @after{}
blocks (obviously this is not always possible). If you meet this goal,
then your parser will work with any target without any changes.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of
FranklinChen at cmu.edu
Sent: Wednesday, November 04, 2009 5:49 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Strange bug in ANTLR version higher than 3.1.2

In a long-delayed ANTLR upgrade, I have encountered a strange bug that
has a critical impact on one of my large projects.

Some detective work showed me that my code works fine in ANTLR 3.1.1 and
3.1.2, but then 3.1.3 breaks it (and 3.2 also does not work).  I am not
sure what I am doing wrong, if anything.  I am doing some tree
manipulations in a parser.  I have created a smallest possible test
project to pinpoint and illustrate the difference in behavior.  I would
appreciate it if someone could tell me whether (1) ANTLR 3.1.3 and up
are higher are broken, in which case I must stick with 3.1.1/3.1.2, or
(2) I am not using the Tree API properly, and need to change the way I
am doing what I need to do.

Attached is an archive of my sample project.



More information about the antlr-interest mailing list