Lecture 20 DPDA / Review Topics Given a PDA construct a grammar for the language it accepts Deterministic PDAs Properties of CFLsReadings: November 5,

Slides:



Advertisements
Similar presentations
lec02-parserCFG March 27, 2017 Syntax Analyzer
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
CSCI 3130: Formal languages and automata theory Tutorial 5
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
142 Parsing start (a, Z 0 /aZ 0 ) ( a, a/aa ) (b, a/  ) ( , Z 0 /Z 0 ) For a given CFG G, parsing a string w is to check if w  L(G) and, if it is,
Pushdown Automata Part II: PDAs and CFG Chapter 12.
Chapter 4 Normal Forms for CFGs Chomsky Normal Form n Defn A CFG G = (V, , P, S) is in chomsky normal form if each rule in G has one of.
1 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
start 0, 4, 8 1, 5, 9 2, 6 3, 7 2 0,4,8 2, 6 3, 7 1, 5, 9 to state 2 to state 3 to state 1 to state 0 to state 1 to state 3 to state 0 to state.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Context-Free Grammars Lecture 7
1 Module 34 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Lecture 32 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
Normal forms for Context-Free Grammars
January 23, 2015CS21 Lecture 81 CS21 Decidability and Tractability Lecture 8 January 23, 2015.
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
CPSC 388 – Compiler Design and Construction
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 Dr. torng CFG → PDA construction Shows that for any CFL L, there exists a PDA M such that L(M) = L The reverse is true, but we skip the proof Parsing.
PDA: Sequence of moves By Diana Castro. PDA: Sequence of moves for aaabbb Move No. StateInputStack Symbol Move(s) 1q0q0 aZ0Z0 (q 1, aZ 0 ) 2q1q1 aa(q.
Pushdown Automata (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Syntax Analyzer Syntax Analyzer creates the syntactic structure of the given source program. This.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
Pushdown Automata (PDA) Intro
Parsing G Programming Languages May 24, 2012 New York University Chanseok Oh
Exercise 1 Consider a language with the following tokens and token classes: ident ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP.
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday on CFGs lecture #3.
1 Section 12.3 Context-Free Parsing We know (via a theorem) that the context-free languages are exactly those languages that are accepted by PDAs. When.
CS 44 – Jan. 29 Expression grammars –Associativity √ –Precedence CFG for entire language (handout) CYK algorithm –General technique for testing for acceptance.
1 1. Let A ={r, p, i } and B = { w, o, r, l, d }. What does each of the following (a), (b) and (c) denote? Briefly explain in plain English. (a) A * B.
Chapter 7 Pushdown Automata
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
lec02-parserCFG May 8, 2018 Syntax Analyzer
Theory of Computation Pushdown Automata pda Lecture #10.
Lecture 14 Push Down Automata (PDA)
Chapter 4 - Parsing CSCE 343.
Properties of Context-Free Languages
Lecture 22 Pumping Lemma for Context Free Languages
Context-free Languages
Lecture 8: Top-Down Parsing
CSCE 531 Compiler Construction
Midterm (Models of Computation, Fall, 2000)
The Pumping Lemma for CFL’s
Midterm #2 — Review problems
Key to Homework #8 1. For each of the following context-free grammars (a) and (b) below, construct an LL(k) parser with minimum k according to the following.
CS21 Decidability and Tractability
CS21 Decidability and Tractability
Pushdown Automata (PDA) Part 2
lec02-parserCFG May 27, 2019 Syntax Analyzer
Conversion of CFG to PDA Conversion of PDA to CFG
Lecture 18 Language Recognized by a PDA
Presentation transcript:

Lecture 20 DPDA / Review Topics Given a PDA construct a grammar for the language it accepts Deterministic PDAs Properties of CFLsReadings: November 5, 2008 CSCE 355 Foundations

– 2 – CSCE 355 Fall 2008 Last Time: Top-down parsing Algorithms Left-factoring From Grammars to PDA Section 6.3 Formal PDA Construction from CFLNew: When will our parsing algorithm be deterministic?Homework 1. …

– 3 – CSCE 355 Fall 2008 When will our parsing algorithm be deterministic? First(α ) = { x in T such that α  * x β } Then if A  α and A  β are two productions we are choosing from and the current input character is a which is in First(α) but not in First( β ) Then we choose the production A  α. So if First(α) ∩ First( β ) = ϕ then we can always deterministically choose There is a type of grammar that is LL(1) for which this works well. A grammar with no ε-productions is LL(1) if it satisfies the disjointness property above.

– 4 – CSCE 355 Fall 2008 Homework from Last time 1.Given the grammar simple4.y (and simple4.l)  Modify the semantic actions so that it produces a trace of productions involved in the parse.  If you look at the sequence do you notice anything? b) Strings of 0’s and 1’s such that no prefix has more 1’s than 0’s b,c

– 5 – CSCE 355 Fall 2008 %token INTEGER PLUS TIMES LPAREN RPAREN % line : expr '\n' {printf("Using Prod line -> expr \\n \n");} | line expr '\n' {printf("Using Prod line -> line expr \\n \n");} | line expr '\n' {printf("Using Prod line -> line expr \\n \n");} ; expr : expr PLUS term {printf("Using Prod expr -> expr PLUS term \n");} | term {printf("Using Prod expr -> term \n");} | term {printf("Using Prod expr -> term \n");} ; term : term TIMES factor {printf("Using Prod term -> term TIMES factor\n");} | factor {printf("Using Prod term -> factor \n");} | factor {printf("Using Prod term -> factor \n");} ; factor : LPAREN expr RPAREN {printf("Using Prod factor -> LP expr RP \n");} | INTEGER {printf("Using Prod factor -> INTEGER \n");} | INTEGER {printf("Using Prod factor -> INTEGER \n");} ;%

– 6 – CSCE 355 Fall 2008 cerberus>./simpleHW 2+3*7 Using Prod factor -> INTEGER Using Prod term -> factor Using Prod expr -> term Using Prod factor -> INTEGER Using Prod term -> factor Using Prod factor -> INTEGER Using Prod term -> term TIMES factor Using Prod expr -> expr PLUS term Using Prod line -> expr \n

– 7 – CSCE 355 Fall b) no prefix has more 1’s than 0’s 6.2.1b) Strings of 0’s and 1’s such that no prefix has more 1’s than 0’s qdead 0,Z 0 /0Z 0 0,0/00 1,0/ε 1,Z 0 /Z 0

– 8 – CSCE 355 Fall b St ΣΓ NextSt Γ*Γ* indx q0q0 aZ0Z0 q1q1 AAZ 0 1 q0q0 bZ0Z0 q2q2 BZ 0 2 q0q0 εZ0Z0 fε3 q1q1 aAq1q1 AAA4 q1q1 bAq1q1 ε5 q1q1 εZ0Z0 q0q0 Z0Z0 6 q2q2 aBq3q3 ε7 q2q2 bBq2q2 BB8 q2q2 εZ0Z0 q0q0 Z0Z0 9 q3q3 εBq2q2 ε10 q3q3 εZ0Z0 q1q1 AZ 0 11 (q 0, abb, Z 0 ) ├ (rule 1) (q 1, bb, AAZ 0 ) ├ (rule 5) (q 1, b, AZ 0 ) ├ (rule 5) (q 1, ε, Z 0 ) ├ (rule 6) (q 0, ε, Z 0 ) ├ (rule 3) (f, ε, ε)

– 9 – CSCE 355 Fall c St ΣΓ NextSt Γ*Γ* indx q0q0 aZ0Z0 q1q1 AAZ 0 1 q0q0 bZ0Z0 q2q2 BZ 0 2 q0q0 εZ0Z0 fε3 q1q1 aAq1q1 AAA4 q1q1 bAq1q1 ε5 q1q1 εZ0Z0 q0q0 Z0Z0 6 q2q2 aBq3q3 ε7 q2q2 bBq2q2 BB8 q2q2 εZ0Z0 q0q0 Z0Z0 9 q3q3 εBq2q2 ε10 q3q3 εZ0Z0 q1q1 AZ 0 11 (q 0, b 7 a 4, Z 0 ) ├ (rule 2) (q 2, b 6 a 4, BZ 0 ) ├ (rule 8) (q 2, b 5 a 4, BBZ 0 ) ├ (rule 8) … (q 2, ba 4, BBBBBBZ 0 ) ├ (r8) (q 2, a 4, BBBBBBBZ 0 ) ├ (r7) (q 3, a 3, BBBBBBZ 0 ) ├ (rule10) (q 2, a 3, BBBBBZ 0 ) ├ (rule7) (q 3, a 2, BBBBZ 0 ) ├ (rule10) (q 2, a 2, BBBZ 0 ) ├ (r7) (q 3, a 1, BBZ 0 ) ├ (rule10) (q 2, a 1, BZ 0 ) ├ (rule7) (q 3, ε, Z 0 ) ├ (rule11) (q 1, ε, AZ 0 ) ├ ( No rule!?)

– 10 – CSCE 355 Fall 2008 Sample Test 2 Minimize DFA problem 1

– 11 – CSCE 355 Fall 2008 Dump of Distinguished States Array A B C D E F G H A B C D E F G H A X B X C X D X E X F X X X X X X X G X H X

