BU CS 332 – Theory of Computation
Lecture 7:
- More on CFGs
- Pushdown Automata
Reading: Sipser Ch 2.1‐2.3
Mark Bun February 12, 2020
BU CS 332 Theory of Computation Lecture 7: Reading: More on CFGs - - PowerPoint PPT Presentation
BU CS 332 Theory of Computation Lecture 7: Reading: More on CFGs Sipser Ch 2.1 2.3 Pushdown Automata Mark Bun February 12, 2020 Context Free Grammar (Formal) A CFG is a 4 tuple is a finite set of variables is a
Reading: Sipser Ch 2.1‐2.3
Mark Bun February 12, 2020
A CFG is a 4‐tuple
, where and
∗
2/12/2020 CS332 ‐ Theory of Computation 2
Example Grammar Parse Tree | | | Derivation
2/12/2020 CS332 ‐ Theory of Computation 3
2/12/2020 CS332 ‐ Theory of Computation 4
𝑀 is a context‐free language if it is the language of some CFG
Questions about CFLs
context‐free?
whether 𝑥 ∈ 𝑀?
properties of CFLs?
2/12/2020 CS332 ‐ Theory of Computation 5
Let be a context‐free language. Then there exists a “pumping length” such that 1. 2. 3.
𝑗 𝑗
for all For every where , can be split into five parts where:
2/12/2020 CS332 ‐ Theory of Computation 6
Claim:
Proof: Assume is context‐free with pumping length
with
cannot be pumped If = with | | , then… Case 1: both contain only one kind of symbol Case 2: Either or contains two kinds of symbols
2/12/2020 CS332 ‐ Theory of Computation 7
Claim:
Proof: Assume is context‐free with pumping length
with
cannot be pumped If = with | | , then… Case 1: both contain only one kind of symbol
2/12/2020 CS332 ‐ Theory of Computation 8
2/12/2020 CS332 ‐ Theory of Computation 9
Claim:
Proof: Assume is context‐free with pumping length
with
cannot be pumped If = with | | , then… Case 2: Either or contains two kinds of symbols
Let be a context‐free language. If is long enough, then every parse tree for has a repeated variable.
2/12/2020 CS332 ‐ Theory of Computation 10
What does “long enough” mean? (How do we choose the pumping length ?)
be a CFG for
uses at most symbols
Claim: If with , then the smallest parse tree for has height at least
2/12/2020 CS332 ‐ Theory of Computation 11
Claim: If with , then the smallest parse tree for has height at least
with a repeated variable 𝑆
2/12/2020 CS332 ‐ Theory of Computation 12
2/12/2020 CS332 ‐ Theory of Computation 13
𝑀 is a context‐free language if it is the language of some CFG
Questions about CFLs
context‐free?
whether 𝑥 ∈ 𝑀?
properties of CFLs?
2/12/2020 CS332 ‐ Theory of Computation 14
2/12/2020 CS332 ‐ Theory of Computation 15
2/12/2020 CS332 ‐ Theory of Computation 16
Input 𝑏 𝑐 𝑏 𝑏 Finite control … Input 𝑏 𝑐 𝑏 𝑏 Finite control … 𝑦 𝑦 𝑧 Memory: Infinite Stack
Pushdown Automata (PDAs): Machine with unbounded structured memory in the form of a stack Finite Automata (FAs): Machine with a finite amount of unstructured memory
pop, read) symbol at the top
2/12/2020 CS332 ‐ Theory of Computation 17
Input 𝑏 𝑐 𝑏 𝑏 Finite control … 𝑦 𝑦 𝑧 Memory: Infinite Stack
Transitions of the form: 𝑏, 𝑦 → 𝑦′
2/12/2020 CS332 ‐ Theory of Computation 18
Input 𝑏 𝑐 𝑐 𝑐 𝑐 𝑏 Finite control … Memory: Infinite Stack
2/12/2020 CS332 ‐ Theory of Computation 19
Input 𝑏 𝑐 𝑐 𝑐 𝑐 𝑏 Finite control … Memory: Infinite Stack
Algorithmic Description
1. Place the marker $ on the stack 2. Nondeterministically, either a) Read a character and push it to the stack, or b) Go to the next step 3. Nondeterministically, either a) Pop the stack if it matches the next character or b) Go to the next step 4. Accept if the top of the stack is $
2/12/2020 CS332 ‐ Theory of Computation 20
𝜁, 𝜁 → $ 𝑏, 𝜁 → 𝑏 𝜁, 𝜁 → 𝜁 𝑏, 𝑏 → 𝜁 𝜁, $ → 𝜁
𝑔
𝑐, 𝜁 → 𝑐 𝑐, 𝑐 → 𝜁
A PDA is a 6‐tuple (sorry)
2/12/2020 CS332 ‐ Theory of Computation 21
0 and an empty
2/12/2020 CS332 ‐ Theory of Computation 22
𝜁, 𝜁 → $ 𝑏, 𝜁 → 𝑏 𝜁, 𝜁 → 𝜁 𝑏, 𝑏 → 𝜁 𝜁, $ → 𝜁
𝑔
𝑐, 𝜁 → 𝑐 𝑐, 𝑐 → 𝜁 𝜀 : 𝑅 Σ Γ
→ 𝑄 𝑅 Γ
𝜀 𝑟, 𝑏, 𝑏 𝜀 𝑟, 𝑏, 𝑐