Problem with a simple grammar

2005-04-17 Thread Eulogio Serradilla
Hello,

I have a simple bison file summarizes as

#define YYSTYPE const char*

%token NUMBER A TEXT

%%

stmt: expr  /* append a copy of prg to a list */
| stmt expr /* append a copy of prg to a list */
;

expr: NUMBER TEXT A TEXT {

prg.num = atoi($1);
prg.enu = $1; prg.E += $2; /* as C++ strings */
prg.A = $3; prg.A += $4;
}
;

where "prg" is a struct with an int and 2 string members.

When I run the program I got all members of prg having the same semantic 
value, i.e. all with the last string ($4). So I changed to

expr: NUMBER  {prg.num = atoi($1); prg.enu = $1;}
TEXT { prg.enu += $3 /* as C++ strings */ }
A {prg.A = $5;} 
TEXT {prg.A += $7;}
;

and then works as it should be. So the question is: why doesn't the first one 
work?
thanks

PS. I have to use bison 1.24 so you may not be able to help me.


___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Hans Aberg
I have a simple bison file summarizes as
#define YYSTYPE const char*
...
When I run the program I got all members of prg having the same semantic
value, i.e. all with the last string ($4).
This is one of the most frequently asked question on this list: You 
forget to make copies of the strings in your lexer. Thus you only get 
a pointer into a buffer, as you work with pointers.

PS. I have to use bison 1.24 so you may not be able to help me.
This is rather old; the latest release is 2.0
--
  Hans Aberg
___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Eulogio Serradilla
> >I have a simple bison file summarizes as
> >
> >#define YYSTYPE const char*
>
> ...
>
> >When I run the program I got all members of prg having the same semantic
> >value, i.e. all with the last string ($4).
>
> This is one of the most frequently asked question on this list: You
> forget to make copies of the strings in your lexer. Thus you only get
> a pointer into a buffer, as you work with pointers.

OK, I see. That's solved my problem.

>
> >PS. I have to use bison 1.24 so you may not be able to help me.
>
> This is rather old; the latest release is 2.0

Yes, I know, but I prefer to wait for a C++ output for bison, as it says in 
the FAQ section of the manual.

Thank you very much,

E. SR


___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Hans Aberg
At 15:35 +0200 2005/04/17, Eulogio Serradilla wrote:
 > This is rather old; the latest release is 2.0
Yes, I know, but I prefer to wait for a C++ output for bison, as it says in
the FAQ section of the manual.
Bison already has some C++ support, though you might not get the file 
setup you may want. But if you are starting afresh, that might not be 
a problem to you.
--
  Hans Aberg

___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Eulogio Serradilla
> At 15:35 +0200 2005/04/17, Eulogio Serradilla wrote:
> >  > This is rather old; the latest release is 2.0
> >
> >Yes, I know, but I prefer to wait for a C++ output for bison, as it says
> > in the FAQ section of the manual.
>
> Bison already has some C++ support, though you might not get the file
> setup you may want. But if you are starting afresh, that might not be
> a problem to you.

Actually, I'm using bison++ based on bison 1.19 and it works very well. When 
there is some documentation in bison about a C++ parser I will change my 
code.

E. SR


___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Hans Aberg
At 19:44 +0200 2005/04/17, Eulogio Serradilla wrote:
Actually, I'm using bison++ based on bison 1.19 and it works very well. When
there is some documentation in bison about a C++ parser I will change my
code.
Bison++ is a program different from Bison, supposedly old. Bison has 
a C++ test, that is executed if you do a "make check". (I am using 
Bison 2.0 with a special tweak for my own C++ skeleton file, so that 
can't be used straight off.)
--
  Hans Aberg

___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison


Re: Problem with a simple grammar

2005-04-17 Thread Eulogio Serradilla
> At 19:44 +0200 2005/04/17, Eulogio Serradilla wrote:
> >Actually, I'm using bison++ based on bison 1.19 and it works very well.
> > When there is some documentation in bison about a C++ parser I will
> > change my code.
>
> Bison++ is a program different from Bison, supposedly old. Bison has
> a C++ test, that is executed if you do a "make check". (I am using
> Bison 2.0 with a special tweak for my own C++ skeleton file, so that
> can't be used straight off.)

I may give it a try, thank you for your help.

E. SR.


___
Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison