[antlr-interest] Simple grammar will not compile. I can't figure it out.

Andreas Meyer andreas.meyer at smartshift.de
Wed Mar 11 10:23:28 PDT 2009


It seems that ANTLR's error messages could be improved in this case .... 
DataPath is a lexer rule, because of ANTLR's naming conventions: 
everything starting with a capital letter is a lexer rule. And as such, 
it only can refer to other lexer rules (or fragments). But, keypath 
(because of its lowercase spelling) is a parser rule and therefore not 
visible to the lexer. So, I guess you could just turn DataPath into 
dataPath, so that it becomes a parser rule (if that's your intention).

Best,
Andreas

Stevenson, Todd (GE Healthcare, consultant) schrieb:
> This grammar will not compile.  I can't figure out why not.  It 
> generates the error:
>  
> reference to undefined rule: keypath
>  
> even though it exists.  Help!
>  
> Thanks.
>  
> ------------------------------------------------------------------------------------------------------------------------
> grammar cepath;
>  
> options {
>  output=AST;
>  ASTLabelType=CommonTree;
> }
>  
>  
>  
> start
>  : cpath EOF
>  ;
>  
> cpath 
>  : KEY keypath
>  | DataPath
>  ;
>  
> DataPath
>  : CODE keypath
>  ;
>  
>
> keypath
>  : SEP CODE
>  | SEP DOMAIN
>  ;
>  
>
> // $<lex
>  
> KEY    : 'key';
> CODE   : 'code';
> DOMAIN   : 'domain';
>  
>
> SEP  : '.';
> WS   :  ( '\r' | '\n')+ {skip();};
>  
> // $>
>  
>  
> ------------------------------------------------------------------------
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>   



More information about the antlr-interest mailing list