SlideServe
Menu
Préférences
© SlideServe · v2026

Overview of Compilation

morrison avatar
28 diapositives · 454 Views · Aug 30, 2014

This comprehensive overview by Dr. Manuel E. Bermúdez delves into programming language translators, focusing on compilers and interpreters. A translator is defined as an algorithm that converts source code into an equivalent target program, while compilers target a lower-level language. The document outlines the phases of compilation, including analysis and synthesis, and discusses key concepts like lexical analysis, parsing, and code generation. It provides insights into the functionality of programming language implementations, static semantics, type checking, and the various methods employed in code translation and generation.

Overview of Compilation - slide 1
01 / 28Overview of Compilation
1 / 17

Télécharger la présentation

Overview of Compilation
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Overview of Compilation Programming Language Translators Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida

  2. Target Source Translator Overview of Translation • Definition: A translator is an algorithm that converts source programs into equivalent target programs. • Definition: A compiler is a translator whose target language is at a “lower” level than its source language.

  3. input Source Interpreter output Overview of Translation (cont’d) • When is one language’s level “lower” than another’s? • Definition: An interpreter is an algorithm that simulates the execution of programs written in a given source language.

  4. Overview of Translation (cont’d) • Definition: An implementation of a programming language consists of a translator (or compiler) for that language, and an interpreter for the corresponding target language. input Source Target Compiler Interpreter output

  5. Translation • A source program may be translated an arbitrary number of times before the target program is generated. Source Translator1 Translator2 ... TranslatorN Target

  6. Translation (cont’d) • Each of these translations is called a phase, not to be confused with a pass, i.e., a disk dump. Q: How should a compiler be divided into phases? A: So that each phase can be easily described by some formal model of computation, and so the phase can be carried out efficiently.

  7. Translation (cont’d) Q: How is a compiler usually divided? A: Two major phases, with many possibilities for subdivision. • Phase 1: Analysis (determine correctness) • Phase 2: Synthesis (produce target code) • Another criterion: • Phase 1: Syntax (form). • Phase 2: Semantics (meaning).

  8. Typical Compiler Breakdown • Scanning (Lexical analysis). • Goal: Group sequences of characters that occur on the source, into logical atomic units called tokens. • Examples of tokens: Identifiers, keywords, integers, strings, punctuation marks, “white spaces”, end-of-line characters, comments, etc., … Scanner (Lexical analysis) Source Sequence of Tokens

  9. Example (see diagram) • Probably must deal with end-of-line and end-of-file characters. • A preliminary classification of tokens is made. For example, both ‘program’ and ‘Ex’ are classified as Identifier. • Someone must give unambiguousrules for forming tokens.

  10. Sequence of Tokens Screener Sequence of Tokens Screening • Goals: • Remove unwanted tokens. • Classify keywords. • Merge/simplify tokens.

  11. Example (see diagrams) • Keywords recognized. • White spaces (and comments) discarded. • The screener acts as an interface between the scanner and the next phase, the parser.

  12. Parsing (Syntax Analysis) • Goals • To group together the tokens, into the correct syntactic structures, if possible. • To determine whether the tokens appear in patterns that syntactically correct.

  13. Parsing (Syntax Analysis, cont’d) • Syntactic structures: • Expressions • Statements • Procedures • Functions • Modules • Methodology: • Use “re-write” rules (a.k.a. BNF).

  14. String-To-Tree Transduction (see diagrams) • Goal: To build a “syntax tree” from the sequence of rewrite rules. The tree will be the functional representation of the source. • Method: Build tree “bottom-up,” as the rewrite rules are emitted. Use a stack of trees.

  15. Contextual Constraint Analysis • Goal: To analyze static semantics, e.g., • Are all variables declared before they are used? • Is there assignment compatibility? • e.g., a:=3 • Is there operator type compatibility? • e.g., a+3 • Do actual and formal parameter types match? • Enforcement of scope rules.

  16. Contextual Constraint Analysis (cont’d) • Method: Traverse the tree recursively, deducing type information at the bottom, and passing it up. • Make use of a DECLARATION TABLE, to record information about names. • “Decorate” tree with reference information.

  17. Example Chronologically, • Enter x into the DCLN table, with its type. • Check type compatibility for x = 5. • X2 not declared! • Verify type of ’>’ is boolean. • Check type compatibility for ‘+’. • Check type compatibility between x and int (‘+’).

  18. Code Generation • Goal: Convert syntax tree to target code. Target code could be: • Machine language. • Assembly language. • Quadruples for a fictional machine: • label • opcode • operands (1 or 2)  

  19. Code Generation (cont’d) • Example: • “pc” on UNIX generates assembly code • “pi” on UNIX generates code for the “p” machine, which is interpreted by… an interpreter. • pc: slow compilation, fast running code. • pi: fast compilation, slow running code. • Method: Traverse the tree again.

  20. LOAD 5 STORE X LOAD X LOAD 10 BGT COND L1 L2 L1 LOAD X LOAD 1 BADD STORE X GOTO L3 L2 . . . L3 Code (for a stack machine): See diagrams)

  21. Code Optimization • Goals: • Reduce the size of the target program. • Decrease the running time of the target. • Note: “Optimization” is a misnomer. Code improvement would be better. • Two types of optimization: • Peephole optimization (local). • Global optimization (improve loops, etc.).

  22. Code Optimization (cont’d) • Example (from previous slide): LOAD 5can beLOAD 5 STORE XreplacedSTND X LOAD Xwith Store non-destructively,i.e., store inX, but do not destroy value on top of stack.

  23. Summary Source Scanner Tokens Screener Tokens Error Routines Table Routines Parser Tree Constrainer Tree Code Generator Code (for an abstract machine) Interpreter Input Output

  24. Overview of Compilation Programming Language Translators Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida