[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shift/reduce problem
Hi,
I am using sablecc to parse some if statements, the
grammar is as follows:
if_statement =
{if} if
general_expression then [true]:statement |
{if_else} if
general_expression then [true]:statement else statement;
After run SableCC, I got the following error
message:
[exec] shift/reduce
conflict in state [stack: TIf PGeneralExpression TThen
PStatement *] on TElse
in {
[exec] [ PIfStatement =
TIf PGeneralExpression TThen PStatement * TElse
PStatement ]
(shift),
[exec] [
PIfStatement = TIf PGeneralExpression TThen PStatement * ] fol
lowed by TElse
(reduce)
[exec]
The message basically says that there is a
reduce/shift conflict after it sees the
keyword "else". I would like the code behaving do
shift first. Any suggestion?
Also I look at simplecc.sablecc sample, it looks
like they have similar grammar to
define the "if" statements, just wondering how they
can avoid the problem.
Thanks a lot.
Yuntao Cui