0% found this document useful (0 votes)
233 views9 pages

Question Bank Compiler Design 2024

Uploaded by

jackpatel56826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
233 views9 pages

Question Bank Compiler Design 2024

Uploaded by

jackpatel56826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

College of Technology (01)

Bachelor of Technology
Department of Computer Engineering (004)

Semester: VII Academic Year: 2024-25

Subject Name: Compiler Design Subject Code: 1010043418

Question Bank
UNIT-1
SR
Question Text Marks
NO.
1 What is Compiler? Design the Analysis and Synthesis Model of Compiler. 4
2 Write down the five properties of the compiler. 3
3 What is a translator? Write down the steps to execute a program. 3
4 Discuss all the phases of the compiler with a diagram. 8
5 What is the role of the optimization phase in a compiler? 4
6 Explain the role of each phase in the translation process. 8
What are the major components of a simple compiler, and what functions do 4
7
they perform?
What are the advantages and disadvantages of using an interpreter over a 4
8
compiler?
9 What is the purpose of a linker in the compilation process? 4
10 How does a loader differ from a linker? 4
11 Describe the role of a dynamic linker in modern systems. 4
12 List and describe the different types of compilers. 8
13 How does semantic analysis differ from syntax analysis? 4
14 How do single-pass and multi-pass compilers differ? 4
15 Describe the advantages of using a multi-pass compiler. 4
UNIT-2

SR
Question Text Marks
NO.
16 Explain the main functions performed by a lexical analyzer.. 4
Write a short note on: 4
a. YACC
17 b. Pass
c. Bootstrapping
d. LEX Compiler
18 Discuss the importance of tokenization in the lexical analysis phase. 4
What is input buffering in the context of lexical analysis? And why it is 3
19
necessary
20 Describe the role of sentinels in input buffering. 3
21 Differentiate between tokens, patterns, and lexemes. 3
Explain how reserved words and identifiers are distinguished during token 4
22
specification.
23 Discuss the role of finite automata in the recognition of tokens. 4
24 Describe the process of token recognition in a lexical analyzer. 3
Differentiate between deterministic finite automata (DFA) and 8
25
non-deterministic finite automata (NFA)..
Convert the regular expression a(b|c)* into a non-deterministic finite 8
26
automaton (NFA). Draw the state transition diagram for the NFA.
Given the regular expression (01|10)*, construct the corresponding 8
27 deterministic finite automaton (DFA). Show each step of the conversion
process.
Consider the regular expression 0(0|1)*1. Create the NFA for this regular 8
expression, and then convert it into a DFA. Verify that the DFA correctly
28
accepts strings like "01", "001", and "011", and rejects strings like "00" and
"10".
Given the regular expression (a|b)*abb, construct the corresponding NFA 8
29 and then use the subset construction method to derive the equivalent DFA.
Provide the state transition diagram for both the NFA and DFA.
UNIT-3

