# Compiler Design Confusing Questions

GATE 1994

Que : Generation of intermediate code based on an abstract machine model is useful in compilers because

1. it makes implementation of lexical analysis and syntax analysis easier
2. syntax-directed translations can be written for intermediate code generation
3. it enhances the portability of the front end of the compiler
4. it is not possible to generate code for real machines directly from high level language programs

Soln :

C. stating the actual use of the Intermediate Code.

Also optimizations can be done on intermediate code enhancing the portability of the optimizer.

nothing else other than option C makes sense for the answers. therefore C is correct.

GATE 2003

Que :

Consider the syntax directed definition shown below.

 S →→ id := E {gen(id.place = E.place;);} E →E1+E2→E1+E2 {t = newtemp(); gen(t = E1E1.place + E2E2place;); E.place = t;} E →→ id {E.place = id.place;}

Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti‘s are the temporary variable names generated by newtemp. For the statement ‘X : = Y + Z’, the 3-address code sequence generated by this definition is

1. X=Y+ZX=Y+Z
2. t1=Y+Z;X=t1t1=Y+Z;X=t1
3. t1=Y;t2=t1+Z;X=t2t1=Y;t2=t1+Z;X=t2
4. t1=Y;t2=Z;t3=t1+t2;X=t3

Soln :

x=y+z

operand op1 op2  result

+           y      z      t1

=          t1              x

t1=y+z

x=t1

so ans is b

GATE 2013

Que : What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production (i.e., of type Aϵ and Aa) to parse a string with tokens?

(A) n/2

(B) n1

(C) 2n1

(D) 2n

Soln :

There is Error in Question . Unit production mean A→B  i.e. a non terminal on the RHS.

Just for the sake of knowledge. It is in CNF. and you must know how many steps does it take. Its 2n-1.