Compiler Design Question Paper GATE PSU

Compiler Design Question Paper-GATE & PSU Exam

Last updated on March 20th, 2025 at 03:26 am

Here, We will see the Compiler Design Question Paper from the previous year’s exam and the syllabus of Compiler Design for the GATE and PSU Exam.

1. Compiler Design in Gate CSE Exam

Compiler Design is a pivotal topic in the GATE Computer Science and Information Technology (CS/IT) exam, focusing on the principles and techniques behind translating high-level programming languages into efficient machine code. This subject tests candidates’ understanding of compiler phases, optimization strategies, and runtime environments, with questions often blending theoretical concepts and practical applications.

2. Compiler Design Syllabus

The Compiler Design Questions asked in the GATE and PSU Exam focused on topics:

  1. Lexical Analysis: Tokenization, finite automata, and regular expressions.
  2. Parsing: Context-free grammars, LL(1), LR(1), and LALR parsers.
  3. Syntax-Directed Translation: Attribute grammars, and intermediate representations (e.g., three-address code).
  4. Runtime Environments: Activation records, parameter passing, stack allocation.
  5. Intermediate Code Generation & Optimization: Control flow graphs, data-flow analysis (e.g., constant propagation, dead code elimination).
  6. Code Generation: Instruction selection, register allocation.

Q. Among all given options, __ must reside in the main memory.

  1. Assembler
  2. Compiler
  3. Linker
  4. Loader
Answer

Loader
NIELIT 2018

Q. The structure or format of data is called

  1. Syntax
  2. Struct
  3. Semantic
  4. none of the above
Answer

Syntax
NIELIT 2016 DEC Scientist B (CS)

Q. Relocation bits used by the relocating loader are specified by

  1. Relocating loader itself
  2. Linker
  3. Assembler
  4. Macro processor
Answer

Linker
NIELIT 2016 MAR Scientist C

Q. In a single-pass assembler, most of the forward references can be avoided by putting the restriction

  1. on the number of strings/lifereacts.
  2. that the data segment must be defined after the code segment.
  3. on the unconditional rump.
  4. that the data segment be defined before the code segment.
Answer

that the data segment be defined before the code segment.
NIELIT 2016 MAR Scientist B

Q. Context-free grammar can be recognized by

  1. finite state automation
  2. 2- way linear bounded automata
  3. push down automata
  4. both (B) and (C)
Answer

both (B) and (C)
NIELIT 2016 MAR Scientist C

Q. The optimization phase in a compiler generally

  1. Reduces the space of the code
  2. Optimizes the code to reduce execution time
  3. Both (A) and (B)
  4. Neither (A) nor (B)
Answer

Both (A) and (B)
NIELIT 2017 DEC Scientist B

Q. Which of the following is machine-independent optimization?

  1. Loop optimization
  2. Redundancy Elimination
  3. Folding
  4. All of the option
Answer

All of the option
NIELIT 2017 DEC Scientist B

Q. Which of the following code replacements is an example of operator strength reduction?

  1. Replace by P^2 by P*P
  2. Replace by P*16 by P<<4
  3. Replace by pow(P,3) by P*P*P
  4. Replace by (P<<5)-P by P*3
Answer

Replace by P*16 by P<<4
NIELIT 2018

Q. ____ merges the bodies of two loops

  1. loop rolling
  2. loop folding
  3. loop merge
  4. loop jamming
Answer

loop jamming
NIELIT 2018

Q. Some code optimizations are carried out on the intermediate code because:

  1. they enhance the portability of the compiler to other target processors
  2. program analysis is more accurate on intermediate code than on machine code
  3. the information from data flow analysis cannot otherwise be used for optimization
  4. the information from the front end cannot otherwise be used for optimization
Answer

they enhance the portability of the compiler to other target processors
NIELIT Scientific Assistant A 2020 November

Q. Two Important lexical categories are ________ .

  1. White Space
  2. Comments
  3. White Space & Comments
  4. None of the options
Answer

None of the options
NIELIT 2021 Dec Scientist B

Q. Peephole optimization is a :

  1. Loop optimization
  2. Local optimization
  3. Constant folding
  4. Data flow analysis
Answer

Local optimization
NIELIT Scientific Assistant A 2020 November

Q. Which one of the following statements is false?

  1. Context-free grammar can be used to specify both lexical and syntax rules.
  2. Typechecking is done before parsing
  3. High-level language programs can be translated into different Intermediate Representations
  4. Arguments to a function can be passed using the program stack
