[antlr-interest] Ignore reserved word and treat it as TOKEN

Jim Idle jimi at temporal-wave.com
Wed Mar 23 09:38:23 PDT 2011


1) Don't use literals in the parser, create lexer tokens;
2) Replace the use of ID with a non terminal id;
3) Implement as:


rule : KEY id something id SEMI;

id : ID
   | KEY
   | SOME
   | MORE
   | TOKENS
   ;

KEY : 'KEY' ;
etc


Occasionally, this can generate ambiguities which you can solve using k=1
option or a single token predicate:

r2: KEY (id=>id)? KEY KEY SEMI ;

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Hiten R
> Sent: Wednesday, March 23, 2011 9:20 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Ignore reserved word and treat it as TOKEN
>
> Hi,
>
>
> Working on this problem for two days and I don`t seem to be any closer
> than where I started.
>
>
> I have defined a combination of reserved words in grammar something
> like
>
> //grammar
> | 'ip' 'route' call_parser_method
> | 'some' do_something_else
>
>
> But when a parser encounters a line "some other line with ip text" it
> treats ip token as a reserved word and it tries to look for a 'route'
> after ip and finds 'text'. How do I get around this problem?
>
>
> Any help would be appreciated.
>
>
> Thx
>
> Hiten
>
> 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