100% found this document useful (1 vote)
295 views

QB Compiler Design

This document contains a question bank for the Compiler Design and Abstraction course offered at Saveetha School of Engineering. It includes questions in various units of the course, including Introduction to Compiling and Syntax Analysis. The questions range from 2 to 10 marks and cover various levels of Bloom's taxonomy. They are mapped to specific course outcomes and program outcomes. The document provides a comprehensive set of questions to assess students' understanding of compiler design concepts and techniques.

Uploaded by

Gnana Sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
295 views

QB Compiler Design

This document contains a question bank for the Compiler Design and Abstraction course offered at Saveetha School of Engineering. It includes questions in various units of the course, including Introduction to Compiling and Syntax Analysis. The questions range from 2 to 10 marks and cover various levels of Bloom's taxonomy. They are mapped to specific course outcomes and program outcomes. The document provides a comprehensive set of questions to assess students' understanding of compiler design concepts and techniques.

Uploaded by

Gnana Sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

SAVEETHA SCHOOL OF ENGINEERING

SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL SCIENCES


COMPUTER SCIENCE AND ENGINEERING PROGRAMME
QUESTION BANK 2019

Course Code: CSA1401 Course Name: Compiler Design and Abstraction

Branch: CSE Year : II/III Faculty Name: Dr.K.Anitha

Course Outcomes (CO)


1. Describe the various phases of Compiler and their significance to Compiler
Construction
2. Apply the lexical rules for various types of underlying grammars of programming
languages
3. Apply the semantic rules for various types of parsing algorithms and construct
annotated parse trees for various programming constructs
4. Generate intermediate code using intermediate languages
5. Apply optimization rules for various programming structures and construct target
codes using different code generation algorithms

Blooms Taxonomy Levels (BTL)


1. Remembering 2. Understanding 3. Applying 4. Analyzing 5. Evaluating 6. Creating

ANSWER ALL THE QUESTIONS

Q.
Questions Marks CO BTL PI
No.
UNIT 1
INTRODUCTION TO COMPILING
Compilers – Language Processors – Phases of a compiler – Grouping of Phases – Compiler
construction tools – Lexical Analysis – Role of Lexical Analyzer – Specification of Tokens -
Language for Specifying Lexical Analyzers – LEX.

