COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.

Slides:



Advertisements
Similar presentations
Compiler construction in4020 – lecture 4 Koen Langendoen Delft University of Technology The Netherlands.
Advertisements

COP4020 Programming Languages
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
LANGUAGE TRANSLATORS: WEEK 3 LECTURE: Grammar Theory Introduction to Parsing Parser - Generators TUTORIAL: Questions on grammar theory WEEKLY WORK: Read.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 6, 10/02/2003 Prof. Roy Levow.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
CPS 506 Comparative Programming Languages Syntax Specification.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
LESSON 04.
Lecture 3: Parsing CS 540 George Mason University.
PZ03BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03BX –Recursive descent parsing Programming Language.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Mid-Terms Exam Scope and Introduction. Format Grades: 100 points -> 20% in the final grade Multiple Choice Questions –8 questions, 7 points each Short.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 3: Describing Syntax and Semantics
Chapter 3 – Describing Syntax
Compiler Design (40-414) Main Text Book:
Introduction to Parsing
Chapter 4 - Parsing CSCE 343.
G. Pullaiah College of Engineering and Technology
Programming Languages Translator
CS510 Compiler Lecture 4.
Lexical and Syntax Analysis
Parsing and Parser Parsing methods: top-down & bottom-up
Unit-3 Bottom-Up-Parsing.
Fall Compiler Principles Context-free Grammars Refresher
Chapter 3 Context-Free Grammar and Parsing
Introduction to Parsing (adapted from CS 164 at Berkeley)
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 5, 09/25/2003 Prof. Roy Levow.
Parsing IV Bottom-up Parsing
Chapter 3 – Describing Syntax
Table-driven parsing Parsing performed by a finite state machine.
Syntax Analysis Chapter 4.
Simplifications of Context-Free Grammars
Context-Free Grammars
Compiler Construction
Syntax versus Semantics
Compiler Lecture 1 CS510.
CS 363 Comparative Programming Languages
Compiler Design 4. Language Grammars
Regular Grammar - Finite Automaton
Lexical and Syntax Analysis
Top-Down Parsing CS 671 January 29, 2008.
Context-Free Grammars
CPSC 388 – Compiler Design and Construction
Context-Free Grammars
Programming Language Syntax 2
COP4020 Programming Languages
Chapter 2: A Simple One Pass Compiler
CSC 4181Compiler Construction Context-Free Grammars
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 4: Lexical and Syntax Analysis Sangho Ha
CSC 4181 Compiler Construction Context-Free Grammars
Context-Free Grammars
Fall Compiler Principles Context-free Grammars Refresher
Chapter 3 Describing Syntax and Semantics.
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Context-Free Grammars
Programming Languages 2nd edition Tucker and Noonan
COMPILER CONSTRUCTION
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003 Prof. Roy Levow.
Compiler design Review COMP 442/6421 – Compiler Design
Presentation transcript:

COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow

Syntax Analysis Recursive Descent Parsing Uses one procedure per construct Checks production one item at a time Verify tokens Recursively check constructs Easy to generate by hand

Parsing Routines Parse_operator() Parse_expression() (see fig. 1.13) Parser environment & support (see fig. 1.14) No context handling needed

Code Generation Simple stack machine PUSH n, ADD, MULT, PRINT Generate code by recursive traversal of parse tree (see fig. 1.18)

Interpretation Directly execute code from parse tree (see fig. 1.19)

Complete Compiler Structure (see fig. 1.21) Lexical Analysis Syntax Analysis Context Handling Intermediate Code Generation IC Optimization Symbolic Code Generation Symbolic Code Optimization Machine Code Generation Executable Code Output

Other Issues Run-time system Short-cuts Compiler Architecture Use assembler Output in a compilable language (like C) Compiler Architecture Narrow compiler Process small parts of program in multiple stages Wide compiler Complete each stage

Properties of a Good Compiler Generates correct code Conform to language specification Handle large programs Good compile speed Good error reporting Fast, small generated code

Other Issues Portability Retargetability Optimizations

Grammars Based on productions Classification Translation or replacement rules α→β meaning α is replaced by β Derivation: xαy => xβy Classification Based on limitations on form of α and β Context free: α is a single non-terminal symbol Regular: CF and β contains at most one non-terminal symbol

Context-free Grammars Non-terminals: Language components A, B, C Terminals: Symbols in language x, y, z Strings of grammar symbols Greek letters Empty sequence (string): ε Start symbol: LHS of first production, S

Derivations.1 A derivation is a sequence of replacements using productions A sentential form is a string derived from the start symbol The language defined by a grammar is the set of all sentential forms containing only terminal symbols that can be derived from the start symbol A leftmost derivation always replaces the leftmost non-terminal

Derivations.2 Sample derivation (see fig. 1.26) Parse tree Root is start symbol NT node has RHS of production for children See fig. 1.27

Extended Grammar Forms Backus-Naur Form (BNF) N→α | β | γ for alternatives Extended BNF R+ for 1 or more occurrence R* for 0 or more occurrences R? for 0 or 1 occurrence (optional item) Parentheses for grouping

Properties of Grammars Left-recursive production (or right-) N → Nα (N → αN) Nullable symbol N *=> ε Useless symbol never produces only terminal symbols Ambiguous Grammar Has two parse trees for same string

Closure Algorithms.1 Compute transitive closure of a relationship If aRb & bRc, then aRc Calling graph Direct and Indirect (closure) calls See figs. 1.28, 1.29

Closure Algorithms.2 Basic components of algorithm Data definitions: what are information items Initializations: where do we start Inference rules: apply repeatedly to get closure See fig. 1.31 for directed graph closure for subprogram calls General iterative algorithm See fig. 1.33