1 / 29

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453. FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. CONTEXT-FREE GRAMMARS AND PUSH-DOWN AUTOMATA. NONE OF THESE ARE REGULAR. Σ = {0, 1}, L = { 0 n 1 n | n ≥ 0 }. Σ = {a, b, c, …, z}, L = { w | w = w R }. Σ = { (, ) }, L = { balanced strings of parens }.

Download Presentation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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. 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

  2. CONTEXT-FREE GRAMMARS AND PUSH-DOWN AUTOMATA

  3. NONE OF THESE ARE REGULAR Σ = {0, 1}, L = { 0n1n | n ≥ 0 } Σ = {a, b, c, …, z}, L = { w | w = wR } Σ = { (, ) }, L = { balanced strings of parens } (), ()(), (()()) are in L, (, ()), ())(() are not in L

  4. FINITE STATE CONTROL INPUT STACK (Last in, first out) PUSHDOWN AUTOMATA (PDA)

  5. input pop push ε,ε → $ 0,ε→0 11 0011 0011 011 1,0→ε ε,$ → ε 1,0→ε 1 0 STACK $ 0 $ $ Non-deterministic

  6. input pop push ε,ε → $ 0,ε→0 1 001 001 01 1,0→ε ε,$ → ε 1,0→ε 0 STACK $ 0 $ $ PDA that recognizes L = { 0n1n | n ≥ 0 }

  7. Definition: A (non-deterministic) PDA is a tuple P = (Q, Σ, Γ, , q0, F), where: Q is a finite set of states Σ is the input alphabet Γ is the stack alphabet  : Q Σε Γε→ 2 Q  Γε q0 Q is the start state F  Q is the set of accept states 2Q is the set of subsets of Q and Σε = Σ {ε}

  8. Let w Σ* and suppose w can be written as • w1... wn where wi Σε(recall Σε = Σ {ε}) • Then P acceptsw if there are • r0, r1, ..., rn Q and • s0, s1, ..., sn Γ*(sequence of stacks)such that • r0 = q0 and s0 = ε (P starts in q0with empty stack) • For i = 0, ..., n-1: • (ri+1 , b)(ri, wi+1, a), where si =at and si+1 = bt for some a, bΓε and tΓ* • (P moves correctly according to state, stack and symbol read) • 3. rn  F (P is in an accept state at the end of its input)

  9. ε,ε → $ 0,ε→ 0 q0 q1 1,0→ε ε,$ → ε q3 q2 1,0→ε Q = {q0, q1, q2, q3} Σ = {0,1} Γ = {$,0,1}  : Q Σε Γε→ 2 Q  Γε (q1,1,0) = { (q2,ε) } (q2,1,1) = 

  10. EVEN-LENGTH PALINDROMES Σ = {a, b, c, …, z} ε,ε → $ ,ε→ q0 q1 ε,ε→ε ε,$ → ε ,→ε q3 q2

  11. c,ε→ε b,a→ε q2 q3 q0 ε,$ → ε ε,ε → ε ε,ε → $ q1 q4 ε,ε → ε ε,ε → ε ε,$ → ε q6 q5 a,ε→ a b,ε→ε c,a→ε Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) } choose i=j choose i=k

  12. CONTEXT-FREE GRAMMARS production rules start variable A → 0A1 A → B B → # variables terminals A  00A11  00B11  00#11 • 0A1 • (yields) Derivation A * 00#11 (derives) We say: 00#11is generated by the Grammar Non-deterministic

  13. CONTEXT-FREE GRAMMARS A → 0A1 A → B B → # A → 0A1 |B B → #

  14. CONTEXT-FREE GRAMMARS A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where: V is a finite set of variables Σ is a finite set of terminals (disjoint from V) R is set of production rules of the form A → W, where A  V and W  (VΣ)* S  V is the start variable • L(G) = {w  Σ* | S * w} Strings Generated by G

  15. CONTEXT-FREE LANGUAGES A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where: V is a finite set of variables Σ is a finite set of terminals (disjoint from V) R is set of production rules of the form A → W, where A  V and W  (VΣ)* S  V is the start variable G = { {S}, {0,1}, R, S } R = { S → 0S1, S → ε } • L(G) =

  16. CONTEXT-FREE LANGUAGES A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where: V is a finite set of variables Σ is a finite set of terminals (disjoint from V) R is set of production rules of the form A → W, where A  V and W  (VΣ)* S  V is the start variable G = { {S}, {0,1}, R, S } R = { S → 0S1, S → ε } • L(G) = { 0n1n | n ≥ 0 } Strings Generated by G

  17. WRITE A CFG FOR EVEN-LENGTH PALINDROMES S → S for all   Σ S → ε

  18. WRITE A CFG FOR THE EMPTY SET G = { {S}, Σ, , S }

  19. PARSE TREES A A A B 0 0 # 1 1 A  0A1  00A11  00B11  00#11

  20. <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> <EXPR> a + a x a a + a x a <EXPR> → <EXPR> + <EXPR> <EXPR> → <EXPR> x <EXPR> <EXPR> → ( <EXPR> ) <EXPR> → a Build a parse tree for a + a x a

  21. Definition: a string is derived ambiguously in a context-free grammar if it has more than one parse tree Definition: a grammar is ambiguous if it generates some string ambiguously See G4 for unambiguous standard arithmetic precedence

  22. NOT REGULAR Σ = {0, 1}, L = { 0n1n | n ≥ 0 } But L is CONTEXT FREE A → 0A1 A → ε WHAT ABOUT? Σ = {0, 1}, L1 = { 0n1n 0m| m,n ≥ 0 } Σ = {0, 1}, L2 = { 0n1m 0n| m,n ≥ 0 } Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }

  23. THE PUMPINGLEMMA FOR CFGs Let L be a context-free language Then there is a P such that if w  L and |w| ≥ P then can write w = uvxyz, where: 1. |vy| > 0 2. |vxy| ≤ P 3. For every i ≥ 0, uvixyiz  L

  24. T T R R R R R R y v u z u v x y z v x y Idea of Proof: If w is long enough, then any parse tree for w must have a path that contains a variable more than once

  25. Formal Proof: Let b be the maximum number of symbols on the right-hand side of any rule If the height of a parse tree is h, the length of the string generated by that tree is at most: bh Let |V| be the number of variables in G Define P = b|V|+2 Let w be a string of length at least P Let T be a parse tree for w with a minimum number of nodes. T must have height at least |V|+2

  26. T T R R R R R R y v u z u v x y z v x y The longest path in T must have ≥ |V|+1 variables Select R to be the variable that repeats among the lowest |V|+1 variables (in the path) 1. |vy| > 0 2. |vxy| ≤ P Let T be a parse tree for w with a minimum number of nodes. T must have height at least |V|+2

  27. WHAT ABOUT? Σ = {0, 1}, L1 = { 0n1n 0m| m, n ≥ 0 } Σ = {0, 1}, L2 = { 0n1m 0n| m, n ≥ 0 } Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }

  28. EQUIVALENCE OF CFGs and PDAs A Language L is generated by a CFG  L is recognized by a PDA

  29. Read the rest of Chapter 2 for next time

More Related