Don’t watch the clock; do what it does. Keep going.
--Your friends at LectureNotes

Note for Compiler Design - CD By Chandrakanta Mahanty

  • Compiler Design - CD
  • Note
  • Computer Science Engineering
  • 21 Topics
  • 6 Offline Downloads
  • Uploaded 11 months ago
0 User(s)

Share it with your friends

Leave your Comments

Text from page-1

B.Tech (Computer Science and Engineering) Syllabus for Admission Batch 2015-16 6th Semester PCS6I102 COMPILER DESIGN Module – I (16 Hours) Introduction: Overview and Phases of compilation. Lexical Analysis: Non-Deterministic and Deterministic Finite Automata (NFA & DFA), Regular grammar, Regular expressions and Regular languages, Design of a Lexical Analyzer as a DFA, Lexical Analyzer generator. Syntax Analysis: Role of a Parser, Context free grammars and Context free languages, Parse trees and derivations, Ambiguous grammar. Top Down Parsing: Recursive descent parsing, LL (1) grammars, Non-recursive Predictive Parsing, Error reporting and Recovery. Bottom Up Parsing: Handle pruning and shift reduces Parsing, SLR parsers and construction or SLR parsing tables, LR(1) parsers and construction of LR(1) parsing tables, LALR parsers and construction of efficient LALR parsing tables, Parsing using Ambiguous grammars, Error reporting and Recovery,Parser generator. Module – II (08 Hours) Intermediate Code Generation: DAG for expressions, Three address codes - Quadruples and Triples, Types and declarations, Translation of Expressions, Array references, Type checking and Conversions, Translation of Boolean expressions and control flow statements, Back Patching, Intermediate Code Generation for Procedures. Module – III (08 Hours) Code Generation: Factors involved, Registers allocation, Simple code generation using STACK Allocation, Basic blocks and flow graphs, Simple code generation using flow graphs. Code Optimization: Objective, Peephole Optimization, Concepts of Elimination of local common sub-expressions, Redundant and un-reachable codes, Basics of flow of control optimization. Module – IV (08 Hours) Run Time Environment: Storage Organizations, Static and Dynamic Storage Allocations, STACK Allocation, Handlings of activation records for calling sequences. Syntax Directed Translation: Syntax Directed Definitions (SDD), Inherited and Synthesized Attributes, Dependency graphs, Evaluation orders for SDD, Semantic rules, Application of Syntax Directed Translation. Symbol Table: Structure and features of symbol tables, symbol attributes and scopes. Text Books: 1. Compilers – Principles, Techniques and Tools, A. V. Aho, M. S. Lam, R. Sethi, J. D. Ullman, Pearson. 2. Compiler Design, K. Muneeswaran, Oxford University Press Reference Books: S. Muchnick, Morgan 5 S. Page 1. Compiler Design, S. Chattopadhyay, PHI. 2. Modern Compiler Design, D. Galles, Pearson Education. 3. Advanced Compiler Design & Implementation, Kaufmann. 4. Compiler Design in C, A. I. Holub, PHI

Text from page-2

B.Tech (Computer Science and Engineering) Syllabus for Admission Batch 2015-16 6th Semester COMPILER DESIGN LABORATORY This lab is divided in to two parts namely part 1 and part 2. All programs in part 1 must be written using C/C++. Programs related to lexical analyzer and parser must use Flex(Fast Lex) and Yacc available in all modern versions of UNIX and Linux distributions. For part 2, a simulator JFLAP is required to be installed. JFLAP works much like a black box and used to hide all implementation details and thus should only be used after students. JFLAP is available online at http://www.jflap.org/. PART 1 1. Using JFLAP, create a DFA from a given regular expression. All types of error must be checked during the conversion. 2. Read a regular expression in standard form and check its validity by converting it to postfix form. Scan a string and check whether the string matches against the given regular expression or not. 3. (Tokenizing). A programs that reads a source code in C/C++ from an unformatted file and extract various types of tokens from it (e.g. keywords/variable names, operators, constant values). 4. Read a regular expression in its standard form and find out an Ɛ-NFA from it. Need to use adjacency list data structure of graph to store NFA. Thompson’s construction needs to be used too. [2 labs] 5. Evaluate an arithmetic expression with parentheses, unary and binary operators using Flex and Yacc.[Need to write yylex() function and to be used with Lex and yacc.] 6. (Tokenizing) Use Lex and yacc to extract tokens from a given source code. Page 6 PART 2 7. Write a suitable data structure to store a Context Free Grammar. Prerequisite is to eliminate left recursion from the grammar before storing. Write functions to find FIRST and FOLLOW of all the variables.[May use unformatted file / array to store the result]. 8. Using JFLAP create LL(1) parse table for a given CFG and hence Simulate LL(1) parsing. 9. Using JFLAP create SLR(1) parse table for a given grammar. Simulate parsing and output the parse tree proper format.

