[antlr-interest] More, Status of C++ backend?

Jim Idle jimi at temporal-wave.com
Tue Jan 1 11:49:27 PST 2008


Yes - the new C++ runtime (when I eventually finish it!) will not 
allocate any memory for the token strings unless you access it. It will 
also avoid smart pointers and things. However, at the end of the day, 
unless you really really want to use C++ in your actions, I think that 
the C target will always be a little bit faster. Hence I am also going 
to look at making the C target more C++ compatible too.

Porting a C++ 2.7 grammar to 3.x C probably involves more work on the 
grammar and tree stuff than it does on the C++ to C work. In general I 
advise people to limit the action code to API calls, which means that 
you would need to supply a C linkable interface to your current code, 
then keep your grammar and action ode as separate as possible. Grammars 
that hae too much of the for actions directly typed in to them tend to 
be difficult to read anyway.

Jim

> -----Original Message-----
> From: Ruslan Zasukhin [mailto:sunshine at public.kherson.ua]
> Sent: Tuesday, January 01, 2008 9:16 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] More, Status of C++ backend?
> 
> On 30/10/07 6:47 PM, "Jim Idle" <jimi at temporal-wave.com> wrote:
> 
> > I have made a tentative start now, but I have been busy working for 
a
> while
> > unfortunately. I hope to be back on it next week sometime. The C 
target
> has
> > worked fine for most people that initially wanted C++ back ends, 
though
> > eventually it will be better to have C++ based actions of course.
> 
> Hi Jim,
> 
> Once I again I want repeat this question :-)
> 
> 1) we have few year ago made SQL grammar for ANTLR 2.7.2 made with C++
> target.
> 
> So I wonder, how easy will be port this to C target.
> And what you mean with
> >    eventually it will be better to have C++ based actions of 
course".
> 
> You mean now in C target we cannot have actions as
> 
>     {
>         MyClass * p = new MyClass()
>         i.e. Some C++ code
>     }
> 
> ?
> 
> 
> 2) also I have come to all these issues because again did profile of 
100K-
> 1M
> INSERTS, and I see big troubles in ANTLR 2.7.2 C++ runtime. As far as 
I
> could see problem come from LA() which calls a lots NextToken() which
> creates std::string() what cause call of new() (and later free.
> 
> ANTLR parser looks to work 8-10 times slower of YACC or Lemon. And I 
think
> because of this reason.
> 
> I have check -- and it seems to be deal of few hard days work to try
> remove
> std::string from C++ runtime of ANTLR 2.7.2 and using instead just
>     pair  { char*, length }
>     where char* points right into string we do parse.
>     I do not see any need today do COPY of each token string.
>     btw, how you have implement this in C runtime for v3 ?
> 
> Before to do this I was going to check state of deal in ANTLR 3,
> and I see that C++ runtime even not exists.
> 
> My advice will be not use std::string at all, and do not make not 
required
> copies of strings into each Token object.
> 
> 
> --
> Best regards,
> 
> Ruslan Zasukhin
> VP Engineering and New Technology
> Paradigma Software, Inc
> 
> Valentina - Joining Worlds of Information
> http://www.paradigmasoft.com
> 
> [I feel the need: the need for speed]
> 
> 




More information about the antlr-interest mailing list