Compiler Design GATE CS PYQ Quiz (original) (raw)

Consider the following ANSI C program:

int main () {
Integer x;
return 0;
}

Which one of the following phases in a seven-phase C compiler will throw an error?

Consider the date same as above question. The appropriate entries for E1, E2, and E3 are

For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. [Tex]\\epsilon[/Tex] is the empty string, $ indicates end of input, and, | separates alternate right hand sides of productions.

CSE_2012_51
CSE_GATE_20122

Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.

Program main;
Var ...

Procedure A1;  
 Var ...  
 Call A2;  
End A1  
  
Procedure A2;  
  Var ...  

  Procedure A21;  
    Var ...  
    Call A1;  
    End A21  
      
Call A21;  

End A21

Call A1;  

End main.

Consider the calling chain : Main->A1->A2->A21->A1 The correct set of activation records along with their access links is given by :

gatecs2012activationrecordgatecs2012activationrecord

Consider the following C-program:

C `

double foo (double); /* Line 1 */

int main() {

double da, db;

// input da

db = foo(da);

}

double foo(double a) { return a; }

`

The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:

Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at

The minimum number of arithmetic operations required to evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given value of X using only one temporary variable.

Which data structure in a compiler is used for managing information about variables and their attributes?

Consider the same data as above question. What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation.

The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment.

c = a + b;
d = c * a;
e = c + a;
x = c * c;
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
}

Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion, which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the compiled code?

There are 114 questions to complete.

Take a part in the ongoing discussion