2 Marks
1. Compare and contrast Compiler and Interpreter? 2 CO1 L4 2.6.4
2. Describe translator and list the types of translator 2 CO1 L2 1.6.1
3. Describe Assembler with suitable example. 2 CO1 L2 1.6.1
4. Define Preprocessor 2 CO1 L2 1.6.1
5. What do you mean by cross compiler? 2 CO1 L2 1.6.1
6. Differentiate between Analysis and Synthesis phases 2 CO1 L4 1.6.1
of Compiler
7. Describe symbol table? What is the need for symbol 2 CO1 L2 1.6.1
table?
8. Compare and contrast single pass and multi pass 2 CO1 L4 2.6.4
9. List the error recovery strategies for lexical errors 2 CO1 L1 1.6.1
10. Give the structure of LEX program 2 CO1 L3 2.6.3
11. Define Lexeme and give an example. 2 CO1 L2 1.6.1
12. What is the role of YACC in compiler design? 2 CO1 L2 1.6.1
13. Define token and pattern. 2 CO1 L2 1.6.1
14. List the issues in lexical analyzer. 2 CO1 L1 1.6.1
15. What is the purpose of linker and loader in language 2 CO1 L4 2.6.3
processing system?
16. Draw the syntax tree for a=b+c*2. 2 CO1 L3 2.6.3
17. What is the role of syntax analysis? 2 CO1 L2 1.6.1
18.. List the types of errors with example. 2 CO1 L1 1.6.1
5 Marks
1. Describe in detail about token, pattern and lexeme 5 CO1 L3 2.6.3
and identify the same in the given statements.
void swap(int i, int j)
{  
int t;
t = i;
i = j;
j = t;
}
2. Demonstrate the use of LEX compiler with the 5 CO1 L4 2.7.1
suitable structure and an example
3. Analyze the Passes of Compiler and justify the need 5 CO1 L4 2.5.3
for grouping phases into passes.
4. Illustrate and explain the translation of source code to 5 CO1 L4 1.7.1
machine code in a typical Language Processing
System in detail with suitable diagram.
5. Describe the role of lexical analyzer in compiler 5 CO1 L4 2.7.1
design with suitable diagram.
6. List the types of errors and explain the different error 5 CO1 L2 1.6.1
handling schemes with examples.
7. What is syntax tree and draw the syntax tree for the 5 CO1 L4 2.6.3
expression a = (b+c) * (b+c) *2
8. List the methods of generating intermediate code and 5 CO1 L4 2.6.3
write the intermediate code for the expression
a=b+c*2
10 Marks
1. Infer the broad phases and passes of the compiler 10 CO1 L4 3.7.1
design with the diagrammatic representation and give
the yield of each stage for the following expression
pos=init+rate*60
2. Analyze the phases and passes of the compiler design 10 CO1 L4 3.7.1
with the following expression c: = (a+5) * (b + 60).
3. Illustrate in detail about how the skeletal source code 10 CO1 L4 3.7.1
is fed into a series of tools and operating system
components to get the desired code that can be used
by the machine.
4. Construct the output of each phase for Determine the 10 CO1 L4 2.5.3
yield of each stage of the compiler design for the
following expression i =i * 70 + j +2
5. Explain in detail about LEX tool with suitable 10 CO1 L4 2.5.3
diagram and structure.
6. Explain in detail with suitable diagram 10 CO1 L4 2.5.3
i) Analysis Phase
ii) Synthesis Phase
7. Determine the yield of each stage of the compiler 10 CO1 L4 3.7.1
design for following expression A=B*-C+B*-C
8. Write down the output of each phase for the 10 CO1 L4 3.7.1
expression a = (b+c) * (b+c) *2.
9. Explain in detail with suitable diagram the 10 CO1 L4 3.7.1
i. Front end of the compiler
ii. Back end of the compiler
10. Analyze and define the various stages of compiler 10 CO1 L4 2.5.3
with program segment c=a+b*10
UNIT 2
SYNTAX ANALYSIS
Role of the parser – Context-Free Grammars – Top Down parsing – Recursive Descent Parsing
– Predictive Parsing – Bottom-up parsing – Shift Reduce Parsing – Operator Precedent Parsing –
LR Parsers – SLR Parser – Error Handling and Recovery in Syntax Analyzer –YACC.
1. Eliminate Left Recursion for the following 2 CO2 L3 2.5.1
expression.
S → (L) | x
L → L, S | S
2. Differentiate Top down parsing and Bottom up 2 CO2 L2 2.6.5
Parsing.
3. List the actions available in shift-reduce parser. 2 CO2 L1 1.6.1
4. Define operator precedence parser. 2 CO2 L2 1.6.1
5. What is the rule for eliminating left recursion? 2 CO2 L3 1.6.1
6. Give the illustration about the quadruple CFG? 2 CO2 L3 1.6.1
7. Generate the structure of YACC program. 2 CO2 L3 1.6.1
8. Write the rules for finding follow in predictive parser. 2 CO3 L3 1.6.1
9. Find the Left Recursion Elimination for following 2 CO3 L3 1.6.1
expression.
A →ABd/Aa/a
10. What is the function of parser? 2 CO3 L2 1.6.1
11. What should the error handler in a parser do? 2 CO3 L2 1.6.1
12. Construct parse tree for (id+id) 2 CO3 L3 1.6.1
13. What is ambiguous grammar? 2 CO3 L2 1.6.1
14. Define YACC 2 CO3 L2 1.6.1
15. List the specification of YACC 2 CO3 L1 1.6.1
5 Marks
1. Determine the CFG G = (V, T, P, S) for the following 5 CO2 L3 2.5.3
regular expressions.
X→X+Y|X–Y|Y
Y→Y*Z|Y/Z|Z
Z → (X) | id
2. Calculate the first and follow functions for the given 5 CO2 L3 2.5.3
grammar-
S → ACB / CbB/Ba
A → da / BC
B → g / ∈
C → h / ∈
3. Give the rules for First and Follow and for the given 5 CO2 L3 2.5.3
grammar identify
S → (L) / a
L → L, S / a
i. First ()
ii. Follow ()
4. Discuss the need and role of a parser with an 5 CO2 L3 1.3.1
example.
5. Apply the suitable rules for the following regular 5 CO2 L3 3.2.1
expression and determine the First and Follow for
each non terminal.
E→E+T/T
T→T&F/F
F → ! F / (E) / 1 / 0
6. Find the Leftmost and Rightmost derivation for given 5 CO2 L3 2.5.3
expression
E → E + E | E * E | (E) | a | b | c
ω = id + id * id.
7. Construct the operator precedence table for the 5 CO2 L4 2.5.3
following grammar
E→EAE
A→ +|*
8. Determine the Lead and Trail for the following 5 CO2 L4 2.5.3
regular expression.
X→X+Y|X–Y|Y
Y→Y*Z|Y/Z|Z
Z → (X) | id
9. Discuss in detail about ambiguous and unambiguous 5 CO2 L3 2.5.3
grammar with suitable example
10 Marks
1. Construct stack Implementation of shift reduce 10 CO2 L4 2.5.3
parsing for the grammar
C->C+C
C->C*C
C->(C)
C->id and the input string id + id * id
2. Construct stack Implementation of shift reduce 10 CO2 L4 2.5.3
parsing for the grammar
S→ (L) | a
L→ L, S | a
Show whether the following string will be accepted
or not. (a, ((a, a), (a, a)))
3. Construct stack Implementation of shift reduce 10 CO2 L4 2.5.3
parsing for the grammar
E->E+E
E->E*E
E->(E)
E->id and the input string id1+id2*id3.
4. Check whether the grammar is LL(1) 10 CO2 L4 2.5.3
E→E+T|T
T→T*F|F
F → (E) | id and the input string
id1+id2*id3.
i. Elimination left recursion.
ii. Find First and Follow.
iii. Generate the Parsing Table.
iv. Stack Implementation for input string.
5. Evaluate and verify SLR parser for the given 10 CO2 L3 2.5.3
grammar i/p: dcd
SCC
CcC
Cd
i. Generate augment grammar.
ii. Identify LR (0) items.
iii. Find the Go To.
iv. Find Follow.
v Generate the SLR Parsing Table.
6. Compute the lead and trail and construct the operator 10 CO3 L3 2.5.3
precedence matrix for the following grammar
E → E+T/T  
T → T*F/F  
F → id 
7. Calculate the first and follow functions for the given
grammar and construct the predictive parser table:
S → A
10 CO3 L3 4.4.2
A → aB / Ad
B → b
C → g
8. Construct and evaluate SLR parser for the given
grammar with dbd as input string
ABB
BbB
Bd 10 CO3 L3 4.4.2
i. Generate augment grammar.
ii. Identify LR (0) items.
iii. Generate the SLR Parsing Table
iv. Implement the given input string.
9. Construct a Predictive LL(1) parser and match the
input id+id*id is matching with the given grammar
ETE`
E`+TE` 10 CO3 L3 4.4.2
TFT`
T`*FT`/є
F(E) /id
UNIT 3
SYNTAX DIRECTED TRANSLATION AND TYPE CHECKING
Syntax-Directed Definitions – Construction of Syntax Trees – Bottom-up Evaluation of S-
attributed and L-attributed Definitions – Top-down Translation – Bottom-up Evaluation – Type
Systems – Specification of a simple type checker – equivalence of type expressions – Type
conversions.
1. Define an attribute. Give the types of an attribute. 2 CO3 L3 2.5.1
2. Compare and contrast Syntax tree and Parse tree. 2 CO3 L4 2.6.4
3. Draw the syntax tree for the following statement: c b
2 CO3 L3 2.5.1
c b a − ∗ + − ∗=.
4. Differentiate Synthesized Attribute and Inherited
2 CO3 L4 1.6.1
Attribute.
5. Differentiate L-attributed and S-attributed definition. 2 CO3 L4 1.6.1
6. List the bottom-up evaluation methods. 2 CO3 L1 1.6.1
7. Mention the rule for type checking. 2 CO3 L1 1.6.1
8. Define Annotated parse tree. 2 CO3 L1 1.6.1
9. Construct the syntax tree for the expression
2 CO3 L3 1.6.1
a=b+c*10
10. Explain static type checking. 2 CO3 L2 1.6.1
11. Explain dynamic type checking. 2 CO3 L2 1.6.1
12. Write down the SDD for a simple desk calculator 2 CO3 L3 1.6.1
13. Define a SDT. 2 CO3 L3 2.5.1
14. Define SDD 2 CO3 L1 1.6.1
5 Marks
1. Discuss in detail about the Syntax Directed
5 CO3 L2 1.6.1
Definitions with suitable example.
2. Inscribe the inherited attribute semantic rules for
following productions. Also build the top-down parse
tree for expression int a,b.
E → TF
5 CO3 L4 4.5.1
T → int
T → real
F → F1, id
F → id
3. Display the parse tree in top-down translation scheme
5 CO3 L3 4.4.2
for following input string real, id1, id2, id3.
4. Evaluate the expressions for the SDD annotated parse
5 CO3 L3 4.4.2
tree for the follow expressions. 3 * 5 + 4n.
5. Generalize the concepts of Type checking. 5 CO3 L2 1.6.1
6. Explain in detail the specification of simple type
5 CO3 L4 4.5.1
checker for statements and expressions.
7. Write an inherited attribute semantic rule for
following production and draw syntax tree for double
a,b,c
D → TL
T → int 5 CO3 L3 4.4.2
T → float
T → double
L → L1, id
L → id
10 Marks
1. Explain in detail about L- attributed definition. Write
a semantic rule for the following expression draw the
syntax tree for real a,b,c.
X → YZ
Y → int 10 CO3 L4 4.4.2
Y → real
Y → double
Z → Z1, id
Z → id.
2. Write the inherited attribute grammar along with the
semantic rules and construct a parse tree in top-down
10 CO3 L4 4.4.2
translation scheme for following input string
real id1, id2, id3.
3. Consider the following regular expression. 10 CO3 L4 4.4.2
S→E
E→E+T|T
T→T*F|F
F → (E) | const
i. Find the production for given grammar.
ii. Write a semantic rule for given grammar.
iii. Draw an annotated parse tree for expression
2+3+4
v. Give the stack implementation
4. S→E
E→E+T|T
T→T*F|F
F → (E) | const
i. List the S-attribute semantic rules for given 10 CO3 L4 4.4.2
grammar.
ii. Show the annotated parse tree for expression (3+4)
* (5+6)
iii. Give the stack implementation
5. Construct a Syntax-Directed Translation scheme that
translates arithmetic expressions from infix into
postfix notation. The solution should include the
context-free grammar, the semantic attributes for
each of the grammar symbols, and semantic rules.
10 CO3 L4 4.4.2
Show the application of your scheme to the input
and“3*4+5*2”.
E→ E + T | T
T→T*F|F
F → (E) | num
6. L→E$
E→ E + T | T
T→T*F|F
F → (E) | digit 10 CO3 L4 4.4.2
Input string 3 * 5 + 4$
i. Generate LR parser tree.
ii. Stack Implementation table.
7. Consider the following regular expression.
S→E
E→E+T|T
T→T*F|F
10 CO3 L4 4.4.2
F → (E) | const
i. Write a semantic rule for given grammar.
ii. Draw an annotated parse tree for expression 7*6+5
iii. Give the stack implementation
8. L→E$
E→ E + T | T
T→T*F|F
F → (E) | digit 10 CO3 L4 4.4.2
Input string 5 * 6 + 4$
i. Generate LR parser tree.
ii. Stack Implementation table.
9. Construct a Syntax-Directed Translation scheme that
translates arithmetic expressions from infix into
postfix notation. The solution should include the
context-free grammar, the semantic attributes for
each of the grammar symbols, and semantic rules.
10 CO3 L4 4.4.2
Show the application of your scheme to the input and
“3*9+2*1”.
E→ E + T | T
T→T*F|F
F → (E) | num
UNIT 4
INTERMEDIATE CODE GENERATION
Intermediate Languages – Declarations - Assignment Statements - Boolean Expressions – Case
Statements - Backpatching – Procedure Calls.
1. Give the ways of representing three address 2 CO4 L3 2.6.3
statements.
2. Write the 3 address code for a=b*-c+b*-c. 2 CO4 L3 2.6.3
3. List various types of three address statements. 2 CO4 L3 2.6.3
4. What are the properties of intermediate language? 2 CO4 L2 1.6.1
5. List out the benefits of using machine independent 2 CO4 L3 2.6.3
intermediate forms.
6. What is three address code? 2 CO4 L4 1.6.1
7. Give the equation for two dimensional array. 2 CO4 L3 2.6.3
8. Tabulate the quadruple representation of three 2 CO4 L1 1.6.1
address statements.
9. Tabulate the triple representation of three address 2 CO4 L1 1.6.1
statements.
10. Tabulate the indirect representation of three address 2 CO4 L1 1.6.1
statements.
11. Define backpatching? 2 CO4 L2 1.6.1
12. Describe the three functions used to manipulate the 2 CO4 L2 1.6.1
list of labels?
13. Explain the function of labels and gotos? 2 CO4 L2 1.6.1
14. Translate the arithmetic expression a* - (b+c) into 2 CO4 L3 2.6.3
a) A syntax tree
b) Postfix notation
15. Convert the expression a * – (b + c) into three 2 CO4 L3 2.6.3
address code.
16. Define short-circuit code? 2 CO4 L2 1.6.1
5 Marks
1. Explain how to generate the intermediate code for the 5 CO4 L3 2.6.3
numerical representation with suitable example
2. Construct a syntax directed definition and a syntax
tree for assignment statements.
S → id : = E
E → E1 + E2
5 CO3 L4 4.5.1
E → E1 * E2
E → - E1
E → ( E1)
E → id.
3. Generate the three address code and translate the 5 CO4 L4 2.7.1
following expression to quadruple, triple and indirect
triple (x + y) * (y + z) + (x + y + z)
4. Give a short note about Syntax tree and DAG and 5 CO4 L3 1.6.1
draw the same for the expression a+a*(b-c)+(b-c)*d
5. main(){ 5 CO4 L3 2.6.3
int a;
float b;
double c;
long double d; }
Allocation process{offset = 0 }
For the above given C code find the offset value.
6. List the methods of generating intermediate code and 5 CO4 L4 2.6.3
express the methodologies using the expression
a=b+c*2
10 Marks
1. Determine the back-patching for following 10 CO4 L4 2.5.3
production
B →B1 || M B2 | B1&& M B2 | !B1 | (B1) | El re1 E2 |
true | false
M→ε
Also construct the annotated parse tree for
x< 100 || x > 200 && x ! = y
2. Explain the flow of control statements for Boolean 10 CO4 L4 2.5.3
expression.
3. Describe the various methods of implementing the 10 CO4 L4 2.5.3
three address statements with an example
4. Explain the translation scheme for converting the 10 CO4 L4 2.5.3
assignments into three address code
5. Construct three address code using the following 10 CO4 L4 3.7.1
production for Boolean expression a<b or c<d or e<f
using numerical representation.
B → B1 || B2
B → B1&& B2
B → !B1
B → E1relop E2
B → true
B →false
6. Describe the backpatching technique for flow of 10 CO4 L4 3.7.1
control statements.
7. Translate the executable statements of the following 10 CO4 L4 3.7.1
c program into three-address code:
Main()
{
int i;
int a [10];
i=1;
while(i<10)
{
a[i]=0;
i=i+1;
}

Unit 5
CODE GENERATION AND CODE OPTIMIZATION
Introduction– Principal Sources of Optimization – Peephole Optimization – Optimization of
Basic Blocks –Global Data Flow Analysis – Issues in the Design of Code Generator – The target
machine – Runtime Storage management – Basic Blocks and Flow Graphs – Next-use
Information – A simple Code generator – DAG representation of Basic Blocks.
2 Marks
1. State the advantages of DAGs? 2 CO5 L2 1.6.1
2. What are the characteristics of peephole 2 CO5 L2 1.6.1
optimization?
3. Mention some of the major optimization techniques? 2 CO5 L2 1.6.1
4. What are the methods available in loop optimization? 2 CO5 L2 1.6.1
5. What are the principle sources of optimization? 2 CO5 L2 1.6.1
6. What is data flow analysis? 2 CO5 L4 1.6.1
7. What are the properties of optimizing compiler? 2 CO5 L2 1.6.1
8. Identify the constructs for optimization in basic 2 CO5 L1 1.6.1
block.
9. What are the issues in the design of code generators? 2 CO5 L3 2.6.3
10. Write short note on global data flow analysis. 2 CO5 L4 1.6.1
11. Define constant folding. 2 CO5 L2 1.6.1
12. What is code motion? 2 CO5 L1 1.6.1
13. What is meant by Common Sub-expressions? 2 CO5 L2 1.6.1
14. Define Live variable 2 CO5 L1 1.6.1
5 Marks
1. Generate an algorithm to partition a sequence of three 5 CO5 L3 2.6.3
address statements into basic blocks.
2. Describe in detail about optimization of basic blocks 5 CO5 L4 2.5.3
with example
3. Explain the characteristics of peephole optimization 5 CO5 L4 1.7.1
5. Construct the dag for the following basic block: 5 CO5 L2 1.6.1
d: = b * c
e: = a + b
b: = b * c
a: = e – d
6. Construct a DAG and generate the code for the given 5 CO5 L4 2.6.3
expression (a-b) + c* (d/e)
7. Consider the following expression and construct the 5 CO5 L3 1.6.1
three address code and draw a DAG for it.
(a+b)*(a+b+c)
10 Marks
1. What are the issues in the design of code generator? 10 CO5 L4 3.7.1
Explain in detail.
2. Explain in detail about basic blocks with algorithm. 10 CO5 L4 2.5.3
3. Explain the principal sources of optimization in 10 CO5 L4 3.7.1
detail.
4. Discuss the various peephole optimization techniques 10 CO5 L4 2.5.3
in detail.
5. Explain the common sub expression-- elimination, 10 CO5 L4 2.5.3
copy propagation and transformations for moving
loop invariant computations in detail?
6. Explain in detail about 10 CO5 L4 2.5.3
i. Flow graph
ii. Next Use Information
7. Explain in detail about DAG for basic blocks with 10 CO5 L4 3.7.1
example.
8. Consider the following basic block- 10 CO5 L4 2.5.3
L10:
S1 = 4 x I
S2 = addr(A) – 4
S3 = S2[S1]
S4 = 4 x I
S5 = addr(B) – 4
S6 = S5[S4]
S7 = S3 x S6
S8 = PROD + S7
PROD = S8
S9 = I + 1
I = S9
If I <= 20 goto L10
Draw a directed acyclic graph and identify local
common sub-expressions.

Unit 6
RUN-TIME ENVIRONMENT
Source Language Issues-Storage Organization-Storage Allocation-Parameter Passing-
Symbol Tables-Dynamic Storage Allocation-Storage Allocation in FORTAN.
1. List the different storage allocation strategies CO5 2 L1 1.6.1
2. What are the contents of activation record? CO5 2 L2 1.6.1
3. Define symbol table CO5 2 L2 1.7.1
4. What is dynamic scoping? CO5 2 L2 1.6.1
5. Suggest a suitable approach for computing hash CO5 2 L3 1.7.1
function.
6. What are the various ways to pass a parameter in a CO5 2 L3 1.7.1
function?
7. Define static allocations and stack allocations CO5 2 L2 1.6.1
5 Marks
1. Discuss in detail about Heap allocation. CO5 5 L3 2.5.3
2. Explain how declarations are done in a procedure CO5 5 L4 3.7.1
using syntax directed translations
3. Write in detail about the issues in the design of code CO5 5 L4 2.5.3
generator
10 Marks
1. What are different storage allocation strategies? CO5 10 L3 2.5.3
Explain.
2. Explain in detail about symbol table management CO5 10 L4 3.7.1
with example
3. Explain in detail about Source language issues. CO5 10 L4 3.7.1

You might also like