SR
Question Text Marks
NO.
30 Explain the parsing techniques with a hierarchical diagram. 4
31 What are the problems associated with Top Down Parsing? 4
32 Write the production rules to eliminate the left recursion and left factoring 3
problems.
Consider the following Grammar: 3
A-> ABd|Aa|a
33
B-> Be|b
Remove left recursion.
Do left factoring in the following grammar: 3
34 A-> aAB|aA|a
B-> bB|b
Write a short note on: 4
a. Ambiguity (with example)
b. Recursive Descent Parser
35
c. Predictive LL(1) parser (working)
d. Handle pruning
e. Operator Precedence Parser
36 Write Rules to construct FIRST Function and FOLLOW Function. 4
Consider Grammar: 3
E-> E+T|T
37 T-> T*F|F
F-> (E)|id
Perform Operator Precedence parsing for input string: (id+id)*id
Write the algorithm to create a Predictive parsing table with the scanning of 8
38
input strings.
Show the following Grammar: 4
S-> AaAb|BbBa
39 A-> €
B-> €
Is LL(1) and parse the input string “ba”.
Consider the grammar: 8
E-> E+E
40 E-> E*E
E->id
Perform shift reduce parsing of the input string “id1+id2+id3”.
Write the properties of LR parser with its structure. Also explain the 4
41
techniques of LR parser.
Write a short note on: 3
a. Augmented grammar
42 b. Kernel items
c. Rules of closure operation and goto operation
d. Rules to construct the LR(0) items
Consider the following grammar: 3
S-> Aa|bAc|Bc|bBa
43 A-> d
B-> d
Compute closure and goto.
44 Write the rules to construct the SLR parsing table. 3
Consider the following grammar: 4
E-> E+T|T
45 T-> TF|F
F-> F*|a|b
Construct the SLR parsing table and also parse the input “a*b+a”.
46 Write the rules to construct the LR(1) items. 3
What is LALR parser? Construct the set of LR(1) items for this grammar: 3
S-> CC
47 C-> aC
C->d
Show the following grammar 4
S->Aa|bAc|Bc|bBa
48 A->d
B->d
Is LR(1) but not LALR(1).
Write the comparison among SLR Parser, LALR parser and Canonical LR 4
49
Parser.
What are the limitations of recursive descent parsing? Provide an example 4
50
grammar where recursive descent parsing fails.
Given the grammar below, create the predictive parsing table: 4
51 S → (S)S | ε
processes the input string "(())" using the parsing table
What are the common conflicts encountered in shift-reduce parsing? Provide 4
52
examples for shift/reduce and reduce/reduce conflicts.
Given the following grammar: 4
S → CC
53 C → cC | d
Construct the SLR parsing table. Then, parse the input string "cdcd" using this
table, showing each step of the parsing process.
Consider the grammar: 4
E→E+T|T
T→T*F|F
54
F → (E) | id
Construct the canonical LR(1) (CLR) parsing table for this grammar. Parse the
string "id + id * id" and demonstrate how the CLR parser processes this input.
Given the grammar: 4
S→L=R
S→R
L → *R
55
L → id
R→L
Construct the LALR(1) parsing table. Use the table to parse the input string
"id = *id" and trace each step of the parsing.
Construct the LR(0) items for the following grammar and identify the 4
conflicts (if any):
S→E
E→E+T|T
56
T→T*F|F
F → (E) | id
Explain how these conflicts can be resolved using SLR or LALR parsing
techniques.
Given the grammar: 4
S→Aa|bAc|dc|bda
57 A→d
Create the SLR parsing table and parse the string "bdac". Show the contents of
the stack, the input, and the action at each step of the parsing process.
58 What is a Syntax-Directed Definition (SDD), and how is it used in compilers? 4
Given the grammar: 4
E → E1 + T { E.val = E1.val + T.val }
E → T { E.val = T.val }
T → T1 * F { T.val = T1.val * F.val }
59 T → F { T.val = F.val }
F → ( E ) { F.val = E.val }
F → id { F.val = id.val }
Define the synthesized attributes and explain how the attribute values are
computed during parsing.
Given the grammar: 4
E → E + T
E → T
T → T * F
60
T → F
F → ( E )
F → id
Construct the syntax tree for the expression "id + id * id".
What is an S-attributed definition, and how is it evaluated in a bottom-up 4
61
parsing approach?
Given the following grammar and its SDD: 4
L → L1 , E { L.val = L1.val + [E.val] }
L → E { L.val = [E.val] }
62
E → num { E.val = num.val }
Perform a bottom-up evaluation of the S-attributed definition for the input
"num1= num + num".
What is an L-attributed definition, and how does it differ from an S-attributed 4
63
definition?
Describe the process of generating intermediate code using a syntax-directed 4
64
translation scheme for arithmetic expressions.
How do inherited and synthesized attributes influence the design of translation 4
65
schemes? Provide an example to demonstrate this.
66 Differentiate between synthesized translation and inherited translation. 4
UNIT-4

SR
Question Text Marks
NO.
67 Differentiate between compile-time errors and run-time errors with examples. 4
Describe the different types of errors that can occur during lexical, syntax, and 3
68
semantic analysis in a compiler.
What are the typical error handling strategies employed during the various 3
69
phases of compilation?
Explain the role of error detection in a compiler. How does it differ from error 3
70
recovery?
What are the different strategies for error recovery in parsing? Compare and 8
71 contrast panic mode, phrase-level recovery, error productions, and global
correction.
Provide an example of an ad-hoc error recovery technique that could be used in 4
72
lexical analysis and explain how it operates.
Discuss the advantages of using systematic methods like global correction over 3
73
ad-hoc methods. Provide an example scenario.
Explain the concept of error productions and how they are used in systematic 4
74
error recovery.
UNIT-5

