[antlr-interest] C++ doesn't like my tokens ...

Ric Klaren klaren at cs.utwente.nl
Mon Jul 5 08:30:30 PDT 2004


On Mon, Jul 05, 2004 at 03:29:40PM +0100, Anthony Youngman wrote:
> 	NULL="NULL";
>
> Which gives me a TokenTypes.hpp as attached. Note the line "NULL = 15,"
> - this causes g++ to blow up pretty badly.
>
> Obviously my keyword is being treated as a C++ keyword. I would guess,
> as a temporary measure I can manually mangle the keyword, but are there
> any other keywords that are likely to blow up? And if so, how do we
> handle it? Should Antlr do a little mangling of all keywords for
> safety's sake?

As Noel pointed out it's a preprocessor define (the good old C NULL
definition to be exact). Standard practice is to mangle it yourself, or use
the mangleLiteralPrefix = "MY_PREFIX_" option (at the expense of having to
use that prefix). Personally I do my own mangling. But sometimes you run
into some header file that does some inconvenient #define. #undef might
help but is sometimes just as bad as the #define itself.

Be wary of anything that looks like a C/C++ keyword things like CONST,
EXTERN, PARM, _P etc. those are often defined in header files for
multiplatform packages (tcl to name one).

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
  There are 10 kinds of people - those that understand binary and
  those that don't. --- Unknown



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list