开发者

Is there a shift/reduce error in this yacc code?

开发者 https://www.devze.com 2022-12-12 07:06 出处:网络
I\'m getting a message from yacc saying that there is a shift/reduce conflict.I think it\'s coming from this part of the yacc file.

I'm getting a message from yacc saying that there is a shift/reduce conflict. I think it's coming from this part of the yacc file.

statement : expre开发者_如何学Pythonssion_stmt
          | compound_stmt
          | selection_stmt
          | iteration_stmt
          | return_stmt ;

selection_stmt : IF '(' expression ')' statement
               | IF '(' expression ')' statement ELSE statement ;

expression : var '=' expression | simple_expression ;

Can you see a conflict? How can it be fixed?


Yes, I'm seeing a conflict. The selection_statement rule matches expressions like

IF(<expression 1>)
THEN
    IF(<expression 2>)
    THEN <expression statement 1>
    ELSE <expression statement 2>

But that's ambiguous. It could also be

IF(<expression 1>)
THEN
    IF(<expression 2>)
    THEN <expression statement 1>
ELSE <expression statement 2>
0

精彩评论

暂无评论...
验证码 换一张
取 消