Log In
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Sep 2019
  1. Satbir

    567 Points

  2. Bikram

    566 Points


    348 Points

  4. Vimal Patel

    87 Points

  5. Shaik Masthan

    38 Points


    14 Points

  7. sekhar_1621

    13 Points

  8. OgbeborBeatrice

    13 Points

  9. RAMYA.F

    9 Points

  10. vkw1111

    9 Points

0 votes

Hello all, I have been trying to understand how to add look aheads in cannonical collection of LR(1) items: 

This is my approach:

It asked for the items in closure of S’→.S,$ (calling it P1)

Now since . is present before S, I need to write closure of S.




The lookaheads for the above productions should be First(whatever is present after S in P1) ie. $


S→.SaA, $

|.aSc, $

|.A, $

Also have to write closure of A

A→.Sb, $

|.d, $

I am unable to figure out how to get a, b in lookaheads, I am only getting $. Any help is appreciated. Thank you

in Compiler Design 132 points 17 views
Dont even try attempt LR(1) and LALR(1) parsing in exam(though they are never asked). This is where most people will lose marks. I know after this comment many will oppose me saying that u should try. But, better be safe than sorry. Moreover they do not ask LALR(1) and LR(1) parsing tables in gate
Ya it’s lengthy and confusing. I won’t say confusing but with the clock ticking beside even 1+1 is confusing. Anyway can you tell what I did wrong? Since this is a short question..
i am currently outside, will surely try when i reach home at night..

No worries take your time. Could also check . I got two answers wrong back to back. :( 

I think these type of questions can be kept for last pass. If we have time remaining at last we can attempt it. And these question is not particularly that hard(Agree that this is tricky but if we double check each options then it can be done correctly) as there are questions on counting cache misses given a program fragment which requires hell lot of time. (:

1 Answer

0 votes
Best answer
Answer given is correct which is $(D)$.

This is tricky btw.

Solution is as follow:

1] $S’ \rightarrow .S, \{\$\}$

2] $S \rightarrow .SaA, \{\$\}$

3] $S \rightarrow .aSc, \{\$\}$

4] $S \rightarrow .A, \{\$\}$

5] $A \rightarrow .Sb, \{\$\}$

6] $A \rightarrow .d, \{\$\}$

now, because of item no. $[2]$ we have to add following items.

7] $S \rightarrow .SaA, \{a\}$

8] $S \rightarrow .aSc, \{a\}$

9] $S \rightarrow .A, \{a\}$

10] $A \rightarrow .Sb, \{a\}$

11] $A \rightarrow .d, \{a\}$

and now because of item no. [5] we have to add following items.

12] $S \rightarrow .SaA, \{b\}$

13] $S \rightarrow .aSc, \{b\}$

14] $S \rightarrow .A, \{b\}$

15] $A \rightarrow .Sb, \{b\}$

16] $A \rightarrow .d, \{b\}$

Now combining all those items into one set which is exactly what is given in your test series answer. This time test series answer is right. (:.
199 points
selected by
I think I should have accepted by now that I’m a dumb piece of shit…
It's not like that bro. I have made mistake in this question itself while solving this.

Some topics are difficult for most student but enough practice will do the work.

Point is every time you make mistake you have to remember that mistake and try to not repeat it again.