Answer

Type checking is done before parsing
NIELIT Scientific Assistant A 2020 November

Q. The grammar is S → aSb|bSa|SS|ε is:

  1. Unambiguous CFG
  2. Ambiguous CFG
  3. Not a CFG
  4. Deterministic CFG
Answer

Ambiguous CFG
NIELIT 2017 DEC Scientist B

Q. Identify the total number of tokens in the given statement

printf("A%B=",&i);
  1. 7
  2. 8
  3. 9
  4. 13
Answer

8
NIELIT 2018

Q. Which of the following problems is undecidable

  1. Membership problem for CFGs.
  2. Ambiguity problem for CFGs.
  3. Finiteness problem for FSAs.
  4. Equivalence problem for FSAs.
Answer

Ambiguity problem for CFGs.
NIELIT 2021 Dec Scientist A

Q. The number of tokens in the following C/C++ statement is :

printf("i=%d, &i=%xx", i&i);
  1. 9
  2. 6
  3. 10
  4. 12
Answer

6
NIELIT Scientific Assistant A 2020 November

Q. The context-free grammar S → aSb|bSa|ε generates:

  1. An equal number of a’s and b’s
  2. Unequal number of a’s and b’s
  3. Any number of a’s followed by any number of b’s
  4. Any number of b’s followed by any number of a’s
Answer

Equal number of a’s and b’s
NIELIT 2018

Q. The language {WaXbYa+b | a,b,>1} is

  1. Regular
  2. Context-free but not regular
  3. Context-sensitive but not context-free
  4. Type=0 but not context-sensitive
Answer

Context-free but not regular
NIELIT 2018

Q. The graph that shows basic blocks and their successor relationship is called:

  1. DAG
  2. Control graph
  3. Flow graph
  4. Hamiltonian graph
Answer

Flow graph
NIELIT 2016 DEC Scientist B (CS)

Q. Which of the following is not true for tree and graph?

  1. A tree is a graph
  2. A graph is a tree
  3. Tree can have a cycle
  4. Tree is a DAG
Answer

Tree can have a cycle
NIELIT Scientific Assistant A 2020 November

Q. A bottom-up parser generates ________ .

  1. Rightmost derivation
  2. Rightmost derivation in reverse
  3. Leftmost derivation
  4. Leftmost derivation in reverse
Answer

Rightmost derivation in reverse
NIELIT 2021 Dec Scientist B

Q. One of the purposes of using intermediate code in compilers is to:

  1. make parsing and semantic analysis simpler
  2. improve error recovery and error reporting
  3. increase the chances of reusing the machine–independent code optimizer in other compilers
  4. improve the register allocation
Answer

increase the chances of reusing the machine – independent code optimizer in other compilers
NIELIT 2021 Dec Scientist A

Q. In case of the dynamic programming approach the value of an optimal solution is computed in :

  1. Top-down fashion
  2. Bottom-up fashion
  3. Left to Right fashion
  4. Right to Left fashion
Answer

Bottom up fashion
NIELIT Scientific Assistant A 2020 November

Q. Consider an ε-tree CFG. If for every pair of productions A→u and A→v

  1. If FIRST(u) ∩ FIRST(v) is empty then the CFG has to be LL(1).
  2. If the CFG is LL(1) then FIRST(u) ∩ FIRST(v) has to be empty.
  3. Both (A) and (B)
  4. None of the above
Answer

Both (A) and (B)
NIELIT 2017 OCT Scientific Assistant A (CS)

Q. 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 A→a) to parse a string with n tokens?

  1. n/2
  2. n-1
  3. 2n-1
  4. 2^n
Answer

n-1
NIELIT 2017 July Scientist B (CS)

Q. Which of the following can be accessed by the transfer vector approach of linking?

  1. External data segments
  2. External subroutines
  3. Data located in other procedure
  4. All of these
Answer

External subroutines
NIELIT 2016 MAR Scientist C

Q. Identify the correct nodes and edges in the given intermediate code
1. i=1
2. t1=5*i
3. t2=4*t1
4. t3=t2
5. a|t3|=0
6. i=i+1
7. if i<15 goto(2)

  1. 33
  2. 44
  3. 43
  4. 34
Answer

33
NIELIT 2018

