Presentation is loading. Please wait.

Presentation is loading. Please wait.

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.

Similar presentations


Presentation on theme: "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."— Presentation transcript:

1 INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011

2 THE PUMPING LEMMA Let L be a regular language with |L| =  Then there exists a length P such that 1. |y| > 0 2. |xy| ≤ P 3. xy i z  L for any i ≥ 0 ∀ w  L, if |w| ≥ P then there exist xyz = w where:

3 PUMPING NON-REGULAR LANGUAGES Let F = {a i b j c k | i, j, k ≥ 0 and i=1 ⇒ j=k} F has pumping length 2! F ∩ ab*c* = {ab n c n | n ≥ 0} i = 0 i = 1 i = 2 A non-regular language may still satisfy the pumping lemma.

4 4011 SO FAR… MODEL OF A PROGRAM: DFA MODEL OF A PROBLEM: LANGUAGE EQUIVALENT MODELS: NFA, REGEXP PROBLEMS THAT A DFA CAN’T SOLVE ARE WE DONE?

5 Σ = {0, 1}, L = { 0 n 1 n | n ≥ 0 } Σ = {a, b, c, …, z}, L = { w | w = w R } Σ = { (, ) }, L = { balanced strings of parens } NONE OF THESE ARE REGULAR We can write a SCHEME or JAVA program for any of them!

6 PUSHDOWN AUTOMATA FINITE STATE CONTROL STACK (Last in, first out) INPUT

7 ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε stringpoppush 0011 STACK$ 0011011 $0 11 $ 0 1

8 ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε stringpoppush 001 STACK$$0$ 0 1 01001 PDA to recognize L = { 0 n 1 n | n ≥ 0 }

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

10 ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε q0q0 q1q1 q2q2 q3q3 Q = {q 0, q 1, q 2, q 3 }Γ =Σ =  : Q  Σ ε  Γ ε → P(Q  Γ ε ) {0,1}{$,0,1}  (q 1,1,0) = { (q 2,ε) }  (q 2,1,1) = 

11 EVEN-LENGTH PALINDROMES Σ = {a, b, c, …, z} ε,ε → $ ε,ε → εε,ε → ε , → ε, → ε ε,$ → ε q0q0 q1q1 q2q2 q3q3 ,ε → ,ε → 

12 Build a PDA to recognize L = { a i b j c k | i, j, k ≥ 0 and (i = j or i = k) } ε,ε → $ b,a → ε ε,$ → ε q0q0 q5q5 q1q1 q3q3 a,ε → a q2q2 q4q4 ε,ε → ε q6q6 ε,$ → ε b,ε → ε c,a → ε c,ε → ε

13 Build a PDA to recognize… L 1 = { x0y | |x| = |y| } L 2 = { w | w  0 n 1 n for any n} ε,ε → $ 0,ε → 0 1, ε → ε σ, ε → ε ε,$ → ε q0q0 q1q1 q4q4 q6q6 0,ε → 0 1,0 → ε q2q2 q3q3 σ, ε → ε q5q5 ε, 0 → ε 0,ε → ε

14 A → 0A1 A → B B → # CONTEXT-FREE GRAMMARS A variables terminals production rules start variable  0A1  00A11  00B11  00#11

15 → → LIKE → UMM → YOU KNOW → GAG ME WITH A SPOON → ε → AS IF → WHATEVER VALLEY GIRL GRAMMAR → LOSER

16 → | → LIKE | UMM → YOU KNOW | ε → GAG ME WITH A SPOON | AS IF | WHATEVER | LOSER VALLEY GIRL GRAMMAR

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

18 A → 0A1 A → B B → # CONTEXT-FREE GRAMMARS A variables terminals production rules start variable  0A1  00A11  00B11  00#11 uVw yields uvw if (V → v) ∈ R. A derives 00#11 in 4 steps.

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

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

21 GIVE A CFG FOR… L 3 = { strings of balanced parens } L 4 = { a i b j c k | i, j, k ≥ 0 and (i = j or j = k) }

22 VERY INTERESTING CFGs… http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html http://unununium.org/darcs/stackless-python/Grammar/Grammar

23 COMPILER MODULES LEXER PARSER SEMANTIC ANALYZER TRANSLATOR/INTERPRETER

24 PARSE TREES A  0A1  00A11  00B11  00#11 A B 01# A A 01

25 A Language is generated by a CFG  It is recognized by a PDA


Download ppt "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."

Similar presentations


Ads by Google