[antlr-interest] Are C++ STL instances safe to use with the C runtime?

Richard Lewis Richard.Lewis at ite.com.au
Wed Feb 11 16:24:40 PST 2009


Thanks! Having looked at the examples, I'm starting to think that using
pANTLR3_HASH_TABLE and pANTLR3_STRING might cause less pain. I don't
have a requirement to use STL but it seemed easier when converting from
JAVA. 

 

Looking forward to the C++ runtime. 

 

-Richard

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Thursday, 12 February 2009 10:57 AM
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Are C++ STL instances safe to use with the
C runtime?

 

Richard Lewis wrote: 

Hi, I just started the process of determining how to convert my JAVA
runtime based grammar into the C runtime. Will I run into memory
allocation issues if I embed STL? For example, in my current grammar I
use:

 

scope RScope {

                String name;

                HashMap<String,Enum> symbols;

}

 

If I translate this to:

 

scope RScope {

                std::string name;

                std::map<std::string, int> symbols;

}

Basically, so long as it gets by the ANTLR parser, then it will pretty
much be spit out as seen. However, you need to copy the code in the C
parser example to initialize anything in the scope that isn't automatic,
and also to register a freeScope() function that knows how to free
anything in the scope that isn't automatic. So you r symbol map probably
wants to be a pointer, which you create with new and delete it when the
scope is freed (it will call you back to tell you).

I will be updating the examples for 3.1.2 shortly, and this will show
you how to handle such things much more efficiently than the current
examples (which was really meant as a scope example rather than an
efficiency example.



 

Is this even going to compile? And if it does, will it blow up or leak
memory?


You might find that you have to typedef it to fool ANTLR in some cases,
but generally it will be OK. The output file will be a C file, but if
you compile it is as C++ then it should be fine. There are a couple of
bugs with rewrites and casts that are on my list to fix very soon, ready
for 3.1.2.



 

The second part of my question is: Will there be a C++ runtime available
in the near future?

Don't know how near because I keep getting pulled off into other things,
but I have been working on it. You should be fine with the C runtime but
please read through all the examples and the docs before going to far
;-)

Jim



 

 


________________________________



 
 
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
  

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090212/283e47ff/attachment.html 


More information about the antlr-interest mailing list