Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pushdown Automata (PDAs)

Similar presentations


Presentation on theme: "Pushdown Automata (PDAs)"— Presentation transcript:

1 Pushdown Automata (PDAs)
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

2 + Edges consume a character of input and operate on the stack!
Informally, a pushdown automaton (PDA) pairs a finite automaton (a set of states, alphabet, transition edges, a start state, final states) with an unbounded memory. Crucially, this memory is restricted to behave as a stack. This means information must be retrieved in first-in-last-out order (FILO). . . . ? ? ? ? + q0 q1 ? ? ? ? ? ? ? ? ? Edges consume a character of input and operate on the stack! ?

3 + T S T S T S T W Y Z a,T/S b,S/𝜖 a,U/STW b,S/STS a,Z/UYZ
Informally, a pushdown automaton (PDA) pairs a finite automaton (a set of states, alphabet, transition edges, a start state, final states) with an unbounded memory. Crucially, this memory is restricted to behave as a stack. This means information must be retrieved in first-in-last-out order (FILO). Edges are annotated with both an input token The stack is unbounded but frames are finite, so we use a finite stack alphabet. …and a stack operation. . . . a,T/S T b,S/𝜖 S T S + q0 q1 a,U/STW T S An edge a, T / S means “you may make this state transition if you read the input a while T is atop the stack. If so, replace T on the stack with S.” b,S/STS T W a,Z/UYZ Edges consume a character of input and operate on the stack! Y Z

4 Formally, each PDA is a 7-tuple:
A set of final states Formally, each PDA is a 7-tuple: (𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹) A finite set of states {q…} A starting stack symbol A finite stack alphabet A transition function A finite alphabet A starting state

5 (𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹) As we’ll see, only one of components Z0, F is
really needed for defining an acceptance condition. (𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹) A starting stack symbol A finite stack alphabet We need two new components compared with an NFA: a stack alphabet and starting stack symbol.

6 Formally, each PDA is a 7-tuple:
(𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹) 𝛿⊆(𝑄×Σ×Γ⇀𝒫(𝑄× Γ ∗ )) 𝐹⊆𝑄 𝑞 0 ∈𝑄 𝑍 0 ∈Γ

7 An example of popping from the stack: Recall delta’s signature:
“if the next terminal is a and X is atop the stack, the q0 goes to q1 and X is removed from the stack”. ( 𝑞 0 ,a,X,{( 𝑞 1 ,𝜖)})∈𝛿 OR [( 𝑞 0 ,a,X)↦{( 𝑞 1 ,𝜖)}]⊆𝛿 Recall delta’s signature: 𝛿⊆(𝑄×Σ×Γ⇀𝒫(𝑄× Γ ∗ ))

8 ( 𝑞 0 ,a,X,{( 𝑞 1 ,𝜖)})∈𝛿 ( 𝑞 0 ,a,X,{( 𝑞 1 ,X), ( 𝑞 2 ,YX)})∈𝛿
An example of popping from the stack: “if the next terminal is a and X is atop the stack, the q0 goes to q1 and X is removed from the stack”. ( 𝑞 0 ,a,X,{( 𝑞 1 ,𝜖)})∈𝛿 An example of pushing to the stack (and of checking the stack): “if the next terminal is a and X is atop the stack, the q0 goes to q1 and the stack is unchanged, or q0 goes to q2 and Y is pushed”. ( 𝑞 0 ,a,X,{( 𝑞 1 ,X), ( 𝑞 2 ,YX)})∈𝛿

9 Diagramming PDAs, notational conventions
Without consuming any input, if A is atop the stack, transition from q0 to q1, pushing stack symbol B. b,B/B b,A/A 𝜖,A/BA q0 q1 q2 a,B/𝜖 a,A/B ( 𝑞 1 ,BA)∈𝛿( 𝑞 0 ,𝜖,A)

