[antlr-interest] ASTPair handling in C# runtime for 2.7.6
luisl at scarab.co.za
Thu Oct 27 03:14:15 PDT 2005
I haven't experienced the problem you described in the other message. I
guess a struct makes more sense at this point then.
The _saveIndex optimization only declares _saveIndex when needed.
The trouble is that the C# standard does not allow local variable
redeclarations in nested blocks (even if the definition of local variable in
the outer block occurs after the declaration in the nested block):
"It is an error for two members of a local variable declaration space to
have the same name. It is an error for the local variable declaration space
of a block and the local variable declaration space of a nested block to
contain elements with the same name. [Note: Thus, within a nested block it
is not possible to declare a local variable or constant with the same name
as a local variable or constant in an enclosing block. It is possible for
two nested blocks to contain elements
with the same name as long as neither block contains the other. end note]"
The code generator currently generates code like this:
int _saveIndex=0 // Error! It has already been declared in the
So _saveIndex should only be declared once in the outer block and then used
in the inner block. I don't think it's possible to predict in the code
generator that _saveIndex will be used in a nested block? Personally I'm not
sure this is worth all the effort. Perhaps we should just stick to the way
the Java generator does it - once at the beginning of the method? The
optimization has the side-effect that many _saveIndex variables are declared
that take up more memory than just declaring it once at the beginning.
More information about the antlr-interest