0

I ran into a Old Exam question that solved by our TA. anyone could help me?

when we create SLR(1) about S--> aSb | a grammar, one of the item set LR(0) is like as:

{ S-->a.Sb, S-->a., S-->.aSb, S-->.a}

about extracted rule from above set, which of them is True:

a) one reduced and 2 shift and 1 goto is produced.

b) one reduced and 2 shift and2 goto is produced.

c) two reduced and 1 shift and 1 goto is produced.

d) when we input a, we have conflict. 

anyone could say why (3) is correct? some detail about this question ?

EDIT: i think Goto refer to Action and goto tables. enter image description here

  • Did you write correctly the SLR(0) item? There's a lonely a at the end... Also what you ask doesn't really make much sense...actions are only shift and reduce so it's not clear what do you mean by produces a goto. – Bakuriu Mar 12 '15 at 19:14
  • @Bakuriu, sorry i edit it –  Mar 12 '15 at 19:18

1 Answers1

1

There are three possible lookahead symbols: a, b, and $ (the end-of-input marker). The transitions are:

 lookahead        action
 ---------        ------
     a            shift
     b            reduce S->a
     $            reduce S->a

And one goto action is produced, on the non-terminal S, with the target being the state {S -> aS.b}

rici
  • 234,347
  • 28
  • 237
  • 341
  • would you please add a bit more detail? i'm sorry if i waste your time. –  Mar 12 '15 at 20:21
  • 1
    @Ali: if you compute the FOLLOW sets, what I wrote should be obvious by inspection of the state. Sorry to be short, but SO is not a substitute for reading a standard text on parsing theory. Anyway, think about what the action must be given the three possible following tokens. – rici Mar 12 '15 at 20:23
  • Rici, can i compute here? http://hackingoff.com/compilers/predict-first-follow-set –  Mar 12 '15 at 20:34
  • 1
    Apparently so, but you might learn more doing it by hand and then checking. (The FOLLOW set is just the set of symbols which might follow a non-terminal in a valid sentence, so you can do it by eye. Just don't forget to augment the grammar with `S' -> S $` (you don't have to do that for most tools since the tool will do it automatically). – rici Mar 12 '15 at 20:43
  • rici, i add my picture, would you please check it? –  Mar 12 '15 at 21:05
  • States 2 and 4 are the same, so the shift transition from state 2 should just loop back to itself. Other than that, it's fine. (Of course, it's missing the reduce action, but you knew that.) – rici Mar 12 '15 at 21:08