Fwd: [antlr-interest] C++ parser usage ideas

Akhilesh Mritunjai virtualaspirin at yahoo.com
Thu Oct 13 09:21:19 PDT 2005


Preprocessor macros are one of the most PITA in
languages that support them. Only options are-

1. Use external macro processor and pipe its output in
your compiler/IDE

2. Write your own.

(2) is pretty hard to do as preprocessors are
character and line oriented, rather than token
oriented. So if you're, in special cases, able to use
a lexer, you'd have to lex the output of preprossor
again. But it is the only option you have if you also
want original line/column info.

--- Jim Crafton <jim.crafton at gmail.com> wrote:
> syntactically correct. So the
> only solution (as I understand it) is to either put
> logic in the C++
> grammar to gracefully skip over macro bits (which is
> understandably
> pretty hard to do), or pre-process it first before

Rather next to impossible. C preprocessor is one of
the most 'hard to get right' ones. You can do stuff
like

#define CONCAT(A, B) A##B

CONCAT(cl, ass) CONCAT(some_, class) {
  CONCAT(pr, ivate):
    CONCAT(i, nt) i;
};

which generates-

class some_class {
  private:
    int i;
};

Disgusting, ain't it ?? :=|

- Akhilesh




		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


More information about the antlr-interest mailing list