1 / 15

CSC 415: Translators and Compilers Spring 2009

CSC 415: Translators and Compilers Spring 2009. Midterm Review. Midterm Review: Chapter 1. Context-free Grammar A finite set of terminal symbols A finite set of non-terminal symbols A start symbol A finite se to production rules Aspects of a programming language that need to be specified

dionne
Download Presentation

CSC 415: Translators and Compilers Spring 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 415: Translators and CompilersSpring 2009 Midterm Review

  2. Midterm Review: Chapter 1 • Context-free Grammar • A finite set of terminal symbols • A finite set of non-terminal symbols • A start symbol • A finite se to production rules • Aspects of a programming language that need to be specified • Syntax: form of programs • Contextual constraints: scope rules and type variables • Semantics: meaning of programs

  3. Midterm Review: Chapter 1 • Language specification • Informal: written in English • Formal: precise notation (BNF, EBNF) • Unambiguous • Consistent • Complete • Context-free language • Syntax tree • Phrase • Sentence

  4. Midterm Review: Chapter 1 • Syntax tree • Terminal node labeled by terminal symbol • Non-terminal nodes labeled b y non-terminal symbol • Abstract Syntax Tree (AST) • Each non-terminal node ius labeled by production rule • Each non-terminal node has exactly one subtree for each subprogram • Does not generate sentences

  5. Midterm Review: Chapter 2 • Translator • Accepts any text expressed in one language (source language) and generates a semantically-equivalent text expressed in another language (target language) • Compiler • Translates from high-level language into low-level language • Interpreter • A program that accepts any program (source program) expressed in a particular language (source language) and runs that source program immediately

  6. Midterm Review: Chapter 2 • Interpretive compiler • Combination of compiler and interpreter • Some of the advantages of each • Portable compiler • Compiled and run on any mainline, without change • Portability measured by proportion of code that remains unchanged • Portability is an economic issue • Bootstrapping • Using the language processor to process itself • Tombstone diagrams

  7. Midterm Review: Chapter 3 • Three phases of compilation • Syntactic analysis • Contextual analysis • Code generation • Single pass compilers • Multi-pass compilers • Compiler design issues • Speed • Space • Modularity • Flexibility • Semantic preserving transformations • Source language properties

  8. Midterm Review: Chapter 4 • Sub-phases of syntactic analysis • Scanning (lexical analysis) • Source program transformed to stream of tokens • Comments and blank spaces between tokens are discarded • Parsing • Source program in form of stream of tokens parsed to determine phrase structure • Parser treats each token as a terminal symbol • Representation of the phrase structure • A data structure representing the source program’s phrase structure • Typically an abstract syntax tree (AST)

  9. Midterm Review: Chapter 4 • Tokens • An atomic symbol of the source program • May consist of several characters • Classified according to kind • All tokens of the same kind can be freely interchanged without affecting the program’s phrase structure • Each token completely described by it’s kind and spelling • Token represented by tuple • Only kind of each token examined by parser • Spelling examined by contextual analyzer and/or code generator

  10. Midterm Review: Chapter 4 • Grammars • Regular expressions • “|” separates alternatives • “*” indicates that the previous item may be repeated zero or more times • “(“ and “)” are grouping parenthesis • e is the empty string • a special string of length 0 • Algebraic properties • Common extensions • Grammar transformations • Left factorization • Elimination of left recursion • Substitution of non-terminal symbols

  11. Midterm Review: Chapter 4 • Structure of compiler • Source code • Lexical analyzer • Parser & semantic analyzer • Intermediate code generation • Optimization • Assembly code generation • Assembly code

  12. Midterm Review: Chapter 4 • Scanning (lexical analysis) • What does it do? • Handles keywords (reserve words • Removes white space (tabs, spaces, new lines) • Removes comments • Perform look ahead • Error handling • Issues • Simpler design • Improve compiler efficiency • Enhance compiler portability

  13. Midterm Review: Chapter 4 • Parsing • Given an unambiguous, context-free grammar • Recognition of input string – sentence in grammar • Parsing an input string – determines its phrase structure • Why is unambiguous important? • Advantages of unambiguous, context-free grammars (see chart 81) • How do you know the syntax of a language is legal? • A legal program can be derived from the start symbol of the grammar

  14. Midterm Review: Chapter 4 • Parsing • Rightmost (replace rightmost non-terminal in each step) and leftmost (replaced leftmost non-terminal in each step) derivation • Bottom-up (reconstructs syntax tree from terminal nodes up toward the root node) and top-down (reconstructs syntax tree from the root node down towards the terminal nodes) • Predictive parsers • LL(1) • Recursive decent

  15. Midterm Review: Chapter 4 • Parsing • Converting EBNF production rules to parsing methods • Error repair

More Related