Chapter 1 Formal and View Lecture on the 28th April 2009 Formal of PA Faculty of Information Technology Brno University of Technology 1.1
Aim of the Lecture 1 Define pushdown automaton in a formal way 2 Top-down and bottom-up analysis of context-free languages 3 One-turn pushdown automata 4 Atomic pushdown automata Formal of PA 1.2
Contents 1 2 Formal of PA 3 with PA 4 5 6 Formal of PA 1.3
What is a pushdown? Merriam-Webster A store of data (as in a computer) from which the most recently stored item must be the first retrieved called also pushdown list or pushdown stack. We stick to this definition! Formal of PA 1.4
Why do we need them? Finite automata handle regular languages only Syntax of programming languages is context-free Program text is of arbitrary length Repeated nested bracket-like structures (e.g. arithmetic expressions) Pushdown automata offer infinite memory (even if LIFO structure) Formal of PA 1.5
Informal View tape a a a b b b... pushdown Z b b Formal of PA 1.6
of Pushdown Automaton Formal of Pushdown Automaton A pushdown automaton is a seven-tuple M = (Q, Σ, Γ, δ, q 0, Z 0, F ), where Q finite set of states Σ finite input alphabet Γ finite alphabet of pushdown symbols δ mapping Q (Σ {ε}) Γ 2 Q Γ transition function q 0 Q starting/initial state Z 0 Γ start symbol on the pushdown F Q set of final states Formal of PA 1.7
Configuration of Configuration A configuration of PA M is a triple (q, w, α) Q Σ Γ, where q current state of the finite control w unused input; the first symbol of w is under the reading head; if w = ε, then it is assumed that all the input has been read α contents of the pushdown; the leftmost symbol is the topmost symbol; if α = ε, then the pushdown is assumed to be empty Formal of PA 1.8
Move / Transition Move/Transition A move/transition by M is represented by the binary relation M (or if M is understood) on configurations. We write (q, aw, Z α) (q, w, γα) if (q, γ) δ(q, a, Z ) for any q Q, a Σ {ε}, w Σ, Z Γ, and α Γ. We can define relations i, i 0,, and + in the traditional way. and + stand for reflexive-transitive and transitive closures of, respectively. Formal of PA 1.9
Final Configuration Initial configuration: (q 0, w, Z 0 ), w Σ Note: from the definition, it follows that there is no move possible if the pushdown is empty. Final configuration, Ξ, Ξ {1, 2, 3}: 1 Empty pushdown: (q, ε, ε), q Q 2 Final state: (q F, ε, α), q F F, α Γ 3 Final state and empty pushdown: (q F, ε, ε), q F F Formal of PA 1.10
Accepted Language A word w, w Σ, is accepted by M if it makes transitions (q 0, w, Z 0 ) Ξ, where Ξ {1, 2, 3} is the selected final configuration. Language accepted by M L(M) = {w (q 0, w, Z 0 ) Ξ}, where Ξ {1, 2, 3} is some (but fixed) of the final configurations. Formal of PA 1.11
Example 1 (a n b n, n 0) M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0 } Σ = {a, b} Γ = {a, Z 0 } F = {q 0 } δ: δ(q 0, a, Z 0 ) {(q 0, Z 0 a)} δ(q 0, b, a) {(q 0, ε)} δ(q 0, ε, Z 0 ) {(q 0, ε)} Formal of PA 1.12
Example 1 (a n b n, n 0) Acceptance (q 0, aaabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, Z 0 a) (q 0, aabbb, Z 0 a) // δ(q 0, a, Z 0 ) (q 0, Z 0 a) (q 0, abbb, Z 0 aa) // δ(q 0, a, Z 0 ) (q 0, Z 0 a) (q 0, bbb, Z 0 aaa) // δ(q 0, ε, Z 0 ) (q 0, ε) (q 0, bbb, aaa) // δ(q 0, b, a) (q 0, ε) (q 0, bb, aa) // δ(q 0, b, a) (q 0, ε) (q 0, b, a) // δ(q 0, b, a) (q 0, ε) (q 0, ε, ε) Formal of PA 1.13
Example 1 (a n b n, n 0) Failure (q 0, aabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, Z 0 a) (q 0, abbb, Z 0 a) // δ(q 0, a, Z 0 ) (q 0, Z 0 a) (q 0, bbb, Z 0 aa) // δ(q 0, ε, Z 0 ) (q 0, ε) (q 0, bbb, aa) // δ(q 0, b, a) (q 0, ε) (q 0, bb, a) // δ(q 0, b, a) (q 0, ε) (q 0, b, ε) // no rule to be applied Formal of PA 1.14
Example 2 (ww R, w {a, b} + ) M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0, q 1, q F } Σ = {a, b} Γ = {a, b, Z 0 } F = {q F } δ: δ(q 0, a, Z 0 ) {(q 0, az 0 )} δ(q 0, b, Z 0 ) {(q 0, bz 0 )} δ(q 0, a, a) {(q 0, aa), (q 1, ε)} δ(q 0, a, b) {(q 0, ab)} δ(q 0, b, a) {(q 0, ba)} δ(q 0, b, b) {(q 0, bb), (q 1, ε)} δ(q 1, b, b) {(q 1, ε)} δ(q 1, a, a) {(q 1, ε)} δ(q 1, ε, Z 0 ) {(q F, ε)} Formal of PA 1.15
Example 2 (ww R, w {a, b} + ) Acceptance (q 0, abbaabba, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, az 0 ) (q 0, bbaabba, az 0 ) // δ(q 0, b, a) (q 0, ba) (q 0, baabba, baz 0 ) // δ(q 0, b, b) (q 0, bb) (q 0, aabba, bbaz 0 ) // δ(q 0, a, b) (q 0, ab) (q 0, abba, abbaz 0 ) // δ(q 0, a, a) (q 1, ε) (q 1, bba, bbaz 0 ) // δ(q 1, b, b) (q 1, ε) (q 1, ba, baz 0 ) // δ(q 1, b, b) (q 1, ε) (q 1, a, az 0 ) // δ(q 1, a, a) (q 1, ε) (q 1, ε, Z 0 ) // δ(q 1, ε, Z 0 ) (q F, ε) (q F, ε, ε) Formal of PA 1.16
Example 2 (ww R, w {a, b} + ) Failure (q 0, abbaaaba, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, az 0 ) (q 0, bbaaaba, az 0 ) // δ(q 0, b, a) (q 0, ba) (q 0, baaaba, baz 0 ) // δ(q 0, b, b) (q 0, bb) (q 0, aaaba, bbaz 0 ) // δ(q 0, a, b) (q 0, ab) (q 0, aaba, abbaz 0 ) // δ(q 0, a, a) (q 1, ε) (q 1, aba, bbaz 0 ) // no rule to be applied Formal of PA 1.17
General View How to construct a PA? Directly From a context-free grammar Virtual reconstruction of a particular derivation tree for the given grammar and sentence of the language. Note: to make difference between end of the input tape and ignoring the input symbol we will use $ to represent end of the input tape (empty input) and ε to denote that we do not read the symbol under the reading head and the reading head is not moved. Formal of PA 1.18
Virtual reconstruction of the derivation tree starts from the starting non-terminal of the respective context-free grammar. Construction Let G = (N, T, P, S) be a context-free grammar then construct M = (Q, Σ, Γ, δ, q 0, Z 0, F ) this way: Q = {q 0, q, q F } Σ = T {$} Γ = {Z 0 } T N, F = {q F } {Z 0, $} (T N) = For all A α P, A N, α (N T ) add (q, ε, A) {(q, α)} to δ For all a T add (q, a, a) {(q, ε)} to δ Add (q 0, ε, Z 0 ) {(q, SZ 0 )} to δ Add (q, $, Z 0 ) {(q F, ε)} to δ Formal of PA 1.19
Example Construction CF Grammar Let G = (N, T, P, S), where: N = {S, E}, T = { (, ), +, i }, P = { S SS E, E E + E i (E) }. PA Construction Let M = (Q, Σ, Γ, δ, q 0, Z 0, F ), where: Q = {q 0, q, q F }, F = {q F } Σ = T {$} = { (, ), +, i, $ } Γ = {Z 0 } T N = {S, E, (, ), +, i, Z 0 } δ(q, $, Z 0 ) {(q F, ε)} δ(q 0, ε, Z 0 ) {(q, SZ 0 )} δ(q, ε, S) {(q, SS), (q, E)} δ(q, ε, E) {(q, E + E), (q, i), (q, (E))} δ(q, (, () {(q, ε)} δ(q, ), )) {(q, ε)} δ(q, +, +) {(q, ε)} δ(q, i, i) {(q, ε)} Formal of PA 1.20
Example Analysis (q 0, i + i(i), Z 0 ) // δ(q 0, ε, Z 0 ) (q, SZ 0 ) (q, i + i(i), SZ 0 ) // δ(q, ε, S) (q, SS) (q, i + i(i), SSZ 0 ) // δ(q, ε, S) (q, E) (q, i + i(i), ESZ 0 ) // δ(q, ε, E) (q, E + E) (q, i + i(i), E + ESZ 0 ) // δ(q, ε, E) (q, i) (q, i + i(i), i + ESZ 0 ) // δ(q, i, i) (q, ε) (q, +i(i), +ESZ 0 ) // δ(q, +, +) (q, ε) (q, i(i), ESZ 0 ) // δ(q, ε, E) (q, i) (q, i(i), isz 0 ) // δ(q, i, i) (q, ε) (q, (i), SZ 0 ) // δ(q, ε, S) (q, E) (q, (i), EZ 0 ) // δ(q, ε, E) (q, (E)) (q, (i), (E)Z 0 ) // δ(q, (, () (q, ε) (q, i), E)Z 0 ) // δ(q, ε, E) (q, i) (q, i), i)z 0 ) // δ(q, i, i) (q, ε) (q, ), )Z 0 ) // δ(q, ), )) (q, ε) (q, $, Z 0 ) // δ(q, $, Z 0 ) (q F, ε) (q F, $, ε) Formal of PA 1.21
Example Derivation Reconstruction Grammar rules used in the following order: 1 S SS 2 S E 3 E E + E 4 E i 5 E i 6 S E 7 E (E) 8 E i It was left derivation, thus we get: S SS ES E + ES i + ES i + is i + ie i + i(e) i + i(i) Formal of PA 1.22
s Reconstruction of the derivation tree starts from the symbols of the input sentence up to the starting non-terminal of the respective grammar. of Extended PA An extended pushdown automaton is a seven-tuple M = (Q, Σ, Γ, δ, q 0, Z 0, F ), where Q, Σ, Γ, q 0, Z 0, and F have the same meaning as for pushdown automaton. δ is defined as mapping Q (Σ {ε}) Γ 2 Q Γ Formal of PA 1.23
Construction Let G = (N, T, P, S) be a context-free grammar then construct M = (Q, Σ, Γ, δ, q 0, Z 0, F ) this way: Q = {q 0, q 1, q F } Σ = T {$} Γ = {Z 0 } T N F = {q F } For all A α P, A N, α (N T ) add (q 0, ε, α R ) {(q 0, A)} to δ For all a T and all z Γ add (q 0, a, z) {(q 0, az)} to δ Add (q 0, ε, S) {(q 1, ε)} to δ Add (q 1, $, Z 0 ) {(q F, ε)} to δ Formal of PA 1.24
Example Construction CF Grammar Let G = (N, T, P, S), where: N = {S, E}, T = { (, ), +, i }, P = { S SS E, E E + E i (E) }. PA Construction Let M = (Q, Σ, Γ, δ, q 0, Z 0, F ), where: Q = {q 0, q 1, q F }, F = {q F } Σ = T {$} = { (, ), +, i, $ } Γ = {Z 0 } T N = {S, E, (, ), +, i, Z 0 } δ(q 0, ε, S) {(q 1, ε)} δ(q 1, $, Z 0 ) {(q F, ε)} δ(q 0, ε, SS) {(q 0, S)} δ(q 0, ε, E) {(q 0, S)} δ(q 0, ε, E + E) {(q 0, E)} δ(q 0, ε, i) {(q 0, E)} δ(q 0, ε, )E() {(q 0, E)}... Formal of PA 1.25
Example Construction PA Construction... δ(q 0, (, Z 0 ) {(q 0, (Z 0 )} δ(q 0, ), Z 0 ) {(q 0, )Z 0 )} δ(q 0, +, Z 0 ) {(q 0, +Z 0 )} δ(q 0, i, Z 0 ) {(q 0, iz 0 )} δ(q 0, (, S) {(q 0, (S)} δ(q 0, ), S) {(q 0, )S)} δ(q 0, +, S) {(q 0, +S)} δ(q 0, i, S) {(q 0, is)} δ(q 0, (, E) {(q 0, (E)} δ(q 0, ), E) {(q 0, )E)} δ(q 0, +, E) {(q 0, +E)} δ(q 0, i, E) {(q 0, ie)}...... for all z Γ Formal of PA 1.26
Example Analysis (q 0, i + i(i), Z 0 ) // δ(q 0, i, Z 0 ) (q 0, iz 0 ) (q 0, +i(i), iz 0 ) // δ(q 0, ε, i) (q 0, E) (q 0, +i(i), EZ 0 ) // δ(q 0, +, E) (q 0, +E) (q 0, i(i), +EZ 0 ) // δ(q 0, i, +) (q 0, i+) (q 0, (i), i + EZ 0 ) // δ(q 0, ε, i) (q 0, E) (q 0, (i), E + EZ 0 ) // δ(q 0, ε, E + E) (q 0, E) (q 0, (i), EZ 0 ) // δ(q 0, ε, E) (q 0, S) (q 0, (i), SZ 0 ) // δ(q 0, (, S) (q 0, (S) (q 0, i), (SZ 0 ) // δ(q 0, i, () (q 0, i() (q 0, ), i(sz 0 ) // δ(q 0, ε, i) (q 0, E) (q 0, ), E(SZ 0 ) // δ(q 0, ), E) (q 0, )E) (q 0, $, )E(SZ 0 ) // δ(q 0, ε, )E() (q 0, E) (q 0, $, ESZ 0 ) // δ(q 0, ε, E) (q 0, S) (q 0, $, SSZ 0 ) // δ(q 0, ε, SS) (q 0, S) (q 0, $, SZ 0 ) // δ(q 0, ε, S) (q 1, ε) (q 1, $, Z 0 ) // δ(q 1, $, Z 0 ) (q F, ε) (q F, $, ε) Formal of PA 1.27
Example Derivation Reconstruction Grammar rules used in the following order: 1 E i 2 E i 3 E E + E 4 S E 5 E i 6 E (E) 7 S E 8 S SS It was right derivation in reverse order, thus we get: S SS SE S(E) S(i) E(i) E + E(i) E + i(i) i + i(i) Formal of PA 1.28
Importance of Determinism Non-deterministic analysis of context-free languages Possible With backtracking Inefficient Deterministic analysis of context-free languages Possible for certain, but sufficiently large subset of context-free languages Without backtracking Efficient Formal of PA 1.29
Non-Deterministic Pushdown Presented definition matches non-deterministic pushdown automata Where is the non-determinism? δ(q, a, z) {(q, α), (q, β),... } multiple choice δ(q, ε, z) {... } ε matches always All examples presented so far demonstrated non-deterministic pushdown automata Formal of PA 1.30
Deterministic Pushdown Formal of Deterministic Pushdown Automaton A deterministic pushdown automaton is a seven-tuple M = (Q, Σ, Γ, δ, q 0, Z 0, F ), where Q finite set of states Σ finite input alphabet Γ finite alphabet of pushdown symbols δ mapping Q (Σ {ε}) Γ Q Γ transition function q 0 Q starting/initial state Z 0 Γ start symbol on the pushdown F Q set of final states Configuration, move, final configuration, and accepted language defined the same way Formal of PA 1.31
Deterministic Pushdown Is the definition sufficient to ensure determinism? No! Eliminated multiple choices, but the other option must be eliminated by proper construction. Compare: δ(q, a, Z ) (p, u) versus δ(q, ε, Z ) = (p, u ) Formal of PA 1.32
Deterministic Pushdown Is it possible to find deterministic automaton for every non-deterministic one? Unfortuntely, no! Principal reasons Ambiguity of grammar used for automata construction Let us try... Formal of PA 1.33
Example 1 (a n b n, n 0) Possible solution features: Separation of empty and non-empty input cases State for reading of as with duplication to the pushdown State for reading of bs when removing symbols from pushdown to check that number of both is equal Separete final state final configuration 3 (empty pushdown & final state) Formal of PA 1.34
Example 1 (a n b n, n 0) M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0, q 1, q 2, q F } Σ = {a, b, $} Γ = {Z 0 } F = {q F } δ: δ(q 0, a, Z 0 ) (q 1, Z 0 Z 0 ) δ(q 1, a, Z 0 ) (q 1, Z 0 Z 0 ) δ(q 1, b, Z 0 ) (q 2, ε) δ(q 2, b, Z 0 ) (q 2, ε) δ(q 2, $, Z 0 ) (q F, ε) δ(q 0, $, Z 0 ) (q F, ε) Formal of PA 1.35
Example 1 (a n b n, n 0) Acceptance (q 0, aaabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 1, Z 0 Z 0 ) (q 1, aabbb, Z 0 Z 0 ) // δ(q 1, a, Z 0 ) (q 1, Z 0 Z 0 ) (q 1, abbb, Z 0 Z 0 Z 0 ) // δ(q 1, a, Z 0 ) (q 1, Z 0 Z 0 ) (q 1, bbb, Z 0 Z 0 Z 0 Z 0 ) // δ(q 1, b, Z 0 ) (q 2, ε) (q 2, bb, Z 0 Z 0 Z 0 ) // δ(q 2, b, Z 0 ) (q 2, ε) (q 2, b, Z 0 Z 0 ) // δ(q 2, b, Z 0 ) (q 2, ε) (q 2, $, Z 0 ) // δ(q 2, $, Z 0 ) (q F, ε) (q F, $, ε) Formal of PA 1.36
Example 1 (a n b n, n 0) Failure (q 0, aabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 1, Z 0 Z 0 ) (q 1, abbb, Z 0 Z 0 ) // δ(q 1, a, Z 0 ) (q 1, Z 0 Z 0 ) (q 1, bbb, Z 0 Z 0 Z 0 ) // δ(q 1, b, Z 0 ) (q 2, ε) (q 2, bb, Z 0 Z 0 ) // δ(q 2, b, Z 0 ) (q 2, ε) (q 2, b, Z 0 ) // δ(q 2, b, Z 0 ) (q 2, ε) (q 2, $, ε) // no rule to be applied Formal of PA 1.37
Example 1 (a n b n, n 0) Discussion Creation possible No algorithm to transform the non-deterministic PA Other solutions may work as well What modification can be done? Can we reduce number of states? A non-ambiguous grammar exists S ε asb Other features: LL(1) Formal of PA 1.38
Example 2 (ww R, w {a, b} + ) Discussion No deterministic PA exists Reason: it is impossible to denote the midpoint without additional information deterministically. A non-ambiguous grammar exists though S ε asa bsb Other features: can t be LL(1) Question: can a deterministic PA be defined for language wcw R, w {a, b} +? Formal of PA 1.39
Example 3 based on grammar description of the language: P = { S SS E, E E + E i (E) }. Problem: ambiguous grammar Consider: i + i + i S E E 1 + E 2 E 1.1 + E 1.2 + E 2... S E E 1 + E 2 E 1 + E 2.1 + E 2.2... We can make it non-ambiguous: P = {S ES, S ε ES, E (E)E ie, E ε + E} Does it help? Not for human... but for machine, maybe. We need a modification of PA. Formal of PA 1.40
Modifications of Pushdown Purpose: new features to make our life easier limit features to study properties and simplify analysis extend features (regulated PA) Selected modifications: Formal of PA 1.41
Head Does Not Move During Reading Limiting feature: when recognizing symbol under the reading head, the head has to move. Formal modification of transition function: δ : Q (Σ {ε}) Γ Q Γ {R, M} R stays for reading the symbol under the reading head only M stays for read&move (traditional behaviour) Notation: δ(q, a, z) (q, α) R δ(q, a, z) (q, α) M we write δ(q, a, z) (q, α) if clear where q, q Q, a Σ, z Γ, α Γ Generally non-deterministic variant: δ : Q (Σ {ε}) Γ 2 Q Γ {R,M} Formal of PA 1.42
Example 1 (a n b n, n 0) M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0 } Σ = {a, b, $} Γ = {a, b, Z 0 } F = {q 0 } δ: δ(q 0, a, Z 0 ) (q 0, az 0 b) R δ(q 0, b, Z 0 ) (q 0, ε) R δ(q 0, a, a) (q 0, ε) δ(q 0, b, b) (q 0, ε) δ(q 0, $, Z 0 ) (q 0, ε) Final configuration 3. Formal of PA 1.43
Example 1 (a n b n, n 0) Acceptance (q 0, aaabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, az 0 b) R (q 0, aaabbb, az 0 b) // δ(q 0, a, a) (q 0, ε) (q 0, aabbb, Z 0 b) // δ(q 0, a, Z 0 ) (q 0, az 0 b) R (q 0, aabbb, az 0 bb) // δ(q 0, a, a) (q 0, ε) (q 0, abbb, Z 0 bb) // δ(q 0, a, Z 0 ) (q 0, az 0 b) R (q 0, abbb, az 0 bbb) // δ(q 0, a, a) (q 0, ε) (q 0, bbb, Z 0 bbb) // δ(q 0, b, Z 0 ) (q 0, ε) R (q 0, bbb, bbb) // δ(q 0, b, b) (q 0, ε) (q 0, bb, bb) // δ(q 0, b, b) (q 0, ε) (q 0, b, b) // δ(q 0, b, b) (q 0, ε) (q 0, $, ε) Formal of PA 1.44
Example 1 (a n b n, n 0) Failure (q 0, aabbb, Z 0 ) // δ(q 0, a, Z 0 ) (q 0, az 0 b) R (q 0, aabbb, az 0 b) // δ(q 0, a, a) (q 0, ε) (q 0, abbb, Z 0 b) // δ(q 0, a, Z 0 ) (q 0, az 0 b) R (q 0, abbb, az 0 bb) // δ(q 0, a, a) (q 0, ε) (q 0, bbb, Z 0 bb) // δ(q 0, b, Z 0 ) (q 0, ε) R (q 0, bbb, bb) // δ(q 0, b, b) (q 0, ε) (q 0, bb, b) // δ(q 0, b, b) (q 0, ε) (q 0, b, ε) // no rule to be applied Formal of PA 1.45
Example 3 P = {S ES, S ε ES, E (E)E ie, E ε + E} M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0 } Σ = {+, i, (, ), $} Γ = {+, i, (, ), E, S, E, Z 0 } F = {q 0 } δ: δ(q 0, (, Z 0 ) (q 0, ES ) R δ(q 0, i, Z 0 ) (q 0, ES ) R δ(q 0, (, E) (q 0, (E)E ) R δ(q 0, i, E) (q 0, ie ) R δ(q 0, (, S ) (q 0, ES ) R δ(q 0, i, S ) (q 0, ES ) R δ(q 0, $, S ) (q 0, ε) R... Formal of PA 1.46
Example 3... δ(q 0, +, E ) (q 0, +E) R δ(q 0, ), E ) (q 0, ε) R δ(q 0, (, E ) (q 0, ε) R δ(q 0, i, E ) (q 0, ε) R δ(q 0, $, E ) (q 0, ε) R δ(q 0, ), )) (q 0, ε) δ(q 0, (, () (q 0, ε) δ(q 0, i, i) (q 0, ε) δ(q 0, +, +) (q 0, ε) Formal of PA 1.47
Example 3 Analysis (q 0, i + i(i), Z 0 ) // δ(q 0, i, Z 0 ) (q 0, ES ) R (q 0, i + i(i), ES ) // δ(q 0, i, E) (q 0, ie ) R (q 0, i + i(i), ie S ) // δ(q 0, i, i) (q 0, ε) (q 0, +i(i), E S ) // δ(q 0, +, E ) (q 0, +E) R (q 0, +i(i), +ES ) // δ(q 0, +, +) (q 0, ε) (q 0, i(i), ES ) // δ(q 0, i, E) (q 0, ie ) R (q 0, i(i), ie S ) // δ(q 0, i, i) (q 0, ε) (q 0, (i), E S ) // δ(q 0, (, E ) (q 0, ε) R (q 0, (i), S ) // δ(q 0, (, S ) (q 0, ES ) R (q 0, (i), ES ) // δ(q 0, (, E) (q 0, (E)E ) R (q 0, (i), (E)E S ) // δ(q 0, (, () (q 0, ε) (q 0, i), E)E S ) // δ(q 0, i, E) (q 0, ie ) R (q 0, i), ie )E S ) // δ(q 0, i, i) (q 0, ε) (q 0, ), E )E S ) // δ(q 0, ), E ) (q 0, ε) R (q 0, ), )E S ) // δ(q 0, ), )) (q 0, ε) (q 0, $, E S ) // δ(q 0, $, E ) (q 0, ε) R (q 0, $, S ) // δ(q 0, $, S ) (q 0, ε) R (q 0, $, ε) Formal of PA 1.48
Example 3 Discussion Grammar features: Non-ambiguous LL(1) Not trivial to construct How could we construct the PA? By straightforward reasoning from the grammar too difficult! By algorithm See Aho, Sethi, Ullman: Compilers... in LL(1) grammar is an input Non-moving pushdown automaton necessary Formal of PA 1.49
of Consider two consecutive moves made by a pushdown automaton, M. If during the first move M does not shorten its pushdown and during the second move it does, then M makes a turn during the second move. A pushdown automaton is one-turn if it makes no more than one turn with its pushdown during any computation starting from an initial configuration. Theorem One-turn pushdown automata characterize a family of linear languages. Proof : see Harrison... in. Formal of PA 1.50
Discussion Example of one-turn PA Example 1 Can we re-construct 1 and 2 to be one-turn? YES! Do it! Hint: differentiate extension and shortening of pushdown by states, allow just one turn! Formal of PA 1.51
of Modify δ as a mapping from Q (Σ {ε}) (Γ {ε}). During a move, an atomic pushdown automaton changes a state and, in addition, performs exactly one of the following actions: 1 it pushes a symbol onto the pushdown e.g. δ(q, ε, ε) {(q, a)} 2 it pops a symbol from the pushdown e.g. δ(q, ε, a) {(q, ε)} 3 it reads an input symbol e.g. δ(q, a, ε) {(q, ε)} Formal of PA 1.52
Example 1 (a n b n, n 0) M = (Q, Σ, Γ, δ, q 0, Z 0, F) Q = {q 0, q a, q a, q a, q b, q F } Σ = {a, b, $} Γ = {b, Z 0 } F = {q F } δ: δ(q 0, a, ε) (q a, ε) δ(q a, ε, Z 0 ) (q a, ε) δ(q a, ε, ε) (q a, b) δ(q a, ε, ε) (q 0, Z 0 ) δ(q 0, b, ε) (q b, ε) δ(q b, ε, Z 0 ) (q b, ε) δ(q b, ε, b) (q 0, ε) δ(q 0, $, ε) (q F, ε) δ(q F, ε, Z 0 ) (q F, ε) Features: deterministic, atomic easy to implement Formal of PA 1.53
Example 1 (a n b n, n 0) Acceptance (q 0, aabb, Z 0 ) // δ(q 0, a, ε) (q a, ε) (q a, abb, Z 0 ) // δ(q a, ε, Z 0 ) (q a, ε) (q a, abb, ε) // δ(q a, ε, ε) (q a, b) (q a, abb, b) // δ(q a, ε, ε) (q 0, Z 0 ) (q 0, abb, Z 0 b) // δ(q 0, a, ε) (q a, ε) (q a, bb, Z 0 b) // δ(q a, ε, Z 0 ) (q a, ε) (q a, bb, b) // δ(q a, ε, ε) (q a, b) (q a, bb, bb) // δ(q a, ε, ε) (q 0, Z 0 ) (q 0, bb, Z 0 bb) // δ(q 0, b, ε) (q b, ε) (q b, b, Z 0 bb) // δ(q b, ε, Z 0 ) (q b, ε) (q b, b, bb) // δ(q b, ε, b) (q 0, ε) (q 0, b, b) // δ(q 0, b, ε) (q b, ε) (q b, $, b) // δ(q b, ε, b) (q 0, ε) (q 0, $, ε) // δ(q 0, $, ε) (q F, ε) (q F, $, ε) Formal of PA 1.54
Example 1 (a n b n, n 0) Failure (q 0, a, Z 0 ) // δ(q 0, a, ε) (q a, ε) (q a, $, Z 0 ) // δ(q a, ε, Z 0 ) (q a, ε) (q a, $, ε) // δ(q a, ε, ε) (q a, b) (q a, $, b) // δ(q a, ε, ε) (q 0, Z 0 ) (q 0, $, Z 0 b) // δ(q 0, $, ε) (q F, ε) (q F, $, Z 0 b) // δ(q F, ε, Z 0 ) (q F, ε) (q F, $, b) // no rule to be applied (q 0, b, Z 0 ) // δ(q 0, b, ε) (q b, ε) (q b, $, Z 0 ) // δ(q b, ε, Z 0 ) (q b, ε) (q b, $, ε) // no rule to be applied Formal of PA 1.55
Example 1 (a n b n, n 0) Discussion Easy to implement easy to define (algorithmically) Quite a lot of steps... Automaton without movement of reading head is much more efficient... Importance in the formal theory simplicity of definition minimality of description... Formal of PA 1.56
We have presented: of pushdown automaton Connected terms: configuration, transition step, language accepted by PA Deterministic and non-deterministic variant Some modifications Main importance in: Analysis of context-free languages Theoretical computer science Formal of PA 1.57
Aho, A.V., Ullman, J.D.: The Theory of Parsing, Translation, and Compiling, Volume I: Parsing, Prentice-Hall, 1972, ISBN 0-13-914556-7. Aho, A.V., Sethi, R., Ullman, J.D.: Compilers, Principles, Techniques, and Tools, Addison-Wesley, 1986, ISBN 0-201-10194-7. Merriam Webster, http://www.merriam-webster.com/ Harrison, M.: to Formal Language Theory, Addison Wesley, Reading, 1978. Formal of PA 1.58