Lecture 4: Parsing. Administrivia

Similar documents
Source code. where each α ij is a terminal or nonterminal symbol. We say that. α 1 α m 1 Bα m+1 α n α 1 α m 1 β 1 β p α m+1 α n

CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

(1) Then we could wave our hands over this and it would become:

[ ] 1+ lim G( s) 1+ s + s G s s G s Kacc SYSTEM PERFORMANCE. Since. Lecture 10: Steady-state Errors. Steady-state Errors. Then

Strongly Connected Components

LR(0) Analysis. LR(0) Analysis

L 1 = L G 1 F-matrix: too many F ij s even at quadratic-only level

ME 321 Kinematics and Dynamics of Machines S. Lambert Winter 2002

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

COHORT MBA. Exponential function. MATH review (part2) by Lucian Mitroiu. The LOG and EXP functions. Properties: e e. lim.

Y 0. Standing Wave Interference between the incident & reflected waves Standing wave. A string with one end fixed on a wall

INTRODUCTION TO AUTOMATIC CONTROLS INDEX LAPLACE TRANSFORMS

The second condition says that a node α of the tree has exactly n children if the arity of its label is n.

Abstract Interpretation: concrete and abstract semantics

UNTYPED LAMBDA CALCULUS (II)

Probability and Stochastic Processes: A Friendly Introduction for Electrical and Computer Engineers Roy D. Yates and David J.

Week 3: Connected Subgraphs

Higher order derivatives

First derivative analysis

Economics 201b Spring 2010 Solutions to Problem Set 3 John Zhu

First order differential equation Linear equation; Method of integrating factors

Differentiation of Exponential Functions

Addition of angular momentum

Basic Polyhedral theory

u r du = ur+1 r + 1 du = ln u + C u sin u du = cos u + C cos u du = sin u + C sec u tan u du = sec u + C e u du = e u + C

CS 361 Meeting 12 10/3/18

From Elimination to Belief Propagation

with Dirichlet boundary conditions on the rectangle Ω = [0, 1] [0, 2]. Here,

Syntax Analysis. Context-free grammar Top-down and bottom-up parsing. cs5363 1

Math 34A. Final Review

September 23, Honors Chem Atomic structure.notebook. Atomic Structure

COMPSCI 230 Discrete Math Trees March 21, / 22

cycle that does not cross any edges (including its own), then it has at least

u 3 = u 3 (x 1, x 2, x 3 )

Chapter 10 Time-Domain Analysis and Design of Control Systems

The Transmission Line Wave Equation

ECE602 Exam 1 April 5, You must show ALL of your work for full credit.

Motivation (Cont d) Motivation (Cont d)

Dealing with quantitative data and problem solving life is a story problem! Attacking Quantitative Problems

Thus, because if either [G : H] or [H : K] is infinite, then [G : K] is infinite, then [G : K] = [G : H][H : K] for all infinite cases.

Roadmap. XML Indexing. DataGuide example. DataGuides. Strong DataGuides. Multiple DataGuides for same data. CPS Topics in Database Systems

Alpha and beta decay equation practice

CPSC 665 : An Algorithmist s Toolkit Lecture 4 : 21 Jan Linear Programming

That is, we start with a general matrix: And end with a simpler matrix:

Sundials and Linear Algebra

Calculus concepts derivatives

EEO 401 Digital Signal Processing Prof. Mark Fowler

Chapter 13 GMM for Linear Factor Models in Discount Factor form. GMM on the pricing errors gives a crosssectional

ELEC 372 LECTURE NOTES, WEEK 11 Dr. Amir G. Aghdam Concordia University

1 Minimum Cut Problem

ph People Grade Level: basic Duration: minutes Setting: classroom or field site

Integration by Parts

Transfer function and the Laplace transformation

22/ Breakdown of the Born-Oppenheimer approximation. Selection rules for rotational-vibrational transitions. P, R branches.

6.1 Integration by Parts and Present Value. Copyright Cengage Learning. All rights reserved.

Addition of angular momentum

Fourier Transforms and the Wave Equation. Key Mathematics: More Fourier transform theory, especially as applied to solving the wave equation.

Lecture 1: Numerical Integration The Trapezoidal and Simpson s Rule

perm4 A cnt 0 for for if A i 1 A i cnt cnt 1 cnt i j. j k. k l. i k. j l. i l

The Matrix Exponential

Deift/Zhou Steepest descent, Part I

SECTION where P (cos θ, sin θ) and Q(cos θ, sin θ) are polynomials in cos θ and sin θ, provided Q is never equal to zero.

10. Limits involving infinity

Engineering Differential Equations Practice Final Exam Solutions Fall 2011

Problem Set 6 Solutions

Computing and Communications -- Network Coding

Even/Odd Mode Analysis of the Wilkinson Divider

Abstract Interpretation. Lecture 5. Profs. Aiken, Barrett & Dill CS 357 Lecture 5 1

The Matrix Exponential

MCE503: Modeling and Simulation of Mechatronic Systems Discussion on Bond Graph Sign Conventions for Electrical Systems