– 12 – CSCE 355 Fall 2008 Iteration 0 a=0 Iteration 0 a=1 Adding dist[A,D] since delta(A, 1) = B, delta(D, 1) = F and dist[B,F]=X Adding dist[A,G] since delta(A, 1) = B, delta(G, 1) = F and dist[B,F]=X Adding dist[B,D] since delta(B, 1) = D, delta(D, 1) = F and dist[D,F]=X Adding dist[B,G] since delta(B, 1) = D, delta(G, 1) = F and dist[D,F]=X Adding dist[C,D] since delta(C, 1) = E, delta(D, 1) = F and dist[E,F]=X Adding dist[C,G] since delta(C, 1) = E, delta(G, 1) = F and dist[E,F]=X Adding dist[D,E] since delta(D, 1) = F, delta(E, 1) = H and dist[F,H]=X Adding dist[D,H] since delta(D, 1) = F, delta(H, 1) = H and dist[F,H]=X Adding dist[E,B] since delta(E, 1) = H, delta(B, 1) = D and dist[H,D]=X Adding dist[E,G] since delta(E, 1) = H, delta(G, 1) = F and dist[H,F]=X Adding dist[G,H] since delta(G, 1) = F, delta(H, 1) = H and dist[F,H]=X Adding dist[H,B] since delta(H, 1) = H, delta(B, 1) = D and dist[H,D]=X

– 13 – CSCE 355 Fall 2008 Iteration 1 a=0 Iteration 1 a=1 Adding dist[A,B] since delta(A, 1) = B, delta(B, 1) = D and dist[B,D]=X Adding dist[A,C] since delta(A, 1) = B, delta(C, 1) = E and dist[B,E]=X Adding dist[A,E] since delta(A, 1) = B, delta(E, 1) = H and dist[B,H]=X Adding dist[A,H] since delta(A, 1) = B, delta(H, 1) = H and dist[B,H]=X Adding dist[B,C] since delta(B, 1) = D, delta(C, 1) = E and dist[D,E]=X Iteration 2 a=0 Iteration 2 a=1

– 14 – CSCE 355 Fall 2008 ABCDEFGH A.XXXXXXX BX.XXXXXX CXX.XXX DXXX.XXX EXXX.XX FXXXXX.XX GXXXXX.X HXXXXX. Equivalence Classes A's equivalence class is: A B's equivalence class is: B C's equivalence class is: C E H D's equivalence class is: D G E's equivalence class is: C E H F's equivalence class is: F G's equivalence class is: D G H's equivalence class is: C E H

– 15 – CSCE 355 Fall 2008 Formal PDA Construction from CFL Let G = (V, T, Q, S) P = ({q}, T, (V U T), δ, q, S) where δ is defined by: 1.δ (q, ε, A) = { (q, β ) | A  β is a production of G} 2.δ (q, a, a) = { (q, ε) }

– 16 – CSCE 355 Fall 2008 Homework CFG  PDA Convert the grammar S  aAA A  aS | bS | a To a PDA that accepts the same language by empty stack P = ({q}, {a,b}, {S,A,a,b}, δ, q, S) where δ is defined by: δ (q, a, a) = { (q, ε) } for all a in Σ 1.δ (q, a, a) = { (q, ε) } 2.δ (q, b, b) = { (q, ε) } δ (q, ε, A) = { (q, β ) | A  β in G} 1.δ (q, ε, S) = { (q, aAA) } 2.δ (q, ε, A) = { (q, aS), (q, bS), (q, a) }

– 17 – CSCE 355 Fall 2008 HW 10/ b,c PDA trace (tree of IDs) 1.δ(q, 0, Z 0 ) = { (q, XZ 0 ) } 2.δ(q, 0, X) = { (q, XX) } 3.δ(q, 1, X) = { (q, X) } 4.δ(q, ε, X) = { (p, ε) } 5.δ(p, ε, X) = { (p, ε) } 6.δ(p, 1, X) = { (p, XX) } 7.δ(p, 1, Z 0 ) = { (p, ε) } qp 0,Z 0 /XZ 0 0,X/XX 1,X/X ε,X/ε 1,X/XX 1,Z 0 / ε

– 18 – CSCE 355 Fall b (q, 0011, Z 0 ) (q, 011, XZ 0 )(p, 011, Z 0 ) (q, 11, XXZ 0 )(p, 11, XZ 0 ) (q, 1, XXZ 0 )(p, 1, XXZ 0 ) (q, ε, XXZ 0 )(p, 1, XZ 0 ) (p, 1, Z 0 )(p, ε, XZ 0 ) qp 0,Z 0 /XZ 0 0,X/XX 1,X/X ε,X/ε 1,X/XX 1,Z 0 / ε (p, ε, ε) (p, 1, Z 0 )(p, ε, XZ 0 ) (p, ε, ε) (p, 1, XZ 0 ) (p, 11, Z 0 ) (p, 1, ε) (p, ε, XXXZ 0 ) (p, ε, XXZ 0 ) (p, ε, XZ 0 ) (p, ε, Z 0 )

– 19 – CSCE 355 Fall 2008

– 20 – CSCE 355 Fall 2008

– 21 – CSCE 355 Fall 2008

– 22 – CSCE 355 Fall 2008

– 23 – CSCE 355 Fall 2008

– 24 – CSCE 355 Fall 2008