Redirected
retagged by
1,474 views
2 votes
2 votes

Let G be a grammar with the following productions.

If LR(1) Parser is used to construct the DFA using the above productions, then how many look-a-heads are present for an  item  in the initial state?

retagged by

3 Answers

Best answer
2 votes
2 votes

(1) E'->.E, $

(2) E->.E+T, $/               //because of line 1 and 2

 (3) E->.T , $/                  //because of line 1 and 2

(4) T-> .T*F, $/+/*/-             // because of line 3,4 and 7

(5) T-> .F , $/+/*/-               // because of line 3,4 and 7

(6) F->.(E) , $/+/*/-             // because of line 5 

(7) F->.T-F,  $/+/*/-            // because of line 5 

(8) F->.id , $/+/*/-              // because of line 5


for T->.T*F we have  four Look a heads  {$,+,*,-}

selected by
0 votes
0 votes
The states are given as :

E' -> .E , $           ( initial look-ahead symbol)

E -> .E+T , $,+

        .T     , $,+       

( look-ahead symbol $ comes because of the production E' -> .E  & look-ahead symbol + comes because of the production E -> .E+T , because of the extra .E all productions of E has to written again with their new look-ahead symbol + and hence merged )

T -> .T*F , $,+,*,-

        .F     , $,+,*,-

        .(E)   , $,+,*,-

        .T-F  , $,+,*,-

( similar to the above one )

F -> .id    , $,+,*,-
Answer:

Related questions

3 votes
3 votes
1 answer
1
0 votes
0 votes
1 answer
2
0 votes
0 votes
2 answers
4