[antlr-interest] C# generated code refering rules

Johannes Luber jaluber at gmx.de
Thu Jul 5 14:20:40 PDT 2007


Gavin Lambert wrote:
> At 00:06 6/07/2007, Johannes Luber wrote:
>>The problem is simply that rule names are translated 1:1 into
>>function names. The workaround for now is to change the rule
>>in the grammar into something else. For consistency of rule
>>naming use the source I mentioned in my lats email's PS. This
>>problem appears also if you happen to use a member name of
>>the parser class like "input".  Unfortunately
>>Terence didn't integrate a name mangling option yet which would
>>prefix all rule names in functions.
> 
> There is a standard mangling scheme for the lexer; and I think the C
> target does some extra mangling of its own anyway :)
> 
> But in any case, the C# code generator could work around this by using
> the @ prefix.  (ie. @class is always an identifier, never a keyword.) 
> Ideally, it should only quote the ones that actually need it (by being
> in the keyword list), but I'm not sure how easy that is to do in
> StringTemplate.  Failing that it could just quote everything ;)
> 

Your suggestion doesn't work in general, as "@(" is not a valid
identifier. It would work though to put for all token names, as they are
generated right now, although it considered to be a bad style to use
e.g. "@id". And this doesn't solve all collisions like for "input".

Best regards,
Johannes Luber


More information about the antlr-interest mailing list