COMPILER DESIGN (TCS-502) COURSE FILE FOR Bachelor of Technology IN Computer Science and Engineering Session: 2007-2008 Department of Computer Science and Engineering MEERUT INSTITUTE OF ENGINEERING AND TECHNOLOGY MEERUT Prepared by MOHIT KUMAR for and on behalf of Meerut Institute of Engineering and Technology, Meerut.
CONTENTS PREAMBLE SYLLABUS LECTURE PLAN LECTURE NOTES 01 Introduction to Compilers and its Phases 02 Lexical Analysis 03 Basics of Syntax Analysis 04 Top-Down Parsing 05 Basic Bottom-Up Parsing Techniques 06 LR Parsing 07 Syntax-Directed Translation 08 Symbol Tables 09 Run Time Administration 10 Error Detection and Recovery 11 Code Optimization EXERCISES Practice Questions Examination Question Papers Laboratory Assignments MIET TCS-502 COMPILER DESIGN Course File II
PREAMBLE This course studies programming language translation and compiler design concepts; language recognition, symbol table management, semantic analysis and code generation. Prerequisites: Basic knowledge of Discrete Mathematics. Knowledge of Regular Expressions, Finite Automata and Context Free Grammars. Familiarity with working and features of high level languages. Familiarity with instruction set of at least one microprocessor. Programming knowledge of at least one high level language to carry out practical work. Objectives: To introduce the major concept areas of language translation and compiler design. To develop an awareness of the function and complexity of modern compilers. To provide practical, hands-on experience in compiler design, writing and modification. Topics: Lexical Analysis, regular grammars, scanners. Syntactic Analysis, BNF notation, parsing theory. LL (k) and LR (k) parsers. Grammar transformations for parser compliance. Parser generators, translator writing systems. Semantic Analysis, symbol tables, intermediate text forms. Runtime machine models. Overview of Code Optimization. MIET TCS-502 COMPILER DESIGN Course File III
SYLLABUS (As laid down by Uttar Pradesh Technical University, Lucknow) UNIT I: Introduction to Compiler: Phases and passes, Bootstrapping, Finite state machines and regular expressions and their applications to lexical analysis, Implementation of lexical analyzers, lexicalanalyzer generator, LEX-compiler, Formal grammars and their application to syntax analysis, BNF notation, ambiguity, YACC. The syntactic specification of programming languages: Context free grammars, derivation and parse trees, capabilities of CFG. UNIT II: Basic Parsing Techniques: Parsers, Shift reduce parsing, operator precedence parsing, top down parsing, predictive parsers Automatic Construction of efficient Parsers: LR parsers, the canonical Collection of LR (O) items, constructing SLR parsing tables, constructing Canonical LR parsing tables, Constructing LALR parsing tables, using ambiguous grammars, an automatic parser generator, implementation of LR parsing tables, constructing LALR sets of items. UNIT III: Syntax-directed Translation: Syntax-directed Translation schemes, Implementation of Syntaxdirected Translators, Intermediate code, postfix notation, Parse trees & syntax trees, three address code, quadruple & triples, translation of assignment statements, Boolean expressions, statements that alter the flow of control, postfix translation, translation with a top down parser. More about translation: Array references in arithmetic expressions, procedures call, declarations, case statements. UNIT IV: Symbol Tables: Data structure for symbols tables, representing scope information. Run-Time Administration: Implementation of simple stack allocation scheme, storage allocation in block structured language. Error Detection & Recovery: Lexical Phase errors, syntactic phase errors semantic errors. UNIT V: Introduction to code optimization: Loop optimization, the DAG representation of basic blocks, value numbers and algebraic laws, Global Data-Flow analysis. TEXTBOOK: Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman, “Compilers: Principles, Techniques, and Tools” Addison-Wesley. MIET TCS-502 COMPILER DESIGN Course File IV