Q. Which of the following statements is/are true in the context of interpreters?
S1 : Interpreters process program according to the logical flow of control through the program.
S2 : Interpreter translates and executes the error-free first instruction before it goes to the secon1.
S3 : Interpreter processing time is less compared with compiler.
S4 : LISP and Prolog are interpreted languages.

  1. Only S1
  2. Only S3
  3. Only S1, S2 and S3
  4. Only S1, S2 and S4
Answer

Only S1, S2 and S4
NIELIT 2017 DEC Scientist B

Q. The output of the lexical analyzer is:

  1. A set of regular expressions
  2. Strings of character
  3. Syntax tree
  4. Set of tokens
Answer

Set of tokens
NIELIT 2016 DEC Scientist B (CS)

Q. In a compiler, keywords of a language are recognized during

  1. parsing of the program
  2. the code generation
  3. the lexical analysis of the program
  4. dataflow analysis
Answer

the lexical analysis of the program
NIELIT 2017 July Scientist B (CS)

Q. A linker is given an object module for a set of programs that were compiled separately. What information need not be included in an object module?

  1. Object mode
  2. Relocation bits
  3. Names and locations of all external symbols defined in the object module.
  4. Absolute addresses of internal symbols.
Answer

Absolute addresses of internal symbols.
NIELIT 2016 MAR Scientist B

Q. A system program that combines the separately compiled modules of a program into a form suitable for execution

  1. assembler
  2. linking loader
  3. cross compiler
  4. load and go
Answer

linking loader
NIELIT 2017 July Scientist B (CS)

Q. Which of the following statements is/are false?
S1 : LR(0) grammar and SLR(1) grammar are equivalent
S2 : LR(1) grammar are subset of LALR(1) grammars

  1. S1 only
  2. S1 and S2 both
  3. S2 only
  4. None of the options
Answer

S1 and S2 both
NIELIT 2017 DEC Scientist B

Q. The most powerful parser is

  1. SLR
  2. LALR
  3. Canonical LR
  4. Operator-precedence
Answer

Canonical LR
NIELIT 2016 MAR Scientist C

Q. YACC builds up

  1. SLR parsing table
  2. Canonical LR parsing table
  3. LALR parsing table
  4. None of these
Answer

LALR parsing table
NIELIT 2016 MAR Scientist C

Q. The LL(1) and LR(0) techniques are ____________.

  1. Both same in power
  2. Both simulate the reverse of right-most derivation
  3. Both simulate the reverse of leftmost derivation
  4. Incomparable
Answer

Both same in power
NIELIT Scientific Assistant A 2020 November

Q. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is

  1. n1 is necessarily less than n2
  2. n1 is necessarily equal to n2
  3. is necessarily greater than
  4. none of the options
Answer

n1 is necessarily equal to n2
NIELIT Scientific Assistant A 2020 November

Q. Type of conflicts that can arise in LR(0) techniques are ____________.

  1. Shift-reduce conflict
  2. Shift-Shift conflict
  3. Both “Shift-reduce conflict” & “Shift-Shift conflict”
  4. None of the options
Answer

Shift-reduce conflict
NIELIT Scientific Assistant A 2020 November

Q. The identification of common sub-expressions and replacement of run time computations by compile-time computations is:

  1. Local optimization
  2. Constant folding
  3. Loop Optimization
  4. Data flow analysis
Answer

Constant folding
NIELIT 2016 DEC Scientist B (CS)

Q. Syntax-directed translation scheme is desirable because

  1. It is based on the syntax
  2. It is easy to modify
  3. Its description is independent of any implementation
  4. All of these
Answer

All of these
NIELIT 2016 DEC Scientist B (CS)

Q. Shift reduce parsing can also be called as:

  1. Reverse of the Right Most Derivation
  2. Right Most Derivation
  3. Left Most Derivation
  4. None of the options
Answer

Left Most Derivation
NIELIT Scientific Assistant A 2020 November

Q. Synthesized attributes can easily be simulated by an

  1. LL grammar
  2. ambiguous grammar
  3. LR grammar
  4. none of the above
Answer

LR grammar
NIELIT 2017 OCT Scientific Assistant A (CS)

Q. A top-down parser generates

  1. Left most derivation
  2. Right most derivation
  3. Left most derivation in reverse
  4. Right most derivation in reverse
Answer

Left most derivation
NIELIT 2016 DEC Scientist B (CS)

Scroll to Top