[antlr-interest] Bug in Generated Parser?

Gavin Lambert antlr at mirality.co.nz
Thu Jul 17 14:05:59 PDT 2008


At 00:51 18/07/2008, Johannes Luber wrote:
 >> I'm seeing different behavior running my parser with a syntax
 >> error the second time run. I've tracked it down to where I
 >> believe the problem is, located in BaseRecognizer.cs. The
 >> "follow.Remove( Token.EOR_TOKEN_TYPE )" logic is being
 >> called, which modifies the state of the static readonly
 >> BitSet object found on the parser. The problem with that
 >> is that even though I am creating a completely different
 >> parser instance, the static variable has been altered for
 >> as long as the assembly is in memory. I've copied a simple
 >> program to illustrate the problem at the bottom of this mail.
 >
 >I haven't heard of it yet, but it's a Java target problem, too,
 >so Ter has to say, if removing the static modifier for the
 >BitSet variables in the parser is enough and doesn't affect
 >anything else.

I don't think that's sufficient -- after all, a single instance 
might be re-used, or the rule-path followed might query that 
structure again (expecting it to be in its unmodified state).

Read-only variables should never be modified.  Any code that is 
doing so is clearly erroneous.  (Perhaps it should be modifying a 
clone of the object instead of the original?)



More information about the antlr-interest mailing list