Knowledge Management: 2. Foundations Romi Satria Wahono [email protected] WA/SMS: +6281586220090 1.
Theory of Computation 5. Pushdown Automata Romi Satria Wahono [email protected] Mobile:...
-
Upload
madeleine-paul -
Category
Documents
-
view
215 -
download
2
Transcript of Theory of Computation 5. Pushdown Automata Romi Satria Wahono [email protected] Mobile:...
![Page 1: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/1.jpg)
Theory of Computation5. Pushdown Automata
Romi Satria [email protected]
http://romisatriawahono.net/tcMobile: +6281586220090
1
![Page 2: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/2.jpg)
Romi Satria Wahono
• SD Sompok Semarang (1987)• SMPN 8 Semarang (1990)• SMA Taruna Nusantara Magelang (1993)• B.Eng, M.Eng and Ph.D in Software Engineering from
Saitama University Japan (1994-2004)Universiti Teknikal Malaysia Melaka (2014)• Research Interests: Software Engineering,
Machine Learning• Founder dan Koordinator IlmuKomputer.Com• Peneliti LIPI (2004-2007)• Founder dan CEO PT Brainmatics Cipta Informatika
2
![Page 3: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/3.jpg)
Course Outline
1. Introduction2. Math Fundamental 1: Set, Sequence, Function3. Math Fundamental 2: Graph, String, Logic4. Finite Automata5. Pushdown Automata6. Turing Machines
3
![Page 4: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/4.jpg)
5. Context-Free Languages5.1 Context-Free Grammars5.2 Push Down Automata
4
![Page 5: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/5.jpg)
5.1 Context-Free Grammars
5
![Page 6: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/6.jpg)
Recap: Models of Computation
Model Language Recognition
Memory Management Implementation
Finite Automata
Regular Languages
No temporary memory
Elevators, Vending Machines, Traffic Light, Neural Network(small computing power)
Pushdown Automata
Context-free Languages Stack
Compilers for Programming Languages(medium computing power)
Turing machine
Unrestricted Grammar, Lambda Calculus(Computable Languages)
Random access memory
Any Algorithm(highest computing power)
6
![Page 7: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/7.jpg)
• A Context Free Grammar is a “machine” that creates a language
• A language created by a CF grammar is called A Context Free Language (CFL)
• The class of Context Free Languages Properly Contains the class of Regular Languages
Introduction and Motivation
7
![Page 8: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/8.jpg)
• Consider grammar :
• A CFL consists of substitution rules called Productions
• The capital letters (I) are the Variables
• The string consists of variables and other symbols called the Terminals
Context Free Grammar - Example
1G
I
aIbI
8
![Page 9: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/9.jpg)
• Consider grammar :
• The grammar generates the language
called the language of
, denoted by
Context Free Grammar - Example
0| nbaB nn
1G
I
aIbI
1G
1G 1GL
9
![Page 10: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/10.jpg)
• Consider grammar :
• This is a Derivation of the word by :
• On each step, a single rule is activated
• This mechanism is nondeterministic
Context Free Grammar - Example
aaabbbaaaIbbbaaIbbaIbI
1G
I
aIbI
1Gaaabbb
10
![Page 11: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/11.jpg)
This is A Parse Tree of the word by :
Context Free Grammar - Example
1Gaaabbb
I
I
I
bbbaaa
I
11
![Page 12: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/12.jpg)
Each internal node of the tree is associated with a single production
Context Free Grammar - Example
bbbaaa
I
I
I
I
aIbI
I
12
![Page 13: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/13.jpg)
Context Free Grammar (CFG) - Example• Example of a context-free grammar, which we call G3
A → 0A1A → BB → #
• For example, grammar G3 generates the string 000#111• The sequence of substitutions to obtain a string is called a derivation. A
derivation of string 000#111 in grammar G3 is
A 0A1 00A11 000A111 000B111 000#111⇒ ⇒ ⇒ ⇒ ⇒
• We abbreviate several rules with the same left-hand variable, using the symbol “ | ” as an “or”• A → 0A1 and A → B
A → 0A1 | B
• We may also represent the same information pictorially with a parse tree13
![Page 14: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/14.jpg)
Parse Tree for 000#111 in Grammar G3
14
![Page 15: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/15.jpg)
• Grammar G2 has:• 10 variables (the capitalized grammatical terms written inside brackets)• 27 terminals (the standard English alphabet plus a space character)• 18 rules
• Strings in L(G2) include:• a boy sees• the boy sees a flower• a girl with a flower likes the boy
• Each of these strings has a derivation in grammar G215
CFG – Example of English Language
![Page 16: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/16.jpg)
Derivation of the First String
16
![Page 17: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/17.jpg)
A Context Free Grammar is a 4-tupple
where:
1. is a finite set called the variables
2. is a finite set, disjoint from V called the terminals
3. is a set of rules, where a rule is a variable and a
string of variables and terminals, and
4. is the start variable
CF Grammar – A Formal Definition
SRV ,,,
V
R
VS
17
![Page 18: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/18.jpg)
• A word is a string of terminals
• A derivation of a word w from a context Free Grammar
is a sequence of strings
over , where:
1. is the start variable of G
2. For each , is obtained by activating a single
production (rule) of G on one of the variables of
A Derivation – A Formal Definition
SRVG ,,,
li 1
Ss 0
wsssS l ...10
V
is
1is18
![Page 19: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/19.jpg)
• A word w is in the Language of grammar G,
denoted by , if there exists a
derivation whose rightmost string is w
• Thus,
CF Grammar – A Formal Definition
GLw
GwwGL from derived be can |
19
![Page 20: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/20.jpg)
FACTORFACTORTERMTERM |
Grammar :
Rules:1. 2. 3.
Example2: Arithmetical EXPS
TERMTERMEXPREXPR |
EXPRS
FACTORTERMEXPV ,,
baEXPRFACTOR ||
)(,,,,, ba
2G
20
![Page 21: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/21.jpg)
Derivation of by Grammar : input
Example2: Arithmetical EXPS
EXPR
2G aba
21
![Page 22: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/22.jpg)
Derivation of by Grammar : input rule
Example2: Arithmetical EXPS
EXPR
2G aba
TERMEXPR
22
![Page 23: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/23.jpg)
TERMEXPR
Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS
2G aba
TERMEXPR
23
![Page 24: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/24.jpg)
TERMEXPR
Derivation of by Grammar : input
Example2: Arithmetical EXPS
2G aba
24
![Page 25: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/25.jpg)
Derivation of by Grammar : input rule
TERMEXPR
Example2: Arithmetical EXPS
2G aba
FACTORTERMTERM
25
![Page 26: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/26.jpg)
Derivation of by Grammar : input output rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
FACTORTERMTERM
26
![Page 27: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/27.jpg)
Derivation of by Grammar : input
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
27
![Page 28: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/28.jpg)
Derivation of by Grammar : input
rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aFACTOR
28
![Page 29: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/29.jpg)
Derivation of by Grammar : input output rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aFACTOR
aTERM
29
![Page 30: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/30.jpg)
Derivation of by Grammar :
input
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERM
30
![Page 31: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/31.jpg)
Derivation of by Grammar :
input rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERM
FACTORTERM
31
![Page 32: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/32.jpg)
aFACTORaTERM
Derivation of by Grammar :
input output rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
FACTORTERM
32
![Page 33: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/33.jpg)
Derivation of by Grammar :
input
aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
33
![Page 34: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/34.jpg)
Derivation of by Grammar :
input rule
aFACTORaTERM FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
EXPRFACTOR
34
![Page 35: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/35.jpg)
Derivation of by Grammar :
input output rule
aFACTORaTERM FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
EXPRFACTOR
aEXPR
35
![Page 36: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/36.jpg)
Derivation of by Grammar :
input
aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aEXPR
36
![Page 37: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/37.jpg)
Derivation of by Grammar :
input rule
aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aEXPR
TERMEXPREXPR
37
![Page 38: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/38.jpg)
Derivation of by Grammar :
input output rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
TERMEXPREXPR
38
![Page 39: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/39.jpg)
Derivation of by Grammar :
input
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
39
![Page 40: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/40.jpg)
Derivation of by Grammar :
input
input
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
TERMEXPR
40
![Page 41: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/41.jpg)
Derivation of by Grammar :
input output rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
TERMEXPR
aTERMTERM
41
![Page 42: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/42.jpg)
aTERMEXPRaEXPR aFACTORaTERM
Derivation of by Grammar :
input
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
42
![Page 43: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/43.jpg)
aTERMEXPRaEXPR aFACTORaTERM
Derivation of by Grammar :
input
rule
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
FACTORTERM
43
![Page 44: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/44.jpg)
Derivation of by Grammar :
output rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
FACTORTERM
aFACTORFACTOR
44
![Page 45: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/45.jpg)
Derivation of by Grammar :
input
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM aFACTORFACTOR
45
![Page 46: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/46.jpg)
Derivation of by Grammar :
input rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
aFACTOR
aFACTORFACTOR
46
![Page 47: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/47.jpg)
Derivation of by Grammar :
output rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
aFACTOR
aFACTORFACTOR
aFACTORa
47
![Page 48: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/48.jpg)
Derivation of by Grammar :
input
FACTORTERMTERMEXPR
aTERMEXPRaEXPR aFACTORaTERM
Example2: Arithmetical EXPS
2G aba
aTERMTERM aFACTORFACTOR
aFACTORa
48
![Page 49: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/49.jpg)
Derivation of by Grammar :
input rule
aTERMEXPRaEXPR aFACTORaTERM
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM
bFACTOR
aFACTORFACTOR
aFACTORa
49
![Page 50: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/50.jpg)
aTERMEXPRaEXPR aFACTORaTERM
Derivation of by Grammar :
FACTORTERMTERMEXPR
Example2: Arithmetical EXPS
2G aba
aTERMTERM aFACTORFACTOR
abaaFACTORa
50
![Page 51: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/51.jpg)
Derivation of by Grammar :
Example2: Arithmetical EXPS
TERMEXPREXPR
2G
TERMFACTORTERMTERM
FACTORTERMaTERMa
FACTORFACTORa
FACTORba
aba
aba
Note: There is more than one derivation
51
![Page 52: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/52.jpg)
• We already saw that a word may have more then a single derivation from the same grammar• A Leftmost Derivation is a derivation in which rules
are applied in order left to right• A grammar is ambiguous if it has Two parse trees
• Reminder: Two parse trees are equal if they are equal as trees and if all productions corresponding to inner nodes are also equal
Ambiguity
52
![Page 53: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/53.jpg)
Grammar :
Rules:
Example4: Similar to Arith. EXPS
EXPREXPREXPR
EXPRS
FACTORTERMEXPV ,,
)(,,,,, ba
4G
EXPREXPREXPRaEXPR
53
![Page 54: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/54.jpg)
aba
Example4: 1st Parse Tree for______
EXPR
EXPR
EXPR EXPR
EXPR
aba
EXPREXPREXPR
54
![Page 55: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/55.jpg)
aba
Example4: 2nd Parse Tree for_____
EXPR
EXPR
EXPR EXPR
EXPR
aba
EXPREXPREXPR
55
![Page 56: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/56.jpg)
• Note: Some ambiguous grammars may have an unambiguous equivalent grammar• But: There exist Inherently Ambiguous Grammars,
i.e. an ambiguous grammar that does not have an equivalent unambiguous one
Ambiguity
56
![Page 57: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/57.jpg)
Q: From a computational point of view, how strong are
context free languages?
A: Since the language is not
regular and it is CF, we conclude that
Q: Can one prove ?
A: Yes
Discussion
0| nbaB nn
RLCFL
RLCFL
57
![Page 58: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/58.jpg)
Q: A language is regular if it is recognized by a DFA (or
NFA). Does there exist a type of machine that
characterizes CFL?
A: Yes, those are the Push-Down Automata (Next Lecture)
Q: Can one prove a language not to be CFL ?
A: Yes, by the Pumping Lemma for CFL-s . For example:
is not CFL
Discussion
0| ncbaL nnn
58
![Page 59: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/59.jpg)
5.2 Push Down Automata
59
![Page 60: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/60.jpg)
• In this lecture we introduce Pushdown Automata, a computational model equivalent to context free languages
• A pushdown automata is an NFA augmented with an infinitely large stack
• The additional memory enables recognition of some non regular languages
Introduction and Motivation
60
![Page 61: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/61.jpg)
Schematic of a Finite Automaton
Finite control
a ba a c input
61
![Page 62: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/62.jpg)
z
Schematic of a Pushdown Automaton
Finite control
b cc a ax
y
stack
input
62
![Page 63: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/63.jpg)
• A Pushdown Automata (PDA) can write an unbounded number of Stack Symbols on the stack and read these symbols later.
• Writing a symbol onto the stack is called pushing and it pushes all symbols on the stack one stack cell down.
Informal Description
63
![Page 64: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/64.jpg)
• Removing a symbol off the stack is called popping and every symbol on the stack moves one stack cell up.
• Note: A PDA can access only the stack’s topmost symbol (LIFO).
Informal Description
64
![Page 65: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/65.jpg)
• This PDA reads symbols from the input.
• As each 0 is read, it is pushed onto the stack.
• As each 1 is read, a 0 is popped from the stack.
• If the stack becomes empty exactly when the last 1 is read – accept.
Otherwise – reject.
A PDA Recognizing_________ nnL 10
65
![Page 66: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/66.jpg)
• The definition of a PDA does not give a special way to check emptiness.
• One way to do it is to augment the stack alphabet with a special “emptiness” marker, the symbol $. (Note: There is nothing special about $ any other symbol not in the original can do.)
Checking Stack Emptiness
66
![Page 67: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/67.jpg)
• The computation is started by an transition in which $ is pushed on the stack.
• If the end marker $ is found on the stack at the end of the computation, it is popped by a single additional transition after which the automaton “knows” that the stack is empty.
Checking Stack Emptiness
67
![Page 68: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/68.jpg)
The label of each transition represents the input (left of arrow) and pushed stack symbol (right of the arrow).
$, 1q
4q 3q
A PDA Recognizing_________ nnL 10
2q 0,0
0,1
0,1
,$
68
![Page 69: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/69.jpg)
The $ symbol, pushed onto the stack at the beginning of the computation, is used as an “empty” marker.
$, e1q
4q 3q
A PDA Recognizing_________ nnL 10
2q 0,0
0,1
0,1
,$
69
![Page 70: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/70.jpg)
The PDA accepts either if the input is empty, or if scanning the input is completed and the PDA is at
$, e1q
4q 3q
A PDA Recognizing_________ nnL 10
2q 0,0
0,1
0,1
,$
4q
70
![Page 71: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/71.jpg)
• A Nondeterministic PDA allows nondeterministic transitions.
• Nondeterministic PDA-s are strictly stronger then deterministic PDA-s
• In this respect, the situation is not similar to the situation of DFA-s and NFA-s.
• Nondeterministic PDA-s are equivalent to CFL-s.
Nondeterministic PDAs
71
![Page 72: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/72.jpg)
A pushdown automaton is a 6-tupple
where:
1. is a finite set called the states.
2. is the input alphabet.
3. is the stack alphabet.
4. is the transition function.
5. is the start state, and
6. is the set of accepting states.
PDA – A Formal Definition
FqQ ,,,,, 0
Q
,: QPQ
Qq 0
QF
72
![Page 73: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/73.jpg)
• Consider the expression :
• Recall that , and that .
• Assume that the PDA is in state , the next input
symbol is , and the top stack symbol is
PDA - The Transition Function
,: QPQ
73
![Page 74: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/74.jpg)
• The next transition may either depend on the input symbol and the stack symbol , or only on the input symbol , or only on the stack symbol , or on none of them.
• This choice is formally expressed by the argument of the transition function as detailed in the next slides.
PDA - The Transition Function
74
![Page 75: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/75.jpg)
• Each step of the automaton is atomic, meaning it is executed in a single indivisible time unit.
• For descriptive purposes only, each step is divided into two separate sub-steps:• Sub-step1: A symbol may be read from the input, a symbol
may be read and popped off the stack.
• Sub-step2: A state transition is carried out and a stack symbol may be pushed on the stack.
Transition Function Sub-steps
75
![Page 76: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/76.jpg)
• If the transition depends both on and we write
. In this case is consumed and is
removed from the stack.
• If the transition depends only on we write
, is consumed and the stack does not
change.
Transition Function – 1st Sub-step
,,q
,,q
76
![Page 77: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/77.jpg)
• If the transition depends only on , we write
. In this case is not consumed and
is removed from the stack.
• Finally, If the transition depends neither on , nor
on , we write . In this case is not
consumed and the stack is not changed.
Transition Function – 1st Sub-step
,,q
,,q
77
![Page 78: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/78.jpg)
• The range of the transition function is :The power set of the Cartesian product of the set of PDA states and the stack alphabet.
• Using pairs means that determines:1. The new state to which the PDA moves.
2. The new stack symbol pushed on the stack.
PDA - The Transition Function
,QP
78
![Page 79: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/79.jpg)
• Using the power set means that the PDA is nondeterministic: At any given situation, it may make a nondeterministic transition.
• Finally, the use of means that at each transition the PDA may either push a stack symbol onto the stack or not (if the value is ).
PDA - The Transition Function
79
![Page 80: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/80.jpg)
Theorem:
A language is CFL if and only if there exists a PDA accepting it.
Lemma->
For any CFL L, there exists a PDA P such that .
CFLG-s and PDA-s are Equivalent
PLL
80
![Page 81: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/81.jpg)
• Since L is a CFL there exists a CFG G such that . We will present a PDA P, that recognizes L.
• The PDA P starts with a word on its input.
• In order to decide whether , P simulates the derivation of w.
Proof Idea
*w
GLL
GLw
81
![Page 82: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/82.jpg)
• Recall that a derivation is a sequence of strings, where each string contains variables and terminals. The first string is always the start symbol of G and each string is obtained from the previous one by a single activation of some rule.
Proof Idea (cont.)
82
![Page 83: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/83.jpg)
• A string may allow activation of several rules and the PDA P non deterministically guesses the next rule to be activated.
• The initial idea for the simulation is to store each intermediate string on the stack. Upon each production, the string on the stack before production is transformed to the string after production.
Proof Idea (cont.)
83
![Page 84: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/84.jpg)
• Unfortunately, this idea does not quite work since at any given moment, P can only access the top symbol on the stack.
• To overcome this problem, the stack holds only a suffix of each intermediate string where the top symbol is the variable to be substituted during the next production.
Proof Idea (cont.)
84
![Page 85: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/85.jpg)
The Intermediate String aaSbb
Finite control
a aa b b
input
S
b
stack
$
bb
85
![Page 86: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/86.jpg)
Push the marker $ and the start symbol S on the stack.
Repeat
If the top symbol is a variable V – Replace V by the right hand side of some non deterministically chosen rule whose left hand side is V .
…..
Informal Description of P
86
![Page 87: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/87.jpg)
Push the marker $ and the start symbol S on the stack.
Repeat
…..
If the top symbol is a terminal compare it with the next symbol on the input. If equal – advance the input and pop the variable else – reject.
Informal Description of P
87
![Page 88: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/88.jpg)
Push the marker $ and the start symbol S on the stack.
Repeat
…..
…..
If the top symbol is $ and the input is finished – accept else – reject
Informal Description of P
88
![Page 89: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/89.jpg)
• We start by defining Extended Transitions:
• Assume that PDA P is in state q , it reads from the input and pops from the stack and then moves to state r while pushing onto the stack.
• This is denoted by .
• Next, extended transitions are implemented.
The Proof
as
luuuu ...,, ,21
saqur ,,,
89
![Page 90: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/90.jpg)
Add states .
Set the transition function as follows:
Add to .
Set ,
,
……
(see next slide)
Implementing Extended Trans.
121,...,,
lqqq
luq ,1 saq ,,
121,,,
luqq
222
,,,
l
uqq
11
,,, urql
90
![Page 91: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/91.jpg)
2q
This extended transition
Is implemented by this transition sequence
Implementing Extended Trans.
q
xyzsa ,
r
q zsa ,
r
1q
x ,
y ,
91
![Page 92: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/92.jpg)
• Let G be an arbitrary CFG. Now we are ready to construct the PDA, P such that that The states of P are awhere E contains all states needed to implement the extended transitions presented in the previous slide.
• The PDA P is presented on the next slide:
The Proof
GLPL EqqqQ acceptloopstart ,,
92
![Page 93: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/93.jpg)
This completes the Proof
The Result PDA
startq
loopq
S$, wAwA rulefor ,
A
acceptq
aaa alfor termin ,
,$
93
![Page 94: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/94.jpg)
aaa alfor termin ,
Consider the following CFG:
Example
||
TaT
baTbS
startq $,
loopq
bS ,
acceptq
,$
S , bS , T ,
a ,
aT ,
T ,
T, aa,
bb,
S$,
wAwA rulefor ,
The Schematic NFA
Implementing First Transition
Implementing 1st Rule with Variables
Implementing 2nd Rule with Variables
Implementing 3rd Rule with Variables
Implementing 4th Rule with Variables
Implementing Rules with Constants
That’s All Folks!!!
94
![Page 95: Theory of Computation 5. Pushdown Automata Romi Satria Wahono romi@romisatriawahono.net Mobile: +6281586220090 1.](https://reader030.fdocuments.in/reader030/viewer/2022032722/56649f485503460f94c6a53a/html5/thumbnails/95.jpg)
Referensi
1. Michael Sipser, Introduction to the Theory of Computation Third Edition, Cengage Learning, 2012
2. George Tourlakis, Theory of Computation, Wiley, 2012
3. John Martin, Introduction to Languages and the Theory of Computation, McGraw-Hill , 2010
4. Robert Sedgewick and Kevin Wayne, Introduction to Computer Science, Addison-Wesley, 2015 (http://introcs.cs.princeton.edu/java)
5. Albert Endres dan Dieter Rombach, A Handbook of Software and Systems Engineering, Pearson Education Limited, 2003
95