10 Diagramming PDAs, notational conventions
On input b, self-loop on q1, if either A or B is on the stack. Leave the stack unchanged. ( 𝑞 1 ,A)∈𝛿( 𝑞 1 ,b,A) ( 𝑞 1 ,B)∈𝛿( 𝑞 1 ,b,B) b,B/B b,A/A 𝜖,A/BA q0 q1 q2 a,B/𝜖 a,A/B

11 b,B/B b,A/A 𝜖,A/BA a,B/𝜖 a,A/B ( 𝑞 2 ,B)∈𝛿( 𝑞 1 ,a,A)
Diagramming PDAs, notational conventions b,B/B b,A/A 𝜖,A/BA q0 q1 q2 a,B/𝜖 a,A/B On input a, transition from q1 to q2, replacing A with B or popping B. ( 𝑞 2 ,B)∈𝛿( 𝑞 1 ,a,A) ( 𝑞 2 ,𝜖)∈𝛿( 𝑞 1 ,a,B)

12 Let’s try an example we’ve seen previously: matching as followed by bs.
𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ}

13 Z0 is our starting stack symbol.
Let’s try an example we’ve seen previously: matching as followed by bs. 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} Stack symbol A should be pushed for each input token a, and popped for each input token b. Z0 is our starting stack symbol. ⟨{ 𝑞 0 , 𝑞 1 , 𝑞 2 },{a,b},{A, Z 0 },𝛿, 𝑞 0 , Z 0 ,{ 𝑞 2 }⟩

14 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} b,A/𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖, Z 0 /𝜖 a,A/AA
Let’s try an example we’ve seen previously: matching as followed by bs. 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} On input b, transition from q1 to q1, popping stack symbol A. On input a, transition from q0 to q0, pushing stack symbol A whenever A or Z0 was already atop stack. b,A/𝜖 𝜖, Z 0 / Z 0 𝜖,A/A q0 q1 q2 𝜖, Z 0 /𝜖 a,A/AA a, Z 0 / AZ 0 ⟨{ 𝑞 0 , 𝑞 1 , 𝑞 2 },{a,b},{A, Z 0 },𝛿, 𝑞 0 , Z 0 ,{ 𝑞 2 }⟩

15 𝑄× Σ ∗ × Γ ∗ (𝑞,𝑎𝑤,𝑋𝛽)⊢(𝑝,𝑤,𝛼𝛽) Evaluating PDAs (𝑝,𝛼)∈𝛿(𝑞,𝑎,𝑋)
Given a PDA called P, , we can define a step- wise evaluation relation ( ) and its transitive/reflexitive closure ( ). ⟨𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹⟩ ⊢ ∗ 𝑥 ⊢ ∗ 𝑥 𝑥⊢𝑦 ⊢ ∗ 𝑧⟹𝑥 ⊢ ∗ 𝑧 Evaluation can be described in terms of triples (inst. descriptions) in 𝑄× Σ ∗ × Γ ∗ Iff P contains an edge , then: (𝑝,𝛼)∈𝛿(𝑞,𝑎,𝑋) def (𝑞,𝑎𝑤,𝑋𝛽)⊢(𝑝,𝑤,𝛼𝛽)

16 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} ( 𝑞 0 ,aaabbb, Z 0 )⊢( 𝑞 0 ,aabbb, AZ 0 )
𝜖, Z 0 / Z 0 𝜖,A/A q0 q1 q2 𝜖, Z 0 /𝜖 a,A/AA ( 𝑞 0 ,aaabbb, Z 0 )⊢( 𝑞 0 ,aabbb, AZ 0 ) a, Z 0 / AZ 0 ⊢( 𝑞 0 ,abbb, AAZ 0 ) ⊢( 𝑞 0 ,bbb, AAAZ 0 ) Remember, PDAs are nondeterministic so there are other paths not shown. (E.g., some take the epsilon edge early and get stuck at q1.) ⊢( 𝑞 1 ,bbb, AAAZ 0 ) ⊢( 𝑞 1 ,bb, AAZ 0 ) ⊢( 𝑞 1 ,b, AZ 0 ) ⊢( 𝑞 1 ,𝜖, Z 0 )⊢( 𝑞 2 ,𝜖,𝜖)

