Compiler Design (CSC302) Prasanta K. Jana, IEEE Senior Member Department of Computer Science and Engineering Indian Institute of Technology (ISM), Dhanbad E-mail:prasantajana@iitism.ac.in Lecture Plan LECTURE PLAN, MONSOON 2023-2024 Course Type Course Code CSC302 Name of Course L T P Credit Compiler Design 3 0 0 9 Course Objective The main objective of this course is to make the students understand various phases of a compiler with the associated techniques and algorithms to impart knowledge about designing a new compiler. Learning Outcomes Upon successful completion of this course, students will have a broad understanding of language translator and their need. will have a detailed understanding of various phases of a compiler and their design techniques. will be able to design a complier for new high level language. Unit No. 1 2 3 4 5 6 7 Topics to be Covered Introduction: Need of compilers; Cousins of compilers; Compiler writing tools, compiler phases. Lexical analysis: Tokens, regular expressions, transition diagrams, Design of lexical analyzer generator. Syntax analysis: Context free grammars, ambiguity, top down parsing, bottom up parsing, operator precedence parsing, LR parsers (SLR, LALR, LR). Syntax Directed Translation (SDT): Scheme, Implementation of SDT, postfix notation, SDT to postfix code; Intermediate code generation. Error Detection and Recovery: Lexical-phase errors, Syntactic-phase errors. Code optimization: Sources, optimization of basic blocks, loops in flow graphs, loop optimization. Code generation: Issues, target machine, runtime storage management, basic block and flow graphs, next use information, a simple code generator, register allocation, DAG representation of basic blocks, peephole optimization, code generation from DAGs. Text Book: Lecture Hours 2 5 10 6 3 5 7 Learning Outcome The students will be introduced with the language translator, their need and various phases of a compiler. Students will be familiar with various elements of a scanner (lexical analyzer). They will also learn how to use transition diagram or finite automata for designing a new lexical analyzer This will help the students in understanding various parsing techniques, basic as well as advanced level. They will also gain knowledge of using a specific parsing technique for a new language construct. This unit will help the students to understand intermediate code generator. They will learn how to use Syntax Directed Translation for its design. The students will familiarize with various kinds of compiler errors and they will learn how to design error handler associated with various parsing techniques. This unit will help the students to understand importance of code optimization. They will also learn various code optimization techniques with a special emphasis on loop optimization. Here the students will know how to use DAGs for optimization of a basic block of code. They will also learn about the analysis of flow graph and their use for generating final code. An Introdcution Compiler Designof CompilerIIT (ISM) 1. Alfred Aho andto Jeffrey Ullman, Principles Design, Narosa,Dhanbad 2002 Monsoon 2022-23 2 / 15 Books 1. Alfred V. Aho & Jeffrey D. Ullman, Principles of Compiler Design, ˜ Narosa Pubilishing House, New Delhi. 2. Alfred V. Aho, Ravi Sethi & Jeffrey D. Ullman Compilers, Principles, ˜ Techniques, & Tools, Second Edition, Pearson. An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 3 / 15 Evaluation Mode of Examination: Closed Book Weightage: End-Sem. : 48 Mid-Sem. : 32 Quiz 1 : 10 Quiz 2 : 10 An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 4 / 15 Why do we require this Course Use of Machine Code Use of Assembly language code Tedious Job An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 5 / 15 History of Computer Programming Languages An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 6 / 15 An Introduction What is a Translator? What is a Compiler? An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 7 / 15 OtherTranslators Interpreter Assembler Preprocessor An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 8 / 15 Cosins of a Compiler Loader Linkage Editor Assembler An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 9 / 15 An Example: Computation: b:= a + 2 Identifier Address a 0 b 4 Assembly Code: MOV R1, a ADD R1, # 2 MOV b, R1 Machine Code: 0001 01 00 00000000* 0011 01 10 00000010 0010 01 00 00000100* Code Loaded at 00001111: 0001 01 00 00001111 0011 01 10 00000010 0010 01 00 00010011 An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 10 / 15 Phases of a Compiler What is a Phase? What is a Pass? An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 11 / 15 An Illustration: Position:= initial + rate * 60 An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 12 / 15 Compiler Writing Tools Also Known as Compiler-Compilers, Compiler-Generators. Scanner Generators Parser Generators Data-flow Engines Code Generators An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 13 / 15 Questions An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 14 / 15 End of the Introduction An Introdcution to Compiler Design IIT (ISM) Dhanbad Monsoon 2022-23 15 / 15