[antlr-interest] Best way to match tokens one at a time?

Brian Smith brian-l-smith at uiowa.edu
Sun Jul 7 21:37:28 PDT 2002


I have developed a tool for reading in textual descriptions of software 
models into a repository. My tool can also serialize the contents of the 
repository back into the textual notation.

I have already built the parser for the language using ANTLR. Now, I 
would like to reuse the lexer during the serialization phase.

For example, I have two types of identifier tokens:

UNQUOTED_NAME
         :   ('A'..'Z' | 'a'..'z')
             ('A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '.')*
         ;

QUOTED_NAME: '"'! (~('"'))* '"'!
         ;

When generating code, I can always use the quoted form. But, the 
generated code is much easier to read if I use the unqoted form whenever 
possible. So, I would like to ask the lexer if an identifier can be left 
unquoted, by saying something like "dear lexer, does this string 
(instance of java.lang.String) match the lexer rule UNQOTED_NAME?".

I want to do this on a token-by-token basis and it needs to be pretty 
fast. What is the best way to go about doing this?

Thanks,
Brian


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list