[antlr-interest] Problem with C target output on example C grammar

Jim Idle jimi at temporal-wave.com
Wed Apr 2 11:24:14 PDT 2008



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kamil Burzynski
> Sent: Wednesday, April 02, 2008 11:
 
> > This was just that you did not relink the main executable with your
> > library I believe. If not, then can you provide an example as I did
> > not see anything in the prior emails. It might be there of course,
> but
> > I didn't see anything else?
> 
> Sure, here you go (my mailer may wrap lines, watch out):
> 
> 
> evaluate
> scope A;
> scope B;
> scope C;
> @init
> {
>         printf("\%p \%p \%p\n", SCOPE_TOP(A), SCOPE_TOP(B),
> SCOPE_TOP(C) );
>         $A::a = 42;
>         $B::b = 42;
>         $C::c = 42;
> }
> : 'foo';
> 
> 11856 20:12:14 nopigentoo ~/Warsztat/antlr/scope$ java org.antlr.Tool
> scope1.g
> ANTLR Parser Generator  Version 3.1b1 (??)  1989-2007
> Generating scope1Parser.c
> Generating scope1Parser.h
> Generating scope1Lexer.c
> Generating scope1Lexer.h
> 11857 20:12:26 nopigentoo ~/Warsztat/antlr/scope$ gcc *.c -o main -I. -
> lantlr3c
> 11858 20:12:35 nopigentoo ~/Warsztat/antlr/scope$ ./main
> (nil) (nil) 0x52d390
> Segmentation fault
> 11859 20:12:37 nopigentoo ~/Warsztat/antlr/scope$
> 
> As you see, only last scope (C) was initialized.

OK - will look at that. 

On the smart pointer thing, I did not realize (as I don't use smart pointers) that they were passed around using a reference that was not nullable, but I was looking at supporting boost for the C++ stuff, so I guess it would have fallen out of the trying. I will look into that, but I am still thinking that the answer is that it is better not to initialize the return value. 

Incidentally, rather than passing things up and down the rules, you might find i easier to create helper classes in higher up scopes. 

Jim





More information about the antlr-interest mailing list