[antlr-interest] keyword as identifier problem

Andy Tripp antlr at jazillian.com
Thu Aug 30 12:38:58 PDT 2007


I'm doing the "keyword as Identifier" dance as described in the book.

So I've replaced this token...
TYPE='TYPE';
...with the parser rule:
keyTYPE:
    {input.LT(1).getText().equalsIgnoreCase("TYPE")}? Identifier
    -> TYPE
    ;

When I have this parser rule:
typeDeclaration:
    optionalModScopeDecl keyTYPE Identifier eos
    ( anyVariableDeclaration[$optionalModScopeDecl.tree]? eos)+
    keyEND 'TYPE'
    ;

...it compiles just fine. But changing that 'TYPE' to keyType in the rule:

typeDeclaration:
    optionalModScopeDecl keyTYPE Identifier eos
    ( anyVariableDeclaration[$optionalModScopeDecl.tree]? eos)+
    keyEND keyType

...causes ANTLR to generate code that doesn't compile:

ANTLR Parser Generator  Version 3.0 (May 17, 2007)  1989-2007
VBParser.java:30483: cannot find symbol
symbol  : variable $optionalModScopeDecl
location: class VBParser
                anyVariableDeclaration($optionalModScopeDecl.tree);

It looks like an ANTLR bug to me. Any ideas?

Andy





More information about the antlr-interest mailing list