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: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Hiten R > Sent: Wednesday, March 23, 2011 9:20 AM > To: [email protected] > 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 List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
