[antlr-interest] ANTLR Two Simple Questions :-)

Jim Idle jimi at temporal-wave.com
Mon May 17 09:54:43 PDT 2010



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Sameh W. Zaky
> Sent: Monday, May 17, 2010 7:33 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] ANTLR Two Simple Questions :-)
> 
> Dear All,
> 
> I am a Masters student, I use Java, and I am trying to make my parser
> with
> the help of ANTLR. I need this for my Masters project.
> I am using ANTLRWorks 1.3.1
> I had 2 questions concerning it:
> 
> 1) How can I have a dynamic token name (or dynamic lexer)?
> *Example: (the symbol SERVICE, will have different token values,
> depending
> on certain list (array) whose contents change over time)*

Match the possible sequences generally, then change the token type if the strings match your dynamic list:

fragment SERVICE : ;
ID : ('a'..'z')+
    {
       If (myLookupMethod($text)) { $type = SERVICE; }
    }
  ;

So the token ID will be returned if the matched text is not in your list and the token SERVICE will be returned if it is.


> 2) Given a certain grammar, how can I (or: is it possible to) get the
> list
> of all possible next tokens? 

Read: http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery 

Do I get a masters too? ;-)

Jim





More information about the antlr-interest mailing list