Compiler Design GATE CS PYQ Quiz

Last Updated :
Discuss
Comments

Question 1

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?
 

  • Lexical analyzer
     

  • Syntax analyzer
     

  • Semantic analyzer
     

  • Machine dependent optimizer
     

Question 2

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

 
  • A

  • B

  • C

  • D

Question 3

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

  • A

  • B

  • C

  • D

Question 4

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
  • A

  • B

  • C

  • D

Question 5

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:

  • no compile warning or error

  • some compiler-warnings not leading to unintended results

  • some compiler-warnings due to type-mismatch eventually leading to unintended results

  • compiler errors

Question 6

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

  • Edit-time

  • Compile-time

  • Link-time

  • Load-time

Question 7

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.

  • 6

  • 7

  • 8

  • 9

Question 8

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

  • Abstract syntax tree

  • Symbol table

  • Semantic stack

  • Parse Table

Question 9

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.

  • 3

  • 4

  • 5

  • 6

Question 10

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?

  • 0

  • 1

  • 2

  • 3

There are 114 questions to complete.

Take a part in the ongoing discussion