17 Evaluating PDAs: two criteria for acceptance
Acceptance by final state: A PDA accepts if and only if, there exists an evaluation reaching a qF. 𝑃=⟨𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹⟩ 𝐿(𝑃)={𝑤|( 𝑞 0 ,𝑤, 𝑍 0 ) ⊢ ∗ ( 𝑞 𝐹 ,𝜖,𝛼)∧ 𝑞 𝐹 ∈𝐹}

18 Evaluating PDAs: two criteria for acceptance
Acceptance by final state: A PDA accepts if and only if, there exists an evaluation reaching a qF. 𝑃=⟨𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹⟩ 𝐿(𝑃)={𝑤|( 𝑞 0 ,𝑤, 𝑍 0 ) ⊢ ∗ ( 𝑞 𝐹 ,𝜖,𝛼)∧ 𝑞 𝐹 ∈𝐹} Acceptance by empty-stack: A PDA accepts only if there exists an evaluation reaching an empty stack. 𝑃=⟨𝑄,Σ,Γ,𝛿, 𝑞 0 , 𝑍 0 ,𝐹⟩ 𝑁(𝑃)={𝑤|( 𝑞 0 ,𝑤, 𝑍 0 ) ⊢ ∗ (𝑞,𝜖,𝜖)}

19 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} b,A/𝜖 𝜖, Z 0 / Z 0 𝜖, Z 0 /𝜖 𝜖,A/A a, Z 0 / AZ 0
Recall our PDA for recognizing strings in anbn-language via an accept state. 𝐿={ a 𝑛 b 𝑛 |𝑛∈ℕ} b,A/𝜖 𝜖, Z 0 / Z 0 𝜖, Z 0 /𝜖 𝜖,A/A q0 q1 q2 a, Z 0 / AZ 0 b,A/𝜖 a,A/AA 𝜖,A/𝜖 q0 q1 It may be simplified if our PDA will accept on an empty stack. a,A/AA

20 Let’s try an example. Diagram and formalize a PDA for the language of even-length palindromes over alphabet {a, b}. 𝐿={𝑤 𝑤 ℛ |𝑤∈{a,b } ∗ }

21 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,B/B 𝜖, Z 0 /𝜖 a, Z 0 / AZ 0 a,A/𝜖 b, Z 0 / BZ 0
Let’s try an example. Diagram and formalize a PDA for the language of even-length palindromes over alphabet {a, b}. 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,B/B 𝜖, Z 0 /𝜖 q0 q1 q2 a, Z 0 / AZ 0 a,A/𝜖 b, Z 0 / BZ 0 b,B/𝜖 a,A/AA b,A/BA ⟨{ 𝑞 0 , 𝑞 1 , 𝑞 2 },{a,b}, a,B/AB {A,B, Z 0 },𝛿, 𝑞 0 , Z 0 ,{ 𝑞 2 }⟩ b,B/BB

22 𝐿={𝑤𝑠 𝑤 ℛ |𝑤∈{a,b } ∗ ∧𝑠∈{a,b,𝜖}}
Let’s try an example. Diagram and formalize a PDA for the language of all palindromes over alphabet {a, b}. 𝐿={𝑤𝑠 𝑤 ℛ |𝑤∈{a,b } ∗ ∧𝑠∈{a,b,𝜖}}

23 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖, Z 0 /𝜖 𝜖,B/B a, Z 0 / Z 0 a,A/A a,B/B
Let’s try an example. Diagram and formalize a PDA for the language of all palindromes over alphabet {a, b}. 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖, Z 0 /𝜖 𝜖,B/B q0 q1 q2 a, Z 0 / Z 0 a,A/A a,B/B a, Z 0 / AZ 0 a,A/𝜖 b, Z 0 / Z 0 b, Z 0 / BZ 0 b,B/𝜖 b,A/A a,A/AA b,B/B b,A/BA a,B/AB ⟨{ 𝑞 0 , 𝑞 1 , 𝑞 2 },{a,b}, b,B/BB {A,B, Z 0 },𝛿, 𝑞 0 , Z 0 ,{ 𝑞 2 }⟩

24 Models of context-free languages
“Converts to” CFG PDA “Converts to”

25 accepts when it reaches accepts when it reaches
Models of context-free languages “Converts to” “Converts to” CFG PDA PDA “Converts to” “Converts to” accepts when it reaches an empty stack accepts when it reaches a final state

26 Given an final-state-accepting PDA, P
Given an final-state-accepting PDA, P. How can we derive an empty-stack-accepting version, P’?

27 Given an final-state-accepting PDA, P
Given an final-state-accepting PDA, P. How can we derive an empty-stack-accepting version, P’? 𝜖,_/𝜖 𝜖, Z 0 / Z 0 B 𝜖,_/𝜖 𝜖,_/𝜖 We push a fresh symbol B under Z0 that P cannot pop. We transition from final states to states that can pop any stack symbol (symbol _ is a wildcard) without consuming input!

28 Given an empty-stack-accepting PDA, P
Given an empty-stack-accepting PDA, P. How can we derive an final-state-accepting version, P’?

29 Given an empty-stack-accepting PDA, P
Given an empty-stack-accepting PDA, P. How can we derive an final-state-accepting version, P’? 𝜖, Z 0 / Z 0 B 𝜖,B/𝜖 𝜖,B/𝜖 𝜖,B/𝜖 We push a fresh symbol B under Z0. When B is atop the stack, the PDA P can accept (when input is empty). Thus, we add an edge that can pop B from all states to the final state.

30 Let’s try an example. Diagram a PDA using an accept state.
𝐿={ a 𝑛 b 𝑚 |𝑚<𝑛}

31 Let’s try an example. Diagram a PDA using an accept state.
𝐿={ a 𝑛 b 𝑚 |𝑚<𝑛} b,A/𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,A/𝜖 q0 q1 q2 a, Z 0 / AZ 0 a,A/AA

32 b,A/𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,A/𝜖 a, Z 0 / AZ 0 a,A/AA
Let’s try an example. Diagram an equivalent PDA that accepts by emptying its stack instead (using the standard construction). b,A/𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,A/𝜖 q0 q1 q2 a, Z 0 / AZ 0 a,A/AA

33 𝜖,A/𝜖 𝜖,B/𝜖 b,A/𝜖 𝜖, Z 0 /𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,A/𝜖 𝜖, Z 0 / Z 0 B
Let’s try an example. Diagram an equivalent PDA that accepts by emptying its stack instead (using the standard construction). 𝜖,A/𝜖 𝜖,B/𝜖 b,A/𝜖 𝜖, Z 0 /𝜖 𝜖, Z 0 / Z 0 𝜖,A/A 𝜖,A/𝜖 q0’ q0 q1 q2 qF 𝜖, Z 0 / Z 0 B 𝜖,A/𝜖 a, Z 0 / AZ 0 𝜖, Z 0 /𝜖 a,A/AA

34 Let’s try an example. Diagram and formalize a PDA for the language of all matching braces, which accepts via an empty stack: 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖

35 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖 {, Z 0 / CZ 0 [, Z 0 / SZ 0 (, Z 0 / PZ 0 {,P/CP
Let’s try an example. Diagram and formalize a PDA for the language of all matching braces, which accepts via an empty stack: 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖 q0 {, Z 0 / CZ 0 [, Z 0 / SZ 0 (, Z 0 / PZ 0 {,P/CP [,P/SP (,P/PP {,C/CC [,C/SC (,C/PC 𝜖, Z 0 /𝜖 {,S/CS (,S/PS [,S/SS ),P/𝜖 },C/𝜖 ],S/𝜖 ⟨{ 𝑞 0 },{(,),{,},[,]}, {P,C,S, Z 0 },𝛿, 𝑞 0 , Z 0 ,Ø⟩

36 Given an arbitrary CFG (Σ,N,P,S), how can we produce a PDA to accept the same language (using empty-stack acceptance)? q0 ? We can do it with just a single state using the stack to represent the current sentential form as we generate a leftmost derivation nondeterministically.

37 Given an arbitrary CFG (Σ,N,P,S), how can we produce a PDA to accept the same language (using empty-stack acceptance)? q0 ? We can do it with just a single state using the stack to represent the current sentential form as we generate a leftmost derivation nondeterministically. ⟨{ 𝑞 0 },Σ,Σ∪𝑁,𝛿, 𝑞 0 ,𝑆,Ø⟩ We allow both terminals in Σ and nonterminals in N on the stack. The stack starts out as start-symbol S.

38 For each terminal x, we add a self-edge:
Given an arbitrary CFG (Σ,N,P,S), how can we produce a PDA to accept the same language (using empty-stack acceptance)? For each production: 𝐴→ 𝛼 0 … 𝛼 𝑘 We add a self-edge: q0 𝜖,𝐴/ 𝛼 0 … 𝛼 𝑘 For each terminal x, we add a self-edge: x,x/𝜖 We can do it with just a single state using the stack to represent the current sentence as we generate a leftmost derivation nondeterministically. ⟨{ 𝑞 0 },Σ,Σ∪𝑁,𝛿, 𝑞 0 ,𝑆,Ø⟩ We allow both terminals in Σ and nonterminals in N on the stack. The stack starts out as start-symbol S.

39 Let’s try an example. Diagram and formalize a PDA for the language of all matching braces again, using this CFG->PDA construction. 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖

40 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖 𝜖,S/(S) 𝜖,S/[S] 𝜖,S/{S} 𝜖,S/𝜖 (,(/𝜖 ),)/𝜖 {,{/𝜖 },}/𝜖
Let’s try an example. Diagram and formalize a PDA for the language of all matching braces again, using this CFG->PDA construction. 𝑆→(𝑆)|{𝑆}|[𝑆]|𝜖 q0 𝜖,S/(S) 𝜖,S/[S] 𝜖,S/{S} 𝜖,S/𝜖 (,(/𝜖 ),)/𝜖 {,{/𝜖 },}/𝜖 [,[/𝜖 ],]/𝜖 ⟨{ 𝑞 0 },{(,),{,},[,]}, {(,),{,},[,],S},𝛿, 𝑞 0 ,S,Ø⟩

41 Let’s try an example. Diagram and formalize a PDA for the CFG below using this standard CFG->PDA construction. 𝐸→𝐸+𝐸|𝐸−𝐸|𝐸∗𝐸|(𝐸)|𝑛

42 𝐸→𝐸+𝐸|𝐸−𝐸|𝐸∗𝐸|(𝐸)|𝑛 𝜖,E/E ∗ E 𝜖,E/E + E 𝜖,E/E − E 𝜖,E/(S) 𝜖,E/𝑛 +,+/𝜖
Let’s try an example. Diagram and formalize a PDA for the CFG below using this standard CFG->PDA construction. 𝐸→𝐸+𝐸|𝐸−𝐸|𝐸∗𝐸|(𝐸)|𝑛 𝜖,E/E ∗ E 𝜖,E/E + E q0 𝜖,E/E − E 𝜖,E/(S) 𝜖,E/𝑛 +,+/𝜖 −,−/𝜖 ∗,∗/𝜖 (,(/𝜖 ),)/𝜖 ⟨{ 𝑞 0 },{(,),+,−,∗,n}, 𝑛,𝑛/𝜖 {(,),+,−,∗,n,E},𝛿, 𝑞 0 ,E,Ø⟩

43 𝐸→𝐸+𝐸|𝐸−𝐸|𝐸∗𝐸|(𝐸)|𝑛 𝜖,E/E ∗ E 𝜖,E/E + E 𝜖,E/E − E 𝜖,E/(S) 𝜖,E/𝑛 +,+/𝜖
Let’s try an example. Diagram and formalize a PDA for the CFG below using this standard CFG->PDA construction. 𝐸→𝐸+𝐸|𝐸−𝐸|𝐸∗𝐸|(𝐸)|𝑛 𝜖,E/E ∗ E 𝜖,E/E + E q0 𝜖,E/E − E 𝜖,E/(S) 𝜖,E/𝑛 +,+/𝜖 −,−/𝜖 Five nonterminal-handling edges ∗,∗/𝜖 (,(/𝜖 ),)/𝜖 ⟨{ 𝑞 0 },{(,),+,−,∗,n}, 𝑛,𝑛/𝜖 {(,),+,−,∗,n,E},𝛿, 𝑞 0 ,E,Ø⟩ Six terminal-handling edges

44 𝑁={[𝑞𝐴𝑟]|𝑞,𝑟∈𝑄∧𝐴∈Γ}∪{S}
Given an arbitrary PDA (Q,Σ,Γ,δ,q0,Z0,F), using empty-stack acceptance, how can we produce an equivalent CFG (Σ,N,P,S)? Σ=Σ 𝑁={[𝑞𝐴𝑟]|𝑞,𝑟∈𝑄∧𝐴∈Γ}∪{S} Each [q A r] is a single (composite) nonterminal symbol encoding substrings recognized on a path from state q to r, via zero or more edges, popping exactly symbol A as the net effect to the stack.

45 𝑁={[𝑞𝐴𝑟]|𝑞,𝑟∈𝑄∧𝐴∈Γ}∪{S}
Given an arbitrary PDA (Q,Σ,Γ,δ,q0,Z0,F), using empty-stack acceptance, how can we produce an equivalent CFG (Σ,N,P,S)? Σ=Σ 𝑁={[𝑞𝐴𝑟]|𝑞,𝑟∈𝑄∧𝐴∈Γ}∪{S} 𝑃={S→[ 𝑞 0 Z 0 𝑟]|𝑟∈𝑄} ∪{[𝑞𝑆 𝑟 𝑗 ]→𝑎[ 𝑟 0 𝑆 1 𝑟 1 ]…[ 𝑟 𝑗−1 𝑆 𝑗 𝑟 𝑗 ] |( 𝑟 0 , 𝑆 1 … 𝑆 𝑗 )∈𝛿(𝑞,𝑎,𝑆)∧ 𝑟 0 … 𝑟 𝑗 ∈𝑄} 𝑆=S

46 b,A/𝜖 𝜖,A/𝜖 a,A/AA ⟨{ 𝑞 0 , 𝑞 1 },{a,b},{A},𝛿, 𝑞 0 ,A,Ø⟩
Let’s try an example. Find a CFG for the PDA below using this standard PDA->CFG construction. b,A/𝜖 𝜖,A/𝜖 q0 q1 a,A/AA ⟨{ 𝑞 0 , 𝑞 1 },{a,b},{A},𝛿, 𝑞 0 ,A,Ø⟩

47 b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖
Let’s try an example. Find a CFG for the PDA below using this standard PDA->CFG construction. b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖 q0 q1 [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 1 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 1 ] a,A/AA [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→𝜖 [ 𝑞 1 𝐴 𝑞 1 ]→b

48 b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖
Let’s try an example. Which productions can be used to generate strings in the language? How can we derive aaabbb? b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖 q0 q1 [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 1 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 1 ] a,A/AA [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→𝜖 [ 𝑞 1 𝐴 𝑞 1 ]→b

49 b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖
Let’s try an example. Which productions can be used to generate strings in the language? How can we derive aaabbb? b,A/𝜖 𝑆→[ 𝑞 0 𝐴 𝑞 0 ]|[ 𝑞 0 𝐴 𝑞 1 ] 𝜖,A/𝜖 q0 q1 [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 0 ][ 𝑞 0 𝐴 𝑞 1 ] [ 𝑞 0 𝐴 𝑞 1 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 1 ] a,A/AA [ 𝑞 0 𝐴 𝑞 0 ]→a[ 𝑞 0 𝐴 𝑞 1 ][ 𝑞 1 𝐴 𝑞 0 ] [ 𝑞 0 𝐴 𝑞 1 ]→𝜖 [ 𝑞 1 𝐴 𝑞 1 ]→b


Download ppt "Pushdown Automata (PDAs)"

Similar presentations


Ads by Google