Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Is ANTLR appropriate for building a line-oriented preprocessor like the C preprocessor or m4?

0
Posted

Is ANTLR appropriate for building a line-oriented preprocessor like the C preprocessor or m4?

0

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123