[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with a simple grammar
From: |
Eulogio Serradilla |
Subject: |
Problem with a simple grammar |
Date: |
Sun, 17 Apr 2005 12:56:23 +0200 |
User-agent: |
KMail/1.8 |
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.
- Problem with a simple grammar,
Eulogio Serradilla <=