Questionbank Compiler Design
Questionbank Compiler Design
Faculty of Engineering
Department of Computer Science Engineering
Questions in Question Bank
Course Name: [Link] (CS/IT) Course Code:
Comp
Bloom’s etitive
Difficulty
Questions CO Taxonom Exam Area Topic Unit Marks
Level
y Level Questi
on
Which of the following translates the entire program into machine code Compiler vs
1 CO1 1 L Y Compiler 1 1
before execution? A) Interpreter B) Compiler ✅ C) Assembler D) Linker Interpreter
Which of the following executes the program line by line? A) Compiler B) Compiler vs
2 CO1 1 L Y Compiler 1 1
Interpreter ✅ C) Linker D) Loader Interpreter
What type of grammar cannot have left recursion for top-down parsing?
8 A) Context-free grammar ✅ B) Regular grammar C) Context-sensitive CO2 2 M Y Compiler Parsing 1 1
grammar D) Unrestricted grammar
Lexical
Which tool is used as a lexical analyzer generator? A) YACC B) LEX ✅
10 CO2 2 M Y Compiler Analyzer 1 1
C) Bison D) Flex
Tools
Compiler vs
11 Define compiler and interpreter. Explain the differences with examples. CO1 1 L Y Compiler 1 5
Interpreter
Lexical
13 Differentiate Tokens, Patterns, and Lexemes. CO2 1 L Y Compiler 1 5
Analysis
Grammar
14 What is ambiguity in grammar? CO2 1 L Y Compiler 1 5
Ambiguity
Lexical
15 Define finite automata. CO2 1 L Y Compiler 1 5
Analysis
Grammar
16 Explain elimination of left recursion and left factoring with examples. CO2 2 M Y Compiler Transformatio 1 5
n
Context-Free
17 Explain context-free grammar (CFG) with examples. CO2 1 M Y Compiler 1 5
Grammar
Count the Tokens: 1. int main() { // 2 variables int a, b; a = 10; return 0; } Lexical
19 CO2 1 M Y Compiler 1 5
2. main() { char ch='A'; int x,y; x=y=20; x++; printf("%d %d", x,y); } Analysis
Lexical
20 Explain the role of a lexical analyzer in a compiler with an example. CO2 2 M Y Compiler 1 5
Analyzer
What is the definition of a compiler, and how does it differ from an Compiler vs
21 CO1 2 H Y Compiler 1 10
interpreter? Interpreter
Explain the different phases of a compiler and the role of each phase in Compiler
22 CO2 2 H Y Compiler 1 10
the compilation process. Phases
Define compiler and interpreter. Explain the differences with examples. Lexical
24 CO2 2 H Y Compiler 1 10
What is the role of a lexical analyzer in a compiler? Analysis
Construct a parse tree for the following grammar S -> aSbS / bSaS / ε
Parsing / Parse
25 where the statement is abab. Also verify whether the grammar is CO2 3 H Y Compiler 1 10
Tree
ambiguous for the given statement.
Consider the grammar: S -> aABe , A -> Abc / b , B -> d. Explain how the Parsing /
26 CO2 3 H Y Compiler 1 10
sentence abbcde is reduced to S. Derivation
Grammar
What do you mean by left-recursion and left-factoring, and how are they
27 CO2 2 H Y Compiler Transformatio 1 10
removed?
n
Write the steps and check whether the grammar is LL(1) or not. Construct
28 CO2 3 H Y Compiler LL(1) Parsing 1 10
the parse table for grammar: S -> iCtSS’ / a , S’ -> eS / ε , C -> b
Write the steps and check whether the grammar is LL(1) or not. Construct
29 the parse table for grammar: S -> aBDh , B -> cC , C -> bc / ε , D -> EF , CO2 3 H Y Compiler LL(1) Parsing 1 10
E -> g / ε , F -> f / ε
Compute the First and Follow for grammar: S -> ACB / CbB / Ba , A ->
30 CO2 3 H Y Compiler First & Follow 1 10
da / BC , B -> g / ε , C -> h / ε
Which parsing technique uses stack implementation with shift and reduce
Shift-Reduce
33 operations? A) Top-down parsing B) Bottom-up parsing ✅ C) Recursive CO1 2 M Y Parsing 2 1
Parsing
descent parsing D) Predictive parsing
Look Ahead LR (LALR) parsers are mainly used because: A) They are
38 simpler than SLR B) They are smaller than CLR while maintaining similar CO2 2 M Y Parsing LALR Parsing 2 1
power ✅ C) They do not use stack D) They can parse all grammars
Top-down vs
41 Difference between top-down and bottom-up parsing. CO1 1 L Y Parsing 2 5
Bottom-up
Grammar
42 Write short notes on: a) Left recursion b) Left Factoring CO2 2 M Y Parsing Transformatio 2 5
n
Error
43 Explain error recovery techniques in bottom-up parsing. CO3 2 M Y Parsing 2 5
Recovery
Grammar
49 What is an ambiguous grammar? CO2 1 M Y Parsing 2 5
Ambiguity
Bottom-up vs
51 What is bottom-up parsing? Explain how it differs from top-down parsing. CO1 2 H Y Parsing 2 10
Top-down
During shift-reduce parsing, what types of conflicts can arise? Explain Conflicts in
54 CO2 3 H Y Parsing 2 10
shift-reduce and reduce-reduce conflicts. Parsing
Explain how an LR parser works in the context of a given grammar and
55 CO2 3 H Y Parsing LR Parsing 2 10
how it handles shifts and reductions.
LR Parsing /
For grammar S → AaBb, S → BbBa, A → ε, B → ε. Compute closure (I)
56 CO2 3 H Y Parsing Closure & 2 10
and GOTO operation.
GOTO
57 Show that the grammar E → E+E, E → E*E, E → id is LR(1) or not. CO2 3 H Y Parsing LR Parsing 2 10
SLR Table
58 Construct a SLR table using grammar S → CC, C → cC, C → d CO2 3 H Y Parsing 2 10
Construction
What is error recovery in parsing, and how does it work in bottom-up Error
60 CO3 2 M Y Parsing 2 10
parsers? Recovery
Syntax-
Syntax-directed translation is based on: A) Tokens B) Grammar and
61 CO1 1 L Y SDT/ICG Directed 3 1
attributes ✅ C) Machine code D) Lexical analysis
Translation
Three-address code typically has how many addresses per statement? A) Intermediate
66 CO2 1 L Y SDT/ICG 3 1
One B) Two C) Three ✅ D) Four Code
Three-Address
71 Explain the types of three-address statements and their implementation. CO2 2 M Y SDT/ICG 3 5
Code
Attribute
72 What is attribute grammar? Explain different types of attributes. CO1 1 L Y SDT/ICG 3 5
Grammar
TAC
75 Explain different three-address code representations. CO2 1 L Y SDT/ICG Representation 3 5
s
Boolean
76 How are Boolean expressions translated into intermediate code? CO2 2 M Y SDT/ICG Expression 3 5
Translation
Syntax Tree vs
78 Difference between syntax tree and parse tree. CO2 1 L Y SDT/ICG 3 5
Parse Tree
Intermediate
80 Explain different intermediate forms of source code with example. CO2 2 M Y SDT/ICG 3 5
Code
Explain how syntax trees and intermediate code are used in compiler back- Compilation
81 CO2 3 H Y SDT/ICG 3 5
end for code generation. Back-End
Syntax-
What is a syntax-directed definition (SDD)? How does it relate to the
82 CO1 2 M Y SDT/ICG Directed 3 10
syntax and semantics of a programming language?
Definitions
Create an annotated parser tree for expression (15+7)(5+6) with Syntax Tree
84 CO2 3 H Y SDT/ICG 3 10
grammar: E→E+T, E→T, T→T F, T→F, F→id, F→(E) Construction
Discuss the different types of three-address statements and how they are Three-Address
85 CO2 3 H Y SDT/ICG 3 10
implemented in an intermediate code generator. Code
Describe the process of constructing syntax trees. Why are they important
87 CO2 3 H Y SDT/ICG Syntax Trees 3 10
in compilation? Construct a syntax tree for (a+8)*(b+3).
Generate TAC for program segment: 1) While (A<C and B>D) do if a==1
TAC for
90 then c=c+1 else c=c+2 end if end do; 2) while (a>b and a<c) if a>20 then CO2 3 H Y SDT/ICG 3 10
Control Flow
x=x+20 else x=x+30 end if
Which of the following is not a type expression? A) Basic type B) Array Type
92 CO1 1 L Y Unit IX 4 1
type C) Function type D) Symbol table ✅ Expressions
Static type checking is done: A) At compile time ✅ B) At run time C)
93 CO1 1 L Y Type Checking Unit IX 4 1
During execution D) Dynamically
Explain parameter passing methods: call by value, call by reference, and Parameter
102 CO2 2 M Y Unit IX 4 5
call by value-result. Passing
Parameter
104 Name parameter passing methods in programming languages. CO2 1 L Y Unit IX 4 5
Passing
Runtime
105 Define storage organization. CO2 1 L Y Unit IX 4 5
Environment
106 Explain the specification of a simple type checker with an example. CO1 2 M Y Type Checking Unit IX 4 5
Type
107 Explain type expressions and type systems in compiler design. CO1 2 M Y Unit IX 4 5
Expressions
Runtime
108 Explain access to non-local names in runtime environments. CO2 2 M Y Unit IX 4 5
Environment
Type
109 What is name equivalence of types? CO1 1 L Y Unit IX 4 5
Equivalence
Explain the concept of type conversions. What are the different types of Type
114 CO1 3 H Y Unit IX 4 10
type conversions, and why are they necessary? Conversions
Storage
119 Explain dynamic storage allocation strategies. CO2 2 M Y Unit IX 4 10
Allocation
What is activation tree? How is control stack maintained with the help of Runtime
120 CO2 3 H Y Unit IX 4 10
activation tree? Environment
Which of the following represents the control flow of basic blocks? A) Understan
123 CO1 Low Y Control Flow X 5 1
DAG B) Flow graph ✅ C) Symbol table D) Parse tree d
Which of the following is a target of code generation? A) Source code B) Understan Code
128 CO2 Low Y X 5 1
Intermediate code C) Object code ✅ D) Flow graph d Generation
Code
132 Compare code optimization and code generation CO1 Analyze Medium Y X 5 5
Optimization
Understan Loop
133 What is an induction variable? Explain the induction variable elimination CO1 Medium Y X 5 5
d Optimization
What are different types of local optimization techniques with suitable Local
134 CO1 Apply Medium Y X 5 5
examples Optimization
Register
136 What is register allocation? CO2 Remember Low Y X 5 5
Allocation
Local
137 Name any optimization performed on basic blocks CO1 Remember Low Y X 5 5
Optimization
Code
138 What is the target machine in code generation? CO2 Remember Low Y X 5 5
Generation
Code
139 Explain the design of a simple code generator with an example CO2 Apply Medium Y X 5 5
Generation
Understan Code
141 Define code optimization. What are the different optimization techniques? CO1 Medium Y X 5 10
d Optimization
Data Flow
142 Write an algorithm to compute IN and OUT data flow equations CO2 Apply High Y X 5 10
Analysis
Peephole
144 Explain peephole optimization with example CO1 Apply Medium Y X 5 10
Optimization
Data Flow
145 Write short notes on global data flow analysis CO2 Remember Medium Y X 5 10
Analysis
Understan Code
146 Define code generator and explain issues in design of code generator CO2 Medium Y X 5 10
d Generation
Write in detail the steps of code generation algorithm including the Code
147 CO2 Apply High Y X 5 10
function getreg Generation