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

Reply via email to