SR
Question Text Marks
NO.
Write the definition of the symbol table and the procedure to store the names in 4
75
the symbol table.
76 What are the data structures used in the symbol table? 3
77 What are the limitations of stack allocation? 3
78 Write two important points about heap management. 3
Write the comparison among Static allocation, Stack allocation and Heap 8
79
Allocation with their merits and limitations.
80 What is the activation record? Write the various fields of Activation Record. 4
What are the limitations of static storage allocation? Explain the problem of 4
81
dangling references.
UNIT-6

SR
Question Text Marks
NO.
Given the arithmetic expression a + b * (c - d), construct the abstract 8
81 syntax tree (AST) for this expression. Explain how the AST differs from a parse
tree.
Convert the following arithmetic expression into Three-Address Code (TAC): x 8
82
= (a + b) * (c + d).
Explain how the if-else statement is translated into intermediate code. 4
Translate the following code snippet into Three-Address Code:
if (a > b) {
83 x = a;
} else {
x = b;
}
Discuss the role of register allocation in the design of a code generator. How 8
84
does poor register allocation affect the performance of the generated code?
Given the following sequence of instructions, identify the basic blocks and 4
construct the corresponding flow graph:
1. t1 = a + b
2. t2 = t1 * c
85 3. if t2 > d goto L1
4. t3 = d - e
5. goto L2
6. L1: t4 = t2 + e
7. L2: x = t3 + t4
Construct a Directed Acyclic Graph (DAG) for the expression a = b * c + 4
86
b * c. Explain how the DAG helps in detecting common subexpressions.
Describe the process of generating Three-Address Code from a DAG. Given a 3
87
simple DAG, demonstrate how to produce the corresponding TAC.
What is a code generator generator? Discuss how it can automate the process of 4
88
generating machine code from intermediate representations.
Draw the syntax tree and DAG for the following expression: 3
89
(a*b)+(c-d)*(a*b)+b
What is intermediate code and write the two benefits of intermediate code 3
90
generation.
Write the short note on: 4
a. Abstract syntax tree
91
b. Polish notation
c. Three address code
d. Backpatching
Construct syntax tree and postfix notation for the following expression: 4
92
(a+(b*c)^d-e/(f+g)
Write quadruples, triples and indirect triples for the expression: 8
93
-(a*b)+(c+d)-(a+b+c+d)
Write the three address statement with example for: 8
a. Assignment
b. Unconditional jump (goto)
c. Array statement (2D and 3D)
94
d. Boolean expression
e. If-then-else statement
f. While, do-while statement
g. Switch case statement
UNIT-7

SR
Question Text Marks
NO.
What is code optimization in compiler design, and why is it important? Discuss 8
95
the trade-offs between optimization and compilation time.
Identify and explain three common sources of optimization within basic blocks. 8
96 Provide examples to illustrate how each optimization can improve the efficiency
of the generated code.
Given the following basic block, perform local optimizations (such as constant 8
folding, strength reduction, and algebraic simplifications):
t1 = a * 2
97
t2 = t1 + 0
t3 = t2 * 1
t4 = t3 + b
Explain the significance of loop optimization in flow graphs. How can 4
98 identifying natural loops within a flow graph lead to performance
improvements?
What is dead code elimination, and why is it an important optimization 4
technique? Apply dead code elimination to the following code snippet:
x = 5
99 y = 10
z = x + y
w = z * 0
a = y - x
Discuss loop-invariant code motion as a loop optimization technique. Provide an 4
100 example where moving a loop-invariant statement outside of the loop improves
the code’s efficiency.
What is global data flow analysis, and how does it differ from local data flow 3
101
analysis? Explain its role in optimizing code across multiple basic blocks.
Describe common code-improving transformations such as constant 4
102 propagation, common subexpression elimination, and dead code elimination.
How do these transformations contribute to overall code efficiency?
What is peephole optimization? Discuss its purpose and provide an example 4
103
where peephole optimization improves the code.
Explain how data flow analysis is applied to structured flow graphs to optimize 4
104 code. Provide an example of a data flow analysis problem, such as reaching
definitions or live variable analysis, and explain its impact on code optimization.

Prof. Shalu Peshwani Dr. Jay Dave


Subject Coordinator Head of Department

You might also like