Compiler Design - Tutorialspoint

2y ago
115 Views
19 Downloads
929.41 KB
22 Pages
Last View : 10d ago
Last Download : 3m ago
Upload by : Adele Mcdaniel
Transcription

Compiler Designi

Compiler DesignAbout the TutorialA compiler translates the codes written in one language to some other language withoutchanging the meaning of the program. It is also expected that a compiler should make thetarget code efficient and optimized in terms of time and space.Compiler design principles provide an in-depth view of translation and optimization process.Compiler design covers basic translation mechanisms and error detection & recovery. Itincludes lexical, syntax, and semantic analysis as front end, and code generation andoptimization as back-end.AudienceThis tutorial is designed for students interested in learning the basic principles of compilers.Enthusiastic readers who would like to know more about compilers and those who wish todesign a compiler themselves may start from here.PrerequisitesThis tutorial requires no prior knowledge of compiler design but requires a basic understandingof at least one programming language such as C, Java, etc. It would be an additionaladvantage if you have had prior exposure to Assembly Programming.Copyright & Disclaimer Copyright 2014 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I)Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republishany contents or a part of contents of this e-book in any manner without written consent ofthe publisher.We strive to update the contents of our website and tutorials as timely and as precisely aspossible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our websiteor its contents including this tutorial. If you discover any errors on our website or in thistutorial, please notify us at contact@tutorialspoint.comi

Compiler DesignTable of ContentsAbout the Tutorial ··········· iAudience ························· iPrerequisites ··················· iCopyright & Disclaimer ···· iTable of Contents ··········· ii1.COMPILER DESIGN – OVERVIEW ······················· 1Language Processing System ··················· 1Preprocessor ···················2Interpreter bler ker ·····2Loader ····3Cross-compiler ················3Source-to-source Compiler PILER DESIGN –ARCHITECTURE ················· 4Analysis Phase ·················4Synthesis �·················43.COMPILER DESIGN – PHASES OF COMPILER ······ 5Lexical Analysis ···············6Syntax ····················6Semantic Analysis ···········6Intermediate Code Generation ················6Code Optimization ··········6Code Generation ·············6Symbol ILER DESIGN – LEXICAL ANALYSIS ············ 8Tokens ··· 8Specifications of Tokens · 9Alphabets trings ····9Special Symbols ··············9Language COMPILER DESIGN – REGULAR EXPRESSIONS ·· 11ii

Compiler DesignOperations s edence and Associativity ················126.COMPILER DESIGN – FINITE AUTOMATA ········· 13Finite Automata Construction ··············· 13Longest Match Rule ······ 147.COMPILER DESIGN – SYNTAX ANALYSIS ··········· 15Context-Free Grammar · 15Syntax Analyzers ·········· 16Derivation ···················· 17Left-most Derivation ·····17Right-most Derivation ···17Parse Tree ···················· 18Ambiguity ciativity ··················21Precedence ···················22Left Recursion ···············22Left Factoring ················24First and Follow Sets ····· 25First Set 25Follow Set tions of Syntax Analyzers ············· 268.COMPILER DESIGN – TYPES OF PARSING ········· 27Top-down Parsing ········· 27Bottom-up �··········· 279.COMPILER DESIGN – TOP-DOWN PARSING ····· 29Recursive Descent Parsing racking ················30Predictive Parser ···········30LL Parser LL Parsing Algorithm ·····3210.COMPILER DESIGN – BOTTOM-UP PARSING ···· 34Shift-Reduce Parsing ·····34iii