Text from page-3

RESOURCES FOR COMPILER DESIGN Compiler Design Books 1. Compilers Principles, Techniques and Tools, Second Edition, Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman., Pearson. (free pdf available online) 2. Compiler Design, K. Muneeswaran., Oxford University Press, 2012 Reference Book Compiler Design, Santanu Chattopadhyay., PHI Android Apps Compiler Design https://play.google.com/store/apps/details?id=com.sbg.pintukumar.smp.book.CompilerDesign Learn Compiler Design Full https://play.google.com/store/apps/details?id=com.learnacademic.compiler_design Tools LEX https://silcnitc.github.io/lex.html FLEX http://alumni.cs.ucr.edu/~lgao/teaching/flex.html#FLEX JFLAP (Java Formal Languages and Automata Package) http://www.jflap.org/tutorial/ Online Resources https://www.geeksforgeeks.org/compiler-design-tutorials/ https://www.tutorialspoint.com/compiler_design/ Youtube Videos Compiler Design Gate Lectures by Ravindrababu Ravula https://www.youtube.com/watch?v=Qkwj65l_96I&list=PLEbnTDJUr_IcPtUXFy2b1sGRPsLFMghhS Compiler Design Lectures in Hindi by Easy Engineering Classes https://www.youtube.com/watch?v=hRM9ZvjbpVY&list=PLV8vIYTIdSnaeEO7C3elIV9u-Vj5G5CRF NPTEL Videos Principles of Compiler Design by Prof. Y. N. Srikant, Indian Institute of Science, Bangalore https://nptel.ac.in/courses/106108113/ Compiler Design by Santanu Chattopadhyay, IIT Kharagpur https://onlinecourses.nptel.ac.in/noc19_cs01/preview Notes Prepared by Chandrakanta Mahanty Assistant Professor Department of CSE & IT GIET University, Gunupur, Odisha 765022 +91 8093488380 Mail ID: chandra.mahanty@gmail.com/giet.edu 1 | Notes Prepared by Asst. Prof. Chandrakanta Mahanty

Text from page-4

Compiler Compiler is a translator program that translates a program written in (HLL) the source program and translates it into an equivalent program in (MLL) the target program. As an important part of a compiler is error showing to the programmer. Source target program program Compiler Error message Why Should We Study Compiler Design? Many applications for compiler technology   Parsers for HTML in web browser   Interpreters for JavaScript/flash   Machine code generation for high level languages   Software testing   Program optimization   Malicious code detection   Design of new computer architectures -Compiler-in-the-loop hardware development   Hardware synthesis: VHDL to RTL translation   Compiled simulation -Used to simulate designs written in VHDL -No interpretation of design, hence faster   Draws results from mathematical logic, lattice theory, linear algebra, probability, etc.  Makes practical application of Compiler Design   Greedy algorithms - register allocation   Heuristic search - list scheduling   Graph algorithms - dead code elimination, register allocation   Dynamic programming - instruction selection   Optimization techniques - instruction scheduling   Finite automata - lexical analysis   Pushdown automata - parsing   Fixed point algorithms - data-flow analysis   Complex data structures - symbol tables, parse trees, data dependence graphs  Computer architecture - machine code generation Other Uses of Scanning and Parsing Techniques   Assembler implementation   Online text searching (GREP, AWK) and word processing   Website filtering   Command language interpreters   Scripting language interpretation (Unix shell, Perl, Python)   XML parsing and document tree construction  Database query interpreters Phases of Compiler Compiler operates in phases. • Each phase transforms the source program from one representation to another. • Six phases: – Lexical Analyzer – Syntax Analyzer – Semantic Analyzer – Intermediate code generation – Code optimization – Code Generation • Symbol table and error handling interact with the six phases. 2 | Notes Prepared by Asst. Prof. Chandrakanta Mahanty

Lecture Notes