Is ANTLR appropriate for building a line-oriented preprocessor like the C preprocessor or m4?
Location: http://www.jguru.com/faq/view.jsp?EID=893706 Created: May 27, 2002 Modified: 2002-05-27 12:23:21.181 Author: Terence Parr (http://www.jguru.com/guru/viewbio.jsp?EID=1) Greg Lindholm points out: ANTLR doesn’t have a way of specifing start-of-line as part of a rule. Once you have entered a rule you can use a sematic predicate to check what column your at, but this probably doesn’t help you. IMHO ANTLR is not well suited for writing a preprocessor as; 1) Preprocessors are line-oriented and ANTLR isn’t. 2) The output of an ANTLR lexer is a token stream where the output of a preprocessor is a character stream (or file) that then gets fed into a lexer. Terence adds: This is similar to building an HTML lexer/parser. You want to match tags, but what do you do with all the text surrounding the tags? Well, I have built lexers that lump all that so-called CTEXT into a single big token. This may not be optimal, but works pretty well. Concerning the preprocessor, a strategy that you may w