Syllabus 2
Syllabus 2
Preamble:
The purpose of this course is to create awareness among students about the phases of a compiler
and the techniques for designing a compiler. This course covers the fundamental concepts of
different phases of compilation such as lexical analysis, syntax analysis, semantic analysis,
intermediate code generation, code optimization and code generation. Students can apply this
knowledge in design and development of compilers.
Prerequisite: Sound knowledge in Data Structures, Formal Languages & Automata Theory.
Course Outcomes: After the completion of the course the student will be able to
Model language syntax using Context Free Grammar and develop parse tree
CO2 representation using leftmost and rightmost derivations (Cognitive Knowledge
Level: Apply)
Build Syntax Directed Translation for a context free grammar, compare various
CO4 storage allocation strategies and classify intermediate representations (Cognitive
Knowledge Level: Apply)
147
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
CO4
CO5
Assessment Pattern
Remember 20 20 20
Understand 40 40 40
Apply 40 40 40
Analyze
148
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Evaluate
Create
Mark Distribution
149
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Syllabus
Module - 1 (Introduction to compilers and lexical analysis)
Analysis of the source program - Analysis and synthesis phases, Phases of a compiler. Compiler
writing tools. Bootstrapping. Lexical Analysis - Role of Lexical Analyser, Input Buffering,
Specification of Tokens, Recognition of Tokens.
Role of the Syntax Analyser – Syntax error handling. Review of Context Free Grammars -
Derivation and Parse Trees, Eliminating Ambiguity. Basic parsing approaches - Eliminating left
recursion, left factoring. Top-Down Parsing - Recursive Descent parsing, Predictive Parsing,
LL(1) Grammars.
Handle Pruning. Shift Reduce parsing. Operator precedence parsing (Concept only). LR parsing -
Constructing SLR, LALR and canonical LR parsing tables.
Text Books
1. Aho A.V., Ravi Sethi and D. Ullman. Compilers – Principles Techniques and Tools,
Addison Wesley, 2006.
Reference Books
1. D.M.Dhamdhere, System Programming and Operating Systems, Tata McGraw Hill &
Company, 1996.
2. Kenneth C. Louden, Compiler Construction – Principles and Practice, Cengage Learning
Indian Edition, 2006.
150
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
3. Tremblay and Sorenson, The Theory and Practice of Compiler Writing, Tata McGraw Hill
& Company,1984.
151
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
4. What is left recursive grammar? Give an example. What are the steps in removing
left recursion?
152
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
Part B
(Answer any one question from each module. Each question carries 14 Marks)
11. (a) Explain the different phases of a compiler with a running example.
(9)
OR
12. (a) What is a regular definition? Give the regular definition of an unsigned integer
(7)
13. (a) What is Recursive Descent parsing? List the challenges in designing such a
parser? (4)
OR
153
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
14. (a) What is Recursive Descent parsing? List the problems in designing such a (4)
parser
(b) Design a recursive descent parser for the grammar S→cAd, A→ab/ b (5)
Find the FIRST and FOLLOW of the non-terminals S, A and B in the (5)
grammar
S→aABe
A→Abc | b
B→d
15. (a) Construct the LR(0) set of items and their GOTO function for the grammar (10)
S→S S + | S S * | a
OR
17. (a) Design a Syntax Directed Translator(SDT) for the arithmetic expression (4 * (8)
7 + 19) * 2 and draw an annotated parse tree for the same.
(b) Consider the grammar with following translation rules and E as the start (6)
symbol
E → E1 # T {E.value=E1.value x T.value ;}
| T{E.value=T.value ;}
T → T1 & F{ T.value=T1.value + F.value ;}
| F{T.value= F.value ; }
F → num { F.value=num. lvalue ;}
Compute E.value for the root of the parse tree for the expression
2#3 & 5# 6 &7
154
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
OR
18. (a) Write Syntax Directed Translator ( SDT) and parse tree for infix to postfix (8)
translation of an expression.
OR
20. (a) Write the Code Generation Algorithm and explain the getreg function (6)
Teaching Plan
No. of
No Contents Lecture
Hours
Module - 1(Introduction to Compilers and lexical analyzer) (8 hours)
155
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
156
Downloaded from Ktunotes.in
COMPUTER SCIENCE AND ENGINEERING
157
Downloaded from Ktunotes.in