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

Jim Idle jimi at temporal-wave.com
Thu Nov 5 16:37:29 PST 2009



> -----Original Message-----
> From: FranklinChen at cmu.edu [mailto:FranklinChen at cmu.edu]
> > So first, here is your grammar rewritten without anything but
> standard rewrite rules (lexer skipped and compressed for space). You
> can see that this is somewhat, err... 'simpler' ;-)
 
> Unfortunately, the stripped down grammar you propose is completely
> inequivalent to mine (and mine was a stripped down version of the much
> more complicated version in my real program, in which I have multiple
> alternatives and cases and decisions on what type of tree to create).

Produces the same tree ;-). But really the point was to highlight that there is nothing wrong with the stream and that a simple example shows you how to do the tree building yourself.

> 
> Your code results in:
> 
> tree = (TIER (WORD a (PHO 0)) (WORD b (PHO 1)) (WORD c (PHO 2)) (WORD d
> (PHO 3)))


> Exception in thread "main"
> org.antlr.runtime.tree.RewriteCardinalityException: token d
> 	at
> org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElemen
> tStream.java:165)
 
> so it behaves nothing like my production code.

Well, I said you needed to do conditional rewrites right? When they imbalance the rewrite streams will throw exceptions, which is all that is happening here.
> 
> So I think the right thing for me to do is to study the generated code
> for rewrites and mimic the use of the adaptor APIs to link up the
> trees correctly.

Yes - this is what I was getting at basically.

Jim





More information about the antlr-interest mailing list