CS 6002 Compiler Design
CS 6002 Compiler Design
Course Description:
The course is intended to teach the students the basic techniques that underlie the practice of Compiler
Construction. The course will introduce the theory and tools that can be standardly employed in order to
perform syntax-directed translation of a high-level programming language into an executable code. It also
focuses on various designs of Compiler and structuring and optimizing various phases of a Compiler
Course Objective
Understand the basic concepts and application of Compiler Design.
To learn how to construct compiler to translate High Level Languages to Machine Language.
To learn different phases of compiler and how to implement them.
To learn efficient machine Language Code Generation using the techniques of Optimization.
Syllabus
Unit I:
Introduction of compiler & Lexical Analysis: Phases and passes, Bootstrapping, Finite state machines
and regular expressions and their applications to lexical analysis, implementation of lexical analyzers,
LEecification of programming languages: Context free grammars, derivation and parse trees, capabilities of
CFGX-compiler, Formal grammars and their application to syntax analysis, ambiguity, The syntactic sp
Unit-II:
Syntax Analysis:Parsers, Shift reduce parsing, operator precedence parsing, top down parsing, predictive
parsers Automatic Construction of efficient Parsers: LR parsers, the canonical Collection of LR(0) items,
constructing SLR parsing tables, constructing Canonical LR parsing tables, Constructing LALR parsing
tables, using ambiguous grammars, an automatic parser generator, YACC tool.
Unit-III:
Syntax-directed Translation: Syntax-directed Translation schemes, Intermediate code, postfix notation,
Parse trees & syntax trees, three address code, quadruple & triples, Translation of simple statements and
control flow statements, Type checking, Type conversions, Equivalence of type expressions, Overloading
of functions and operations.
Unit-IV:
Run Time Environment and Error Recovery: Source Language Issues, Storage Organization, Storage-
Allocation Strategies, and Access to Non local Names, Parameter Passing, Symbol Tables, and Language
Facilities for Dynamic Storage Allocation, Dynamic Storage Allocation Techniques, Error Detection &
Recovery, Ad-Hoc and Systematic Methods.
Unit V:
Code Generation and Code Optimization: Issues in the Design of a Code Generator, The Target
Machine, Run-Time Storage Management, Basic Blocks and Flow Graphs, Next-Use Information, A
Simple Code Generator, Register Allocation and Assignment, The DAG Representation of Basic Blocks,
Peephole Optimization, Generating Code from DAGs, Dynamic Programming Code-Generation
Algorithm, Global Data Flow Analysis, A Few Selected Optimizations like Command Sub Expression
Removal, Loop Invariant Code Motion, Strength Reduction etc.
Course Outcomes:
Understands compiler and various phases in compilation
Understands Lexical Analysis and implement it using LEX tool.
Understands LL, LR, and SLR parsing techniques.
Implement parsing using YACC tool.
Understands Syntax Directed Translation, Symbol Tables and their applications.
References Books:
1. A. V. Aho, R. Sethi, and J. D. Ullman. Compilers: Principles, Techniques and Tools, Pearson
Edu.
2. Raghavan, Compiler Design, TMH Pub.
3. Louden. Compiler Construction: Principles and Practice, Cengage Learning
4. A.C. Holub. Compiler Design in C, Prentice-Hall Inc., 1993.
5. Mak, writing compiler & Interpreters, Willey Pub.
List of Experiments:
1. Develop a lexical analyzer to recognize a few patterns in C. (Ex. identifiers, constants, comments,
operators etc.). Create a symbol table, while recognizing identifiers
2. Write a C program to identify whether a given line is a comment or not.
3. Write a Lex program to count number of vowels and consonants in a given input string.
4. Write a Lex program to printout all HTML tags in file
5. Write a Lex program to count the number of comment lines in a given C program. Also eliminate
them and copy that program into separate file.
6. Write a C program for constructing of LL (1) parsing.
7. Write a C program for constructing recursive descent parsing.
8. Write a C program to implement LALR parsing.
9. Write a C program to implement operator precedence parsing.
10. Generate YACC specification for a few syntactic categories