Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

Similar documents
Einführung in die Computerlinguistik

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Fundamentele Informatica II

Pushdown Automata. Reading: Chapter 6

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Computational Models - Lecture 4

Theory of Computation - Module 3

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

CISC4090: Theory of Computation

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Computational Models - Lecture 4 1

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Automata Theory CS F-08 Context-Free Grammars

Foundations of Informatics: a Bridging Course

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

C6.2 Push-Down Automata

CPS 220 Theory of Computation Pushdown Automata (PDA)

Section 1 (closed-book) Total points 30

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Computation (IV) Yijia Chen Fudan University

Introduction to Theory of Computing

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Theory of Computation

Automata Theory (2A) Young Won Lim 5/31/18

Computational Models - Lecture 4 1

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computational Models - Lecture 5 1

Accept or reject. Stack

Theory of Computer Science

Introduction to Formal Languages, Automata and Computability p.1/42

CA320 - Computability & Complexity

Theory of Computation

A representation of context-free grammars with the help of finite digraphs

How to Pop a Deep PDA Matters

Lecture 11 Context-Free Languages

Pushdown Automata (2015/11/23)

5 Context-Free Languages

Languages, regular languages, finite automata

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Automata Theory - Quiz II (Solutions)

CISC 4090 Theory of Computation

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

Formal Languages and Automata

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Pushdown Automata. Chapter 12

Theory of Computation Turing Machine and Pushdown Automata

INSTITUTE OF AERONAUTICAL ENGINEERING

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Computability and Complexity

CS375: Logic and Theory of Computing

Lecture 17: Language Recognition

How do regular expressions work? CMSC 330: Organization of Programming Languages

Theory of Computation (Classroom Practice Booklet Solutions)

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CISC 4090 Theory of Computation

Embedded systems specification and design

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

UNIT-VI PUSHDOWN AUTOMATA

Computational Models - Lecture 3

Please give details of your answer. A direct answer without explanation is not counted.

Part I: Definitions and Properties

Solution Scoring: SD Reg exp.: a(a

REGular and Context-Free Grammars

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

Concordia University Department of Computer Science & Software Engineering

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage?

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Context-free Grammars and Languages

Parsing -3. A View During TD Parsing

CSE 105 THEORY OF COMPUTATION

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

Uses of finite automata

Theory of Computation - Module 4

Chapter 3. Regular grammars

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Automata Theory and Formal Grammars: Lecture 1

3515ICT: Theory of Computation. Regular languages

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) Turing Machines 9-0

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

CpSc 421 Final Exam December 15, 2006

3.13. PUSHDOWN AUTOMATA Pushdown Automata

The View Over The Horizon

Pushdown Automata (Pre Lecture)

Mildly Context-Sensitive Grammar Formalisms: Embedded Push-Down Automata

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Transcription:

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