Cse CD
Cse CD
Cse CD
COURSE PURPOSE
The purpose of this course is to provide students with an overview of the issues that arise
in Compiler construction as well as to throw light upon the significant theoretical
developments and tools that are deep rooted into computer science. This course will basically
introduce the major phases of Compiler construction and also its theoretical aspects including
regular expressions, context free grammars etc. As a part of this course the students are
required to design a compiler passing through the phases namely Lexical Analysis, Syntax
Analysis, Semantic Analysis and Intermediate code generation for a small language.
SCOPE OF COURSE
This course provides the concepts related Compiler Design. Here, A mastery of these
areas is essential for us to develop Compiler Design that utilizes computer resources in an
effective manner. A Compiler Design will certainly help the student to create good System.
The Regular Languages are required to determine the quality of Representation Mechanisms.
As computers become faster and faster, the need for programs that can handle large amounts
of input becomes more acute. The objective of this course is to teach students good
automation skills simultaneously so that they can develop such languages with the maximum
amount.
PRE-REQUISITES
1. Formal Languages and Automata Theory
2. Computer organization.
3. Discrete mathematics
4. System software
Course Objectives:
To understand the various phases in the design of a compiler.
To understand the design of top-down and bottom-up parsers.
To understand syntax directed translation schemes.
To introduce LEX and YACC tools.
To learn to develop algorithms to generate code for a target machine.
Course Outcomes:
CO1:Ability to design, develop, and implement a compiler for any language.
CO2:Able to use LEX and YACC tools for developing a scanner and a parser.
CO3:Able to design and implement LL and LR parsers.
CO4:Able to design algorithms to perform code optimization in order to improve
the performance of a program in terms of space and time complexity.
CO5:Ability to design algorithms to generate machine code
Proficiency
Program Outcomes (PO) Level assessed
by
PO1 Assignments,
Engineering knowledge: Apply the knowledge of mathematics,
Tutorials,
science, engineering fundamentals, and an engineering 3
Mock
specialization to the solution of complex engineering problems.
Tests
PO2 Problem analysis: Identify, formulate, review research literature, and
analyze complex engineering problems reaching substantiated Assignments,
3
conclusions using first principles of mathematics, natural sciences, Tutorials
and engineering sciences.
PO3 Design/development of solutions: Design solutions for complex
Assignments,
engineering problems and design system components or processes
Tutorials,
that meet the specified needs with appropriate consideration for the 3
Mock
public health and safety, and the cultural, societal, and
Tests
environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based Assignments,
knowledge and research methods including design of experiments, Tutorials,
3
analysis and interpretation of data, and synthesis of the information Mock
to provide valid conclusions. Tests
PO5 Modern tool usage: Create, select, and apply appropriate techniques, Assignments,
resources, and modern engineering and IT tools including Tutorials,
3
prediction and modeling to complex engineering activities with an Mock
understanding of the limitations. Tests
PO6 The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues
- -
and the consequent responsibilities relevant to the professional
engineering practice.
PO7 Environment and sustainability: Understand the impact of the
professional engineering solutions in societal and environmental
- -
contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and
2 Quiz
responsibilities and norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and
as a member or leader in diverse teams, and in multidisciplinary 2 Quiz
settings.
Proficiency
Program Outcomes (PO) Level assessed
by
PO10 Communication: Communicate effectively on complex engineering
activities with the engineering community and with society at large,
such as, being able to comprehend and write effective reports and - -
design documentation, make effective presentations, and give and
receive clear instructions.
PO11 Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and Hands on
3
apply these to one’s own work, as a member and leader in a team, to training
manage projects and in multidisciplinary environments.
PO12 Life-long learning: Recognize the need for, and have the preparation
Hands on
and ability to engage in independent and life-long learning in the 2
training
broadest context of technological change.
Proficiency
Program Specific Outcomes (PSO) Level assessed
by
PSO1 Software Development and Research Ability: Ability to understand the
structure and development methodologies of software systems. Possess
Assignments,
professional skills and knowledge of software design process.
Tutorials,
Familiarity and practical competence with a broad range of 3
Mock
programming language and open source platforms. Use knowledge in
Tests
various domains to identify research gaps and hence to provide solution
to new ideas and innovations.
PSO2 Foundation of mathematical concepts: Ability to apply the acquired
knowledge of basic skills, principles of computing, mathematical Assignments,
3
foundations, algorithmic principles, modeling and design of computer- Tutorials
based systems in solving real world engineering Problems.
PSO3 Successful Career: Ability to update knowledge continuously in the tools
Assignments,
like Rational Rose, MATLAB, Argo UML, R Language and
Tutorials,
technologies like Storage, Computing, Communication to meet the 3
Mock
industry requirements in creating innovative career paths for immediate
Tests
employment and for higher studies.
1: Slight (Low) 2: Moderate (Medium) 3: Substantial (High) - : None
COURSE CONTENTS
UNIT – I
UNIT – II:
Syntax Analysis: Introduction, Context-Free Grammars, Writing a Grammar, Top-Down
Parsing, Bottom-Up Parsing, Introduction to LR Parsing: Simple LR, More Powerful LR
Parsers, Using Ambiguous Grammars, Parser Generators
UNIT – III:
Syntax-Directed Translation: Syntax-Directed Definitions, Evaluation Orders for SDD's,
Applications of Syntax-Directed Translation, Syntax-Directed Translation Schemes, and
Implementing L-Attributed SDD's.
Intermediate-Code Generation: Variants of Syntax Trees, Three-Address Code, Types and
Declarations, Type Checking, Control Flow, Back patching, Switch-Statements, Intermediate
Code for Procedures.
UNIT – IV:
Run-Time Environments: Storage organization, Stack Allocation of Space, Access to
Nonlocal Data on the Stack, Heap Management, Introduction to Garbage Collection,
Introduction to Trace-Based Collection.
Code Generation: Issues in the Design of a Code Generator, The Target Language,
Addresses in the Target Code, Basic Blocks and Flow Graphs, Optimization of Basic Blocks, A
Simple Code Generator, Peephole Optimization, Register Allocation and Assignment,
Dynamic Programming Code-Generation.
UNIT – V:
Machine-Independent Optimizations: The Principal Sources of Optimization, Introduction
to Data-Flow Analysis, Foundations of Data-Flow Analysis, Constant Propagation, Partial-
Redundancy Elimination, Loops in Flow Graphs.
TEXT BOOKS
1. Compilers: Principles, Techniques and Tools, Second Edition, Alfred V. Aho, Monica
S. Lam, Ravi Sethi, Jeffry D. Ullman, Pearson.
REFERENCE BOOKS
1. Compiler Construction-Principles and Practice, Kenneth C Louden, Cengage Learning.
2. Modern compiler implementation in C, Andrew W Appel, Revised edition,
Cambridge University Press.
3. The Theory and Practice of Compiler writing, J. P. Tremblay and P. G. Sorenson, TMH
4. Writing compilers and interpreters, R. Mak, 3rd edition, Wiley student edition.
5. lex & yacc – John R. Levine, Tony Mason, Doug Brown, O’reilly
LESSON PLAN
Session Week Topic Reference
1 Week – 1 Introduction: Language Processors T1
2. Structure of a compiler
3. Science of building a compiler
4. Programming language basics
5. Lexical Analysis: The Role of the Lexical Analyzer
6. Week – 2 Input Buffering, Recognition of Tokens
7. The Lexical-Analyzer Generator Lex
8. Finite Automata, From Regular Expressions to Automata
9. Design of a Lexical-Analyzer Generator
10. Optimization of DFA-Based Pattern Matchers.
11. *Types of Compiler
12. *Bootstrapping
13. Week-3 Mock Test-1
14. Bridge Class
15. UNIT-II : Syntax Analysis: Introduction T1
16. Context-Free Grammars
17. Context-Free Grammars
18. Week – 4 Writing a Grammar
19. Top-Down Parsing
20. Top-Down Parsing…1
21. Top-Down Parsing…2
22. Bottom-Up Parsing.
23. Week – 5 Bottom-Up Parsing..1
24. Bottom-Up Parsing..2 T1
25. Introduction to LR Parsing
26. Simple LR
27. Simple LR..1
28. Simple LR..2
29. Week – 6
More Powerful LR Parsers
30. Using Ambiguous Grammars
31. Parser Generators
32. Bridge Class -2
33. Syntax-Directed Translation: Syntax -Directed
Week – 7
Definitions
34. Evaluation Orders for SDD's
35. Applications of Syntax-Directed Translation
36. Syntax-Directed Translation Schemes
37. Implementing L-Attributed SDD's
38. Week – 8 *Implementing S-Attributed SDD's
39. Intermediate-Code Generation: Variants of Syntax Trees
40. Three-Address Code T2
41. Types and Declarations
42. Type Checking
43. Week-10 Control Flow
44. Back patching,
45. Switch-Statements
46. Intermediate Code for Procedures.
47. Bridge Class -3
48. Run-Time Environments: Storage organization T2
Week -11
49. Stack Allocation of Space
50. Access to Nonlocal Data on the Stack
51. Heap Management
52. Week – 12 Introduction to Garbage Collection
53. Introduction to Trace-Based Collection.
54. Code Generation: Issues in the Design of a Code
Generator
55. The Target Language
56. Addresses in the Target Code
57. Basic Blocks and Flow Graphs T2
58. Optimization of Basic Blocks
59. Week – 13 A Simple Code Generator
60. Peephole Optimization
61. Register Allocation and Assignment
62. Dynamic Programming Code-Generation
63 Week-14 Mock-Test2
64. Bridge Class-4
65. Machine-Independent Optimizations:
66. Week – 15 The Principal Sources of Optimization
67. Introduction to Data-Flow Analysis
68. Foundations of Data-Flow Analysis
69. Constant Propagation
70. Partial- Redundancy Elimination
71. Loops in Flow Graphs.
72. Revision- Unit1
73. Week-16 Revision – Unit2
74. Revision – Unit3
75. Revision – Unit4
Program Specific
Outco
mes
Course
Outcomes
Program Outcomes (PO) (PSO)
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 3 3 3 3 3 - - 1 2 - 2 1 3 3 2
CO2 3 3 3 3 3 - - 1 2 - 2 1 3 3 2
CO3 3 3 3 3 3 - - 1 2 - 2 1 3 3 2
CO4 3 3 3 3 3 - - 1 2 - 3 1 3 3 2
CO5 3 3 3 3 3 - - 1 2 - 3 1 3 3 2
AVG 3.00 3.00 3.00 3.00 3.00 1.00 2.00 2.40 1.00 3.00 3.00 2.00
Short questions
1. Write regular expressions for the set of words having a,e,i,o,u appearing in that order,
although not necessarily consecutively
[L2:Understand ]
2. Explain about parser and its types [L2:Understand ]
3. Define Pass and Phase [L1:Remember]
4. Explain ambiguous grammar with examples [L2:Understand ]
5. Explain the issues of lexical analyzer. [L2:Understand
]
Objective questions
1. A finite sequence of symbols drawn from alphabet is
a) Symbol b) String c) Node d) None
2. Lexical Analyzer divides the source string into
a) Tokens b) Pattern c) Symbols d) Strings
3. The action of passing the source program into the proper syntactic classes is known as [ ]
A) Lexical analysis B) Syntax analysis C) Interpretation analysis D) Parsing
4. FOLLOW is applicable for [ ]
A) Only non-terminals B) Either terminals or non terminals
C) Only terminals D) Neither terminals nor non-terminals
5. System program such as compiler are designed so that they are [ ]
A) Re-entrable B) Serially usable C) Recursive D) non re-usable
UNIT-II:
Long Questions
. UNIT-III:
Long questions
1. Write the semantic actions to generate the three address code for function call
[L2:Understand ]
and return statements in C language?
2. Consider the following three address code in a basic block. [L3:Evaluate]
(a) t1 = j -1
(b) t2 = 4 * t1
(c) temp = A[t2]
(d) t3 = j
(e) t4 = j + 1
(f) t5 = 4 * t3
(g) t6 = A[t5]
(h) t7 = j - 1
(i) t8 = 4 * t7
(j) A[t8] = t6
(k) t9 = j
(l) t10 = j+1
(m) t11 = 4*t9
(n) A [t11] = temp
(a) Perform copy propagation. You need to do necessary data ow analysis to
make sure that the propagation can be done correctly.
(b) Perform dead code elimination. You need to do necessary analysis to make
sure that the elimination can be done correctly. Also, assume that after the
basic block, A[i], for all i, are alive and no other variables are alive.
3. Write semantic actions for the following? [L6:Create]
(a) for - loop
(b) repeat - until loop.
4. Illustrate the following techniques with suitable examples [L3:Apply]
(a) Constant folding
(b) constant propagation
(c) reduction in strength
(d) Elimination of induction variables.
5. Describe the use of symbol tables in the code generation process. That is, describe
how symbol tables are used to determine scope of variables and how this acts the
code that performs the run-time access to load/store values in subroutine frames
or in static data space [L2:Understand
]
Short questions
Objective questions
1. Pick the odd man out.
(a) Syntax Tree
(b) Triples
(c) Quadruples
(d) Indirect Triples
2. Which of the following translation program converts assembly language programs to object
program?
(a) Assembler
(b) Compiler
(c) Linker
(d) Pre-processor
3. In Quadruple notation ___________ fields are used to represent operands.
(a) 3
(b) 4
(c) 2
(d) 1
UNIT-IV:
Long Questions
Short questions
1.DAG has .
(a) only one root (b) any number of roots (c) no root (d) no does at all
1 The runtime representation of an object program in the logical address space consists of
___________.
2. The static data objects are created at ___________________.
3. The activations of procedures during the running of an entire program by a tree called _________.
4. Activation records are sometimes called ______________.
UNIT-V:
Long questions
1. Represent DAG for register allocation in detail [L4:Apply]
2. Describe different object code forms and illustrate this with an example [L2:Understand]
6. Explain in detail about register allocation and assignment of generic code [L2:Understand]
generation algorithms.
3. Discuss in detail about the issues in the design of a code generator [L2:Understand]
4. Explain in detail about machine dependent code optimization. [L2:Understand]
Short Questions
Objective Questions
1.Which of the following is related to synthesis phase?
A) Syntax analysis B) Code generation
C) Lexical analysis D) Semantic analysis
1. The relative address for a field name is relative to the __________ for that record.
2. The advantage of generating a code from DAG__________
3. The input to the code generator is a__________
4. Addressing modes involving registers have__________
5. The output of code generator is__________
Websites
Free Compiler e-books : http: // more-compiler.blogspot.com/
Lex and Yacc Links
A Compact Guide to Lex and Yacc by Tom Niemann
The Lex and Yacc Page
Assembly Language
http://www.drpaulcarter.com/pcasm/
Expert Details
Sebastian Hack
Prof. Dr.Sebastian Hack is a professor of computer science at Saarland University. His work
focuses on compiler construction, especially code generation, automatic vectorization and
parallelization. Before, he was an assistant professor at Saarland University, a Post-Doc
at EPFL, Switzerland in the LAMP lab and a Post-Doc at ENS Lyon, France in
the COMPSYSproject. He received his PhD in 2006 from Karlsruhe University, Germany
and his Diploma degree also from Karlsruhe University in 2004.
Journals