2

Consider the following grammar:

  • S → A
  • A → S | a

This grammar would have an accept/reduce conflict in the SLR(1) parsing table in the state with the following kernel when reading the end symbol($):

  • S' → S.
  • A → S.

Is this conflict considered a shift/reduce or a reduce/reduce conflict?

Additionally, since the parsing table contains this conflict, is it correct to say that the grammar is not SLR(1) and therefore no SRL(1) grammar can have accept/reduce conflicts?

1 Answer 1

2

The way I learned it (which I'm surprised to find isn't what my copy of the Dragon book says), the augmenting production would be S' -> S $, so the first kernel item in the state in question would be S' -> S . $. So the conflict is shift-reduce.

Additionally, since the parsing table contains this conflict, is it correct to say that the grammar is not SLR(1)

Yes. You can also observe that there's a cycle in the grammar (S -> A -> S), and so it's ambiguous, and so can't be SLR(k) for any k.

and therefore no SRL(1) grammar can have accept/reduce conflicts?

To my thinking, accept/reduce conflicts can't exist. The accept action comes from the item S' -> S $ ., and the state with that item can't have any other item, so there can't be a conflict in that state.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. Can you kindly share what the Dragon book says differently about this?
In the dragon book (1977), the augmenting production doesn't have the end symbol, so it seems like they could get an accept-reduce conflict, but I don't think they ever mention the possibility.

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.