[antlr-interest] Preprocessor implementation

Johannes Luber jaluber at gmx.de
Mon Nov 19 15:50:58 PST 2007


Hi,

it occurred to me that a special case isn't handled so far correctly:

#if SYMBOL
/* This is a comment.
 #error This preprocessor directive will be only recognized with an
undefined SYMBOL
 # Sadly is this no preprocessor directive
*/
#endif

If SYMBOL is defined then the comment in the section is a comment, if
SYMBOL is undefined then the comment is treated as text blob, only
broken up by other preprocessor directives. As those start with '#', the
harmless number sign blows the compilation up when it isn't followed by
magic sequences.

How can I lex these cases correctly? Depending on circumstances, one and
the same input can create different tokens. I have to check for #define
and #undef while lexing. Can this be done by ANTLR?

Johannes



More information about the antlr-interest mailing list