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

FranklinChen at cmu.edu FranklinChen at cmu.edu
Thu Nov 5 16:20:30 PST 2009


Sam Harwell writes:
> 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.

For the record, this was a orders-of-magnitude stripped down version
of my actual program, in which I create a huge PHO tree, hence my
introduction of the dummy node; also, depContent creates other kinds
of trees, depending on conditions, other than PHO.

> * In your @after blocks, if you reference a parameter like it, you
> should use $it instead of just it.

Thanks, I am making this correction everywhere relevant.

> * I think TIER[c.tree.getToken(), "TIER"] should be
> TIER[$c.tree.getToken(), "TIER"]

Yes, you are right.

> * 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.

Yes.

> * 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.

The problem is that I need to do a lot of tree restructuring before I
arrive at a canonical AST that is used by many different tools.  I can
think of no better place to do it than in the parser.  In this
specific toy example, the restructuring involved is taking two lines
of text with various directives within them and then merging them
"word" by "word" like a zipper.

-- 
Franklin


More information about the antlr-interest mailing list