Mail Archives: djgpp/1999/06/23/14:25:22
From: | "Campbell, Rolf [SKY:1U32:EXCH]" <cp1v45 AT americasm01 DOT nt DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Bison and particular expressions.
|
Date: | Wed, 23 Jun 1999 13:34:19 -0400
|
Organization: | Nortel Networks
|
Lines: | 57
|
Message-ID: | <37711A9A.4D73B486@americasm01.nt.com>
|
NNTP-Posting-Host: | bmerhc00.ca.nortel.com
|
Mime-Version: | 1.0
|
X-Mailer: | Mozilla 4.6 [en] (X11; I; HP-UX B.10.20 9000/712)
|
X-Accept-Language: | en
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Here is the grammar rule section of a bison program. It is a simple
version of a very complex problem I'm having. It is designed to allow
input of these types:
*
* & =
* & ,
The first 2 lines are in the rule for star.
The last rule uses '*' followed by another token-group which can start
with '&'. Typing the 2nd expression gives a parse error, because it
tries to resolve it as 'and' instead of the 3rd rule of star. You might
say I can fix it by removing 'and', just putting "starB andB commaB" as
the 2nd rule for 'star', and you are right, but that only works because
of this simple example.
What I'm really trying to do is parse C code, and I can't seem to
find a way to parse both of these expressions:
int a,b,c;
int main(int a, b c, d e);
Each line is syntactically correct by itself (assuming 'b' & 'd' are
defined types for line #2). The problem is, my bison program looks for
"type id, id," and when it hits the main line, it gets a parse error
because 'c' is not a comma. If you really want to look at the whole
code, ask and I'll post it. But, I think this small program illustrates
the problem.
%%
file:
| file star
| file and
;
starB: '*';
andB: '&';
equalB: '=';
commaB: ',';
star: starB
| starB and
| starB andB commaB
;
and: andB commaB
;
--
-Rolf Campbell (39)3-6318
PS: Am I trying to break LR grammar modes? If so, is there any way to
resolve it?
- Raw text -