Compilers Overview.ppt

21
Compilers: Overview Compilers: Overview

description

it 6th semester elective subject

Transcript of Compilers Overview.ppt

  • Compilers: Overview

  • Compilers and InterpretersCompilation

    Translation of a program written in a source language into a semantically equivalent program written in a target languageOversimplified view:*CompilerError messagesSourceProgramTargetProgramInputOutput

    *

  • Compilers and Interpreters (contd)Interpretation

    Performing the operations implied by the source programOversimplified view:*InterpreterSourceProgramInputOutputError messages

  • Compilers and Interpreters (contd)Compiler: a program that translates an executable program in one language into an executable program in another language

    Interpreter: a program that reads an executable program and produces the results of running that program

    *

  • The Analysis-Synthesis Model of CompilationThere are two parts to compilation:

    Analysis Breaks up source program into pieces and imposes a grammatical structureCreates intermediate representation of source programDetermines the operations and records them in a tree structure, syntax treeKnown as front end of compiler*

  • The Analysis-Synthesis Model of Compilation (contd)Synthesis Constructs target program from intermediate representation Takes the tree structure and translates the operations into the target programKnown as back end of compiler

    *

  • A language-processing system*PreprocessorCompilerAssemblerLinkerSkeletal Source ProgramSource ProgramTarget Assembly ProgramRelocatable Object CodeAbsolute Machine CodeLibraries andRelocatable Object Files

    *

  • AnalysisIn compiling, analysis has three phases:

    Linear analysis: stream of characters read from left-to-right and grouped into tokens; known as lexical analysis or scanningHierarchical analysis: tokens grouped hierarchically with collective meaning; known as parsing or syntax analysisSemantic analysis: check if the program components fit together meaningfully*

  • Lexical analysisCharacters grouped into tokens.

    *

  • Syntax analysis (Parsing)Grouping tokens into grammatical phrasesCharacter groups recorded in symbol tableRepresented by a parse tree

    *

  • Syntax analysis (contd)Hierarchical structure usually expressed by recursive rulesRules for definition of expression:

    *

  • Semantic analysisChecks source program for semantic errorsGathers type information for subsequent code generation (type checking)Identifies operator and operands of expressions and statements

    *

  • Phases of a compiler*

  • Symbol-Table ManagementSymbol table data structure with a record for each identifier and its attributesAttributes include storage allocation, type, scope, etcAll the compiler phases insert and modify the symbol table

    *

  • Intermediate code generationProgram representation for an abstract machineShould have two properties

    Easy to produceEasy to translate into target programThree-address code is a commonly used form similar to assembly language

    *

  • Code optimization and generationCode Optimization

    Improve intermediate code by producing code that runs fasterCode Generation

    Generate target code, which is machine code or assembly code*

  • The Structure of a Compiler (8)*

    Parse treeAbstract Syntax Tree w/ AttributesNon-optimized Intermediate CodeOptimized Intermediate Code

    Target machine code

    *

  • The Grouping of PhasesCompiler front and back ends:

    Front end: Analysis steps + Intermediate code generationDepends primarily on the source languageMachine independentBack end: Code optimization and generationIndependent of source languageMachine dependent*

  • The Grouping of Phases (contd)Compiler passes:

    A collection of phases is done only once (single pass) or multiple times (multi pass)Single pass: reading input, processing, and producing output by one large compiler program; usually runs fasterMulti pass: compiler split into smaller programs, each making a pass over the source; performs better code optimization*

  • Compiler-Construction ToolsSoftware development tools are available to implement one or more compiler phases

    Scanner generatorsParser generatorsSyntax-directed translation enginesAutomatic code generatorsData-flow engines*

  • Thank You*

    *

    *

    *