
Explore the six phases of compiler design—from lexical and syntax analysis to semantic analysis, intermediate code generation, optimization, and code generation—plus practical skills with tools like Lex.
Explore the structure of a compiler across six phases—lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation—covering front end, back end, symbol table, and error handler.
Explore modeling a compiler design and the science of code optimization, including finite state machines, regular expressions, context-free grammars, and parse trees, preserving meaning while improving performance.
Explore the role of the lexical analyzer in the compiler, detailing tokens, patterns, lexemes, and attributes, its interaction with the symbol table and parser, and how lexical errors are handled.
Master input buffering in lexical analysis with a two-buffer scheme and sentinels, enabling lookahead, and specify tokens using strings, regular expressions, and regular definitions.
Explore recognition of tokens with transition diagrams and a lexical analyzer architecture, covering keywords, identifiers, numbers, and relational operators, with start and accepting states.
Explore the lexical analyzer generator Lex (Flex), its three-part Lex program—declarations, translation rules, auxiliary functions—and lookahead and conflict-resolution concepts, plus token generation.
Explore how nondeterministic and deterministic finite automata recognize tokens in lexical analysis, using transition diagrams and transition tables, and relate them to regular languages and regular expressions.
Learn how to convert regular expressions to automata using subset construction, turning NFA with epsilon moves into a deterministic DFA, and study NFA simulation and regex to NFA basics.
Design a lexical analyzer generator using NFA and DFA, build a transition table and actions, convert regular expressions to automata, and implement lookahead.
Explore optimization of dfa-based pattern matches by computing nullable, first and last positions, follow positions from syntax trees, converting regex to dfa, plus state minimization for space-time tradeoffs.
Examine the role of the parser in transforming tokens from lexical analysis into parse trees, using context-free grammars and top-down or bottom-up parsing, with lr variants and error handling strategies.
Explore context free grammars and their role in syntax analysis, including leftmost and rightmost derivations, parse trees, ambiguity, and the relation to regular expressions and language verification.
Explore writing a grammar for compiler design, distinguishing lexical and syntactic analysis, and eliminating ambiguity, left recursion, and left factoring for top-down parsing.
Explore top-down parsing with recursive descent parser, constructing parse trees from root to leaves, using leftmost derivations; examine backtracking, ambiguities, left recursion, left factoring, and predictive parsing.
Explore predictive parser fundamentals, a top-down, non-backtracking alternative to recursive descent, featuring stack-based parsing, parsing tables, and step-by-step moves with an example.
Explore how to compute first and follow values for a predictive parser and use them to build the predictive parsing table.
Learn to construct predictive parsing tables from first and follow sets, define LL(1) grammar, and apply error recovery in predictive parsing.
Explore bottom-up parsing, starting from leaves to root, and learn the shift-reduce parser, reductions, handle pruning, and conflicts in parsing.
Explore how LR parsing uses LR(0) items, closure, and goto to build deterministic automata for bottom-up parsing, with augmented grammar and acceptance.
Explore the LR parsing model, algorithm, and moves across simple LR, canonical LR, and lookahead LR parsers, using action and goto tables, stacks of states, and shift-reduce mechanics.
Construct the SLR parsing table from an augmented grammar by building LR zero items, the canonical collection, and first and follow sets, then apply the SLR algorithm to parse.
Explore canonical lr parsing with lr one items and lookahead, and see how closure, goto, and dfa build clr parsing tables from lr zero and slr methods.
Construct the CLR parsing table from the augmented grammar by building LR(1) items and the canonical collection. Apply the CLR algorithm to generate action and goto entries with lookahead-driven reductions.
Construct lalr parsing tables by merging common lookaheads, study lookahead lr differences with clr and slr, and apply augmented grammar to build lr one items and efficient tables.
Explore handling of ambiguous grammars in LR parsing using precedence and associativity to resolve conflicts, with dangling else, error recovery strategies, and viable prefixes in SLR, CLR, and LR tables.
Learn how Yacc parser generators produce parsers from grammar specifications and generate C code. Discover using Lex for lexical analysis, error recovery strategies, and handling ambiguous grammars.
Learn syntax directed definitions (sdd) and inherited and synthesized attributes, and see how semantic analysis uses sdd to validate programs and prepare for intermediate code generation.
Explore evaluation orders for syntax directed definitions, using dependency graphs and topological sorts to handle s-attributed and l-attributed definitions, with side-effect control.
Learn how syntax-directed translation applies semantic actions to build syntax trees and translate expressions, comparing it with syntax-directed definitions, and using S-attributed and L-attributed rules, including array types.
Explore syntax directed translation schemes with embedded semantic actions, including postfix and parser-stack implementations; learn s-attributed and l-attributed forms for LR and predictive parsing, illustrated by a desk calculator.
Explore implementing l-attributed syntax-directed definitions through recursive-descent translation, on-the-fly code generation, and both ll and lr parsing with embedded semantic actions.
Explore intermediate code generation, including syntax trees and directed acyclic graphs (DAGs), identify common subexpressions, apply the value number method, and learn three-address code as a low-level intermediate representation.
Explore the three-address code intermediate representation, including quadruples, triples, and indirect triples, plus SSA and Dag concepts, and learn how they support addresses, instructions, and optimization.
Explore type expressions, declarations, and storage layouts in compiler design; learn type checking and translation, type equivalence, and the role of records, arrays, and symbol tables in code generation.
Explore type checking rules and type conversions, including overloading of functions and operators, and apply type inference to polymorphic functions, culminating in a unification algorithm.
Explore control flow concepts, including boolean expressions and short-circuit jumps, three address code for if and while, and switch statements with syntax directed translation, plus intermediate code for procedures.
Explores runtime environments and storage organization, detailing static versus dynamic storage allocation, and a typical memory layout with code, static, heap, free memory, and stack, plus garbage collection basics.
Explore stack allocation of space through activation trees and records, covering seven fields, and how calling sequences and the control stack manage nested quicksort calls.
Explore access to non-local data on the stack using access links and displays, manage nesting depth and activation records, and handle procedure parameters in nested procedures.
Explore heap management in memory allocation, detailing the memory manager's allocation and deallocation roles, fragmentation reduction, and memory hierarchy optimization through locality, coalescing, and best-fit strategies.
Explore garbage collection goals, reachability, reference counting, and trace-based collection, then examine mark and sweep, mark and compact, and copying collectors with cost comparisons.
Explore the design of the code generator, focusing on input from optimized intermediate code and producing target code in assembly language, relocatable machine language, or absolute machine language.
Identify basic blocks from three-address code, construct flow graphs, and optimize blocks with dag-based common subexpression elimination, dead code elimination, and algebraic transformations.
Generate target code from three-address statements using a simple code generator, guided by register and address descriptors, and optimize with peephole techniques such as redundant instruction elimination and algebraic simplifications.
Master register allocation and assignment, including global strategies for inner loops. Apply dynamic programming code generation to expression trees on machines with interchangeable registers, using flow graphs and graph coloring.
master machine independent optimization with data flow analysis and transformations like common subexpression elimination, copy propagation, dead code elimination, constant folding, and code motion in flow graphs.
Explore loops in flow graphs, dominators and dominator trees, natural and inner loops, back edges, and reducible graphs, then learn constant propagation and partial redundancy elimination in code optimization.
Explore data flow analysis as a core compiler optimization, using live variables, reaching definitions, gen/kill, and data flow equations across a flow graph.
Apply iterative data-flow analysis on a flow graph of basic blocks to compute in and out sets for reaching definitions using gen, kill, and union as the confluence operator.
Course Objectives:
Introduce the major concepts of language translation and compiler design and impart the knowledge of practical skills necessary for constructing a compiler.
Topics include phases of compiler, parsing, syntax directed translation, type checking use of symbol tables, code optimization techniques, intermediate code generation, code generation and data flow analysis.
Course Outcomes:
Demonstrate the ability to design a compiler given a set of language features.
Demonstrate the the knowledge of patterns, tokens & regular expressions for lexical analysis.
Acquire skills in using lex tool & yacc tool for developing a scanner and parser.
Design and implement LL and LR parsers
Design algorithms to do code optimization in order to improve the performance of a program in terms of space and time complexity.
Design algorithms to generate machine code.
SYLLABUS:
Module- I:
Introduction: The structure of a compiler, the science of building a compiler, programming language basics.
Lexical Analysis: The Role of the Lexical Analyzer, Input Buffering, Recognition of Tokens, The Lexical-Analyzer Generator Lex, Finite Automata, From Regular Expressions to Automata, Design of a Lexical-Analyzer Generator, Optimization of DFA-Based Pattern Matchers.
Module- 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 and Parser Generators.
Module- III:
Syntax-Directed Translation: Syntax-Directed Definitions, Evaluation Orders for SDD's, Applications of Syntax-Directed Translation, Syntax-Directed Translation Schemes, Implementing L-Attributed SDD's.
Intermediate-Code Generation: Variants of Syntax Trees, Three-Address Code, Types and Declarations, Type Checking, Control Flow, Switch-Statements, Intermediate Code for Procedures.
Module- IV:
Run-Time Environments: Stack Allocation of Space, Access to Non-local 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.
Module- V:
Machine-Independent Optimization: The Principal Sources of Optimization, Introduction to Data-Flow Analysis, Foundations of Data-Flow Analysis, Constant Propagation, Partial-Redundancy Elimination, Loops in Flow Graphs.
Reference:
Compilers: Principles, Techniques and Tools, Second Edition, Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffry D. Ullman.