[antlr-interest] c runtime with templates

Jim Idle jimi at temporal-wave.com
Fri Feb 13 09:32:44 PST 2009


Carter Cheng wrote:
> Thanks for the reply.
>
> I did actually manage to find a semi workaround for this though it is a bit cumbersome (involves manually editing the extern "C" scopes in the tree grammar .h generated file). I am a bit of a C++ newbie and part of me is curious if this extern "C" stuff is really needed here since I am compiling everything with g++.
>
> Unfortunately given how the declarations look in the header it seems that since in certain cases I am returning stl types these show up in some of the generated structs in the header i suspect that #ifdefing them out of the header would mean the header would not compile.
>
>   
In the latest source I think that the #ifdefs are more selective, but 
you probably want to put your #includes inside @preincludes and not 
@header. Chack the docs on the various sections.  Also don't put any of 
your classes and things directly into the grammar, place them in .cpp 
files and the include the headers the define the classes in the 
preincludes sections. Then your classes won't be marked as extern "C". 
There are comments about the approach you take to structure in the 
examples - separate include that includes your headers and the 
parser/lexer headers and so on. Keep as much of your own code as 
possible out of the .g file and the generated headers basically.

Jim


More information about the antlr-interest mailing list