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

Jim Idle jimi at temporal-wave.com
Fri Jan 20 10:41:35 PST 2012


Don't use literals in the parser grammar - this gets you in to a lot of
trouble when you are starting out. It is the work of maybe an hour or so
to move to 'real' tokens - bite the bullet now.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian
> Sent: Friday, January 20, 2012 5:03 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] duplicate int values in the token
> definition file
>
> 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
> >
>
>
> 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