Privacy Policy

Wednesday, 22 May 2013

Gate 2003 Questions on Compiler Design


GATE 2003 TWO MARK QUESTIONS


5. Consider the grammar shown below
SàiEtSS’|α
S’àeS|ԑ
Eà b
In the predictive parse table. M, of this grammar, the entries M[S’, ԑ] and M[S’,$] respectively are
(a){S’àe S} and {S’à ԑ}
(b){S’àe S} and {}
(c) {S’à ԑ} and {S’à ԑ}
(d) {S’àe S,S’à ԑ} and {S’à ԑ}

Answer: D

Explanation:
The grammar is
SàiEtSS’|a
S’àeS|ԑ
Eàb
            The predicted parser  table M is



      Non
 Terminal               a              b              c              I               t               $

                S           s->a                                   S->iEiSS’
                S’                                        S’->ԑ                                            S’->ԑ
                                                            S’->es
                E                      E->b





So M[S’, e] ={S’à ԑ,  S’->e S} M[S’, $]=Sà ԑ


6.Consider the following grammar shown below
SàCC
CàcC|d
The grammar is
(a)LL(1)
(b)SLR(1)but not LL(1)
(c)LALR(1)but not SLR(1)
(d)LR(1) but not LALR(1)

Answer: D

Explanation:
Consider the  grammar 
SàCC
CàcC|d
The given grammar is LR(1)  grammar. Every SLR(1) grammar is an LR(1) grammar but not every LALR(1) grammar is LR(1) grammar. The given grammar is canonical LR(1) grammar and  every canonical LR(1)grammar is LR(1) grammar.

7. Consider the translation scheme shown below
SàTR
Rà+T{print(‘+’);} R| ԑ
Tànum {print(num,val);}
Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string ‘9+5+2’, this translation scheme will print
(a)9+5+2
(b)95+2+
(c)952++
(d)  ++952

Answer: B

Explanation:
For the input ‘9+5+2’ the translation scheme is 95+2+ shown below:

























No comments:

Post a Comment