[antlr-interest] Suggestion for simplifying a parser grammar

dotlessbraille easjolly at ix.netcom.com
Wed Dec 10 17:08:23 PST 2003


I've discovered a useful strategy for simplifying a parser grammar. 
In my application I need the lexer to make distinctions that are 
significant to the tree analysis but not to the parser.  That is, if 
the parser grammar were to make direct use of the token types from 
the lexer, it would need rules like:

id: (A|B|C|D|E|F)+;

I've found it convenient to simplify the parser grammar by using a 
filter to change some of the token types identified by the lexer.  
The previous rule now looks something like: 

id: (X)+;

The actual lexer token type is squirreled away in a sub-classed 
Token for use in the tree analysis.

(The documentation shipped with ANTLR discusses the necessary 
mechanisms for filtering a TokenStream and extending Token.)

S. J.



 

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




More information about the antlr-interest mailing list