Compiler DesignLR Parser ·······················34LL vs. LR ························ 3611.COMPILER DESIGN – ERROR RECOVERY ·········· 37Panic Mode ···················37Statement Mode ···········37Error Productions ··········37Global Correction ··········37Abstract Syntax Trees ···3812.COMPILER DESIGN – SEMANTIC ANALYSIS ······ 40Semantics ····················· 40Semantic Errors ············ 41Attribute Grammar ······· 41Synthesized Attributes ··41Inherited Attributes ······42S-attributed SDT ··········· 43L-attributed SDT ··········· 4313.COMPILER DESIGN – RUNTIME ENVIRONMENT ······················· 45Activation �·············· 45Storage Allocation ········ 47Static Allocation ··········· 47Stack Allocation ············ 48Heap Allocation ············ 48Parameter Passing ········ 49r-value ··49l-value ··49Formal Parameters ·······49Actual Parameters ········50Pass by �·················· 50Pass by Reference ········· 50Pass by Copy-restore ···· 50iv

Compiler DesignPass by Name ··············· 5114.COMPILER DESIGN – SYMBOL TABLE ··············· ···················· 52Operations ··················· 53insert() ······53Scope Management ······ 5415.COMPILER DESIGN – INTERMEDIATE CODE GENERATION ······· 56Intermediate Representation ················ 56Three-Address Code ····· 57Declarations ················· 5816.COMPILER DESIGN – CODE GENERATION ········ 60Directed Acyclic Graph · 60Peephole Optimization · 61Redundant Instruction Elimination ········61Unreachable Code ········62Flow of Control gebraic Expression Simplification ·······63Strength Reduction ·······63Accessing Machine Instructions ·············63Code Generator ····················

Compiler Design 10 A compiler can broadly be divided into two phases based on the way they compile. Analysis Phase Known as the front-end of the compiler, the analysis phase of the compiler reads the source program, divides it into core parts,

Related Documents:

COMPILER DESIGN LECTURE NOTES . Department of CSE - 2 - UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. . 1.9 STRUCTURE OF THE COMPILER DESIGN Phases of a compiler: A compiler

Compiler Design 10 A compiler can broadly be divided into two phases based on the way they compile. Analysis Phase Known as the front-end of the compiler, the analysis phase of the compiler reads the source program, divides it into core parts, and then checks for lexical, grammar, and syntax errors.

This C programming language compiler will be used to compile your source code into final executable program. I assume you have basic knowledge about a programming language compiler. Most frequently used and free available compiler is GNU C/C compiler, otherwise you can have compilers either from HP or Solaris if you have respective Operating .

In particular you need: Linux { Compilers either Intel Fortran Compiler versions 14 or 15 with correspond-ing Intel C Compiler or GNU’s Compiler Collection 4.9.2, both gfortran and gcc { GNU’s make, gmake, version 3.77 or 3.81 { perl, version 5.10 Cray/Linux { either Intel Fortran Compiler versions 14 or 15 with corresponding Intel C Compiler

IAR ARM compiler 6.3 and higher GNU C Compiler for ARM architecture Arm Keil C/C compiler 5.4 and higher For the ColdFire devices, the following compilers are supported: CodeWarrior for MCU, 10.1 and higher. IAR ColdFire C compiler 1.2 GNU C Compiler for ColdFire architecture The Microco

May 2010 A Non-Confidential ARM Compiler toolchain v4.1 Release 30 September 2010 B Non-Confidential Update 1 for ARM Compiler toolchain v4.1 28 January 2011 C Non-Confidential Update 2 for ARM Compiler toolchain v4.1 Patch 3 30 April 2011 C Non-Confidential Update 3 for ARM Compiler toolchain v4.1 Patch 4

Aug 24, 2009 · Lecture Notes on Compiler Design: Overview 15-411: Compiler Design Frank Pfenning Lecture 1 August 24, 2009 1 Introduction This course is a thorough introduction to compiler design, focusing on more low-level and systems aspects rather than high-level questions such as polymorphic type inference or separate compilation. You will be build-File Size: 255KB

Artificial intelligence (AI) – a broad concept used in policy discussions to refer to many different types of technology – greatly influences and impacts the way people seek, receive, impart and access information and how they exercise their right to freedom of expression in the digital ecosystem. If implemented responsibly, AI can benefit societies, but there is a genuine risk that its .