1

I am working on LR(1) items and I am having a bit of doubt and hoping someone can clarify for me. Given the following grammar, I must generate the LR(1) items. I generated the first item but am unsure if its correct, so before I continue, I want to make sure I have the first one correct. If anyone can help me/clarify for me, I'd really appreciate it. Thank you. Here is what I have:

Augmented Grammar:
S' -> S
S -> [ ]
S -> [ S ]
S -> S S

I0: S' -> • S, $
    S  -> • [ ], $
    S  -> • [ S ], $
    S  -> • S S, $
user655321
  • 143
  • 4
  • 18
  • 1
    That's correct. But your grammar is ambiguous, so you're going to end up with conflicts sooner or later. – rici Jul 29 '15 at 18:36
  • Using an online parser generator I just found, it gave me this result for I0:{[S’ -> .S, $]; [S -> .[ ], $/[]; [S -> .[ S ], $/[]; [S -> .S S, $/[]}, Im not sure where it got the $/[ ] from. Can you explain? Thanks. – user655321 Jul 29 '15 at 18:38
  • 1
    Oh, right. I didn't check the lookaheads, sorry. In `S -> S S`, the first `S` on the right-hand side can be followed by FIRST(S), and FIRST(S) is obviously `[`. – rici Jul 29 '15 at 18:44
  • How about the ] , where does that one come from? I'm just a little confused as to why its not just $. Thanks again. – user655321 Jul 29 '15 at 18:51
  • I think the ] is punctuation. That is, it is closing the open bracket started by `[ S -> ...` – rici Jul 29 '15 at 18:52
  • oh! ok, that makes sense. Thank you. – user655321 Jul 29 '15 at 18:53

0 Answers0