[antlr-interest] duplicate int values in the token definition file

Christian chwchw at gmx.de
Fri Jan 20 05:02:53 PST 2012


Ok, I inserted the following action code before the 'get'
    {System.err.println("next int: "+input.LA(1));}

and got:
    next int: 75

This type corresponds to the IDENTIFIER token. It is correct that all
non-keywords should be treated as IDENTIFIER by the lexer. However, I
thought that literals in a combined grammar are prioritized. Do I really
have to replace all literals in the parser rules with a corresponding
token and place it before the IDENTIFIER lexer rule? I hope not...

Regards,
Christian

Am 20.01.2012 12:39, schrieb Christian:
> Hello community,
>
> I have a combined C# grammar and get the following error, while
> executing the parser on a C# source file:
>     attrs: null
>     mods: null
>     resource/Console.cs line 138:6 no viable alternative at input 'get'
>
> within the following rule:
>     accessor_declarations
>   : attrs=attributes? {System.err.println("attrs: "+$attrs.text);}
>     mods=accessor_modifier? {System.err.println("mods: "+$mods.text);}
>     ( 'get' {System.err.println("get");} accessor_body
> set_accessor_declaration?
>     | 'set' accessor_body get_accessor_declaration?
>     )
>   ;
>
> If I define 'get' as explicit token using the tokens section, the same
> error for another such a literal occurs. I have looked at the token
> definition file. It contains among other things the following
>     T__246=246
>     'get'=246
>
> I admit that I do not know for what the T__ are defined. Can somebody
> explain and tell a reason for this behavior?
>
> Regards,
> Christian
>
> 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