[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to resolve if/elseif/else ambiguity?
From: |
Hans Aberg |
Subject: |
Re: how to resolve if/elseif/else ambiguity? |
Date: |
Wed, 13 Jun 2007 23:53:11 +0200 |
On 12 Jun 2007, at 22:12, SirZooro wrote:
I am trying to create grammar which has if/elseif/else instruction.
However I
am unable to get rid of shift/reduce conflicts.
Just write it as:
%token if then else
%%
statement:
if conditional then statement
| if conditional then statement else statement
;
If you do it, I think you get a simple shift/reduce conflict. Look at
the conflicting state and the two tokens before and after the "." in
the conflicting rules of that state. In this case, it should be
"then" and "else". Then apply token precedences to these two tokens, %
left, etc. though I think it does not matter which in this case.
(Since the parser generated prefers shifts over reduces, one can also
just ignore it, and set %expect.)
Hans Aberg