0

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 : expression_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?

14
  • No, I don't see a conflict, but your second question seems to imply that you do. Anyway, this can't be your full grammar (you're missing the rules for expression_stmt, compound_stmt, etc.). If you're having an actual conflict with your grammar, please post all the relevant bits so that we can try and reproduce it. Commented Nov 18, 2009 at 9:49
  • @arthur: the full grammar is here: stackoverflow.com/questions/1752185/whats-wrong-with-my-grammar Commented Nov 18, 2009 at 10:03
  • @Adrien: OK, thanks :-) So it seems it's a duplicate. Commented Nov 18, 2009 at 10:10
  • @arthur: no it's just that our OP is not able to do his homework himself. each error pointed in an answer gives way to a new question where he wants us to correct his mistakes... using this iterative approach, he might be able to answer his assignment in some weeks, and even manage to get a pretty decent mark without doing anything... Commented Nov 18, 2009 at 10:16
  • No, I am learning dialectically. Dialectical learning is one of the best ways to learn. Commented Nov 18, 2009 at 10:22

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Hey, I had to discover it by hand! I inspected the grammar for that.
Yeah, I thought it was in there. Just needed to confirm. So how can it be fixed?
@Phenom: you have asked this precise question in a number of different ways over the last few days. Just read the answers! Your solution is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.