Multiple Short Term Infusion Homework # 5 PHA 5127

Final Exam : Solutions

A Quadratic Serendipity Plane Stress Rectangular Element

The van der Waals interaction 1 D. E. Soper 2 University of Oregon 20 April 2012

Brief Introduction to Statistical Mechanics

MSLC Math 151 WI09 Exam 2 Review Solutions

1 Isoparametric Concept

Objective Mathematics

Ma/CS 6a Class 15: Flows and Bipartite Graphs

General Notes About 2007 AP Physics Scoring Guidelines

Construction of asymmetric orthogonal arrays of strength three via a replacement method

Last time. Resistors. Circuits. Question. Quick Quiz. Quick Quiz. ( V c. Which bulb is brighter? A. A B. B. C. Both the same

Gradebook & Midterm & Office Hours

ME 200 Thermodynamics I Spring 2014 Examination 3 Thu 4/10/14 6:30 7:30 PM WTHR 200, CL50 224, PHY 112 LAST NAME FIRST NAME

Lecture 37 (Schrödinger Equation) Physics Spring 2018 Douglas Fields

Homework #3. 1 x. dx. It therefore follows that a sum of the

Chapter 8: Electron Configurations and Periodicity

Prod.C [A] t. rate = = =

Partial Derivatives: Suppose that z = f(x, y) is a function of two variables.

DISCRETE TIME FOURIER TRANSFORM (DTFT)

MATH 319, WEEK 15: The Fundamental Matrix, Non-Homogeneous Systems of Differential Equations

LaPlace Transform in Circuit Analysis

Differential Equations

In the previous two chapters, we clarified what it means for a problem to be decidable or undecidable.

priority queue ADT heaps 1

Background: We have discussed the PIB, HO, and the energy of the RR model. In this chapter, the H-atom, and atomic orbitals.

Lie Groups HW7. Wang Shuai. November 2015

Aim To manage files and directories using Linux commands. 1. file Examines the type of the given file or directory

u x v x dx u x v x v x u x dx d u x v x u x v x dx u x v x dx Integration by Parts Formula

y = 2xe x + x 2 e x at (0, 3). solution: Since y is implicitly related to x we have to use implicit differentiation: 3 6y = 0 y = 1 2 x ln(b) ln(b)

Transcription:

Adminitrivia Lctur 4: Paring If you do not hav a group, pla pot a rqut on Piazzza ( th Form projct tam... itm. B ur to updat your pot if you find on. W will aign orphan to group randomly in a fw day. Programming Contt coming up. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4

A Glanc at th Map Sourc cod Lxical Analyi Tokn Paring AST Smantic Analyi Dcoratd AST W ar hr Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 2

Rviw: BNF BNF i anothr pattrn-matching languag; Alphabt typically t of tokn, uch a from lxical analyi, rfrrd to a trminal ymbol or trminal. Matching rul hav form: X : α α 2 α n, whr X i from a t of nontrminal ymbol (or nontrminal or mta-variabl), n, and ach α i i a trminal or nontrminal ymbol. For mphai, may writ X : ǫ whn n =. Rad X : α α 2 α n, a An X may b formd from th concatnation of an α, α 2,..., α n. Dignat on nontrminal a th tart ymbol. St of all matching rul i a contxt-fr grammar. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 3

Rviw: Drivation String (of trminal) T i in th languag dcribd by grammar G, (T L(G)) if thr i a drivation of T from th tart ymbol of G. Drivation of T = τ τ k from nontrminal A i qunc of ntntial form: A α α 2... α 2 α 22... τ...τ k whr ach α ij i a trminal or nontrminal ymbol. W ay that α α m Bα m+ α n α α m β β p α m+ α n if B : β β p i a production. ( m n). If Φ and Φ ar ntntial form, thn Φ = Φ 2 man that or mor tp turn Φ into Φ 2. Φ + = Φ 2 man or mor tp do it. So if S i tart ymbol of G, thn T L(G) iff S + = T. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 4

Exampl of Drivation. : ID 2. : ( ) 3. : / 4. : 5. : + 6. : - Altrnativ Notation : ID ( ) / : ǫ + - Problm: Driv - ID / ( ID / ID ) 3 6 = / = ID / = - ID / = - ID / ( ) 4 3 = - ID / ( ) = - ID / ( / ) = - ID / ( ID / ) 4 = - ID / ( ID / ) = - ID / ( ID / ID ) 4 = - ID / ( ID / ID ) 2 Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 5

Typ of Drivation Contxt fr man can rplac nontrminal in any ordr (i.., rgardl of contxt) to gt am rult (a long a you u am production). So, if w u a particular rul for lcting nontrminal to produc from, can charactriz drivation by jut liting production. Prviou xampl wa lftmot drivation: alway choo lftmot nontrminal. Compltly charactrizd by lit of production: 3,, 6, 2, 4, 3,, 4,, 4. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 6

Drivation and Par Tr A lftmot drivation alo compltly charactrizd by par tr: - ID / ( ID / ID ) What i th rightmot drivation for thi?

Drivation and Par Tr A lftmot drivation alo compltly charactrizd by par tr: - ID / ( ID / ID ) What i th rightmot drivation for thi? 3 2 3 = / = / ( ) = / ( / ) 4 = / ( / ID ) = / ( / ID ) 4 = / ( ID / ID ) = / ( ID / ID ) 4 6 = / ( ID / ID ) = ID / ( ID / ID ) = - ID / ( ID / ID ) Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 7

Ambiguity Only on drivation for prviou xampl. What about ID / ID / ID? Claim thr ar two par tr, corrponding to two lftmot drivation. What ar thy? If thr xit vn on tring lik ID / ID / ID in L(G), w ay G i ambiguou (vn if othr tring only hav on par tr). Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 8

Ambiguity Only on drivation for prviou xampl. What about ID / ID / ID? Claim thr ar two par tr, corrponding to two lftmot drivation. What ar thy? - ID/ ID / ID - ID / If thr xit vn on tring lik ID / ID / ID in L(G), w ay G i ambiguou (vn if othr tring only hav on par tr). ID / ID Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 8

Rviw: Syntax-Dirctd Tranlation Want th tructur of ntnc, not jut whthr thy ar in th languag, bcau thi driv tranlation. Aociat tranlation rul to ach production, jut a Flx aociatd action with matching pattrn. Bion notation: : / { $$ = dodivid($, $3); } provid way to rfr to and t mantic valu on ach nod of a par tr. Comput th mantic valu from lav up th par tr. Sam a th ordr of a rightmot drivation in rvr (a.k.a a canonical drivation). Altrnativly, jut prform arbitrary action in th am ordr. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 9

Exampl: Conditional tatmnt Problm: if-l or if-lif-l tatmnt in Python (l optional). Aum that only(indntd) uit may b ud for thn and l clau, that nontrminal tmt dfin an individual tatmnt(on pr lin), and that nontrminal xpr dfin an xprion. Lxr uppli INDENT and DEDENT. A cond i a kind of tmt. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4

Exampl: Conditional tatmnt Problm: if-l or if-lif-l tatmnt in Python (l optional). Aum that only(indntd) uit may b ud for thn and l clau, that nontrminal tmt dfin an individual tatmnt(on pr lin), and that nontrminal xpr dfin an xprion. Lxr uppli INDENT and DEDENT. A cond i a kind of tmt. xpr :... tmt :... cond... cond : "if" xpr : uit lif l uit: INDENT tmt DEDENT tmt: tmt tmt tmt lif: ǫ "lif" xpr : uit lif l : ǫ "l" : uit Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4

Exampl: Conditional tatmnt in Java Problm: if-l in Java. Aum that nontrminal tmt dfin an individual tatmnt (including a block in {}). Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4

Exampl: Conditional tatmnt in Java Problm: if-l in Java. Aum that nontrminal tmt dfin an individual tatmnt (including a block in {}). xpr :... tmt :... cond... cond : "if" ( xpr ) tmt l l : ǫ "l" tmt But thi don t quit work: rcogniz corrct tatmnt and rjct incorrct on, but i ambiguou. E.g., if (foo) if (bar) walk(); l chwgum(); Do w chw gum if foo i fal? That i, i thi quivalnt to if (foo) { if (bar) walk(); } l chwgum(); /*or*/ if (foo) { if (bar) walk(); l chwgum(); }? Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4

Exampl rolvd: Conditional tatmnt in Java Th rul i uppod to b ach l attach to th nart opn if on th lft, which i capturd by: xpr :... tmt :... cond... tmt_clod :... cond_clod... cond_clod : "if" ( xpr ) tmt_clod "l" tmt_clod cond : "if" ( xpr ) tmt "if" ( xpr ) tmt_clod "l" tmt Thi do not allow u to intrprt a if (foo) if (bar) walk(); l chwgum(); if (foo) { if (bar) walk(); } l chwgum(); But it not xactly clar, i it? Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 2

Puzzl: NFA to BNF Problm: What BNF grammar accpt th am tring a thi NFA? ǫ 2 3 ǫ 4 ǫ 5 6 7 ǫ Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 3

Puzzl: NFA to BNF Problm: What BNF grammar accpt th am tring a thi NFA? ǫ 2 ǫ 3 ǫ 4 5 6 7 A convntional anwr (from cla): S: S2 Z S3 Z S2: Z Z Z: Z ǫ S3: Z Z Z S2: S2 S2 S2 S3: S3 S3 S3 ǫ Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 3

Puzzl: NFA to BNF Problm: What BNF grammar accpt th am tring a thi NFA? ǫ 2 ǫ 3 ǫ 4 5 6 7 ǫ Gnral anwr (adaptabl to any NFA), with on nontrminal pr tat: S: S S4 S4: S5 S4 S: S2 S S5: S6 S5 S2: S3 S2 S6: S7 S6 S3: S S3 ǫ S7: S4 S7 ǫ Nontrminal Sk i th t of tring that will gt m from Sk in th NFA to a final tat in th NFA. Lat modifid: Tu Sp 24 2:59:58 23 CS64: Lctur #4 3