# CD |Gate-2006| Previous Year Questions| Set-15

CD |Gate-2006| Compiler Design

1. Consider the following grammar.

``````S -> S * E
S -> E
E -> F + E
E -> F
F -> id
``````

Consider the following LR(0) items corresponding to the grammar above.

``````(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E
``````

Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?    [GATE – 2006]

a. (i) and (ii)
b. (ii) and (iii)
c. (i) and (iii)
d. None of the above

2. Consider the following translation scheme. S → ER R → *E{print(“*”);}R | ε E → F + E {print(“+”);} | F F → (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input ‘2 * 3 + 4’, this translation scheme prints : [GATE – 2006]

a. 2 3 4+*
b. 2 3 * 4 +
c. 2 * +3 4
d. 2 * 3 + 4

3. Consider the following C code segment.

Which one of the following is false? [GATE – 2006]

a. The code contains loop invariant computation
b. There is scope of dead code elimination in this code
c. There is scope of strength reduction in this code
d. There is scope of common sub-expression elimination in this code

4. Consider the following grammar:

``````S → FR
R → S | ε
F → id
``````

In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, \$] respectively .[GATE – 2006]

a. {S → FR} and {R → ε}
b. {S → FR} and { }
c. {S → FR} and {R → *S}
d. {F → id} and {R → ε}

5. Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.

``````subroutine swap(ix,iy)
it = ix
L1 : ix = iy
L2 : iy = it
end
ia = 3
ib = 8
call swap (ia, 1b+5)
print *, ia, ib
end
``````

S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell swap S2: On execution the code will generate a runtime error on line L1 S3: On execution the code will generate a runtime error on line L2 S4: The program will print 13 and 8 S5: The program will print 13 and -2 Exactly the following set of statement(s) is correct : [GATE – 2006]

a. S1 is false and S2 is false
b. S1 is false and S2 is true
c. S1 is true and S2 is false
d. S1 is true and S2 is true