BadGrammar
L = { anbn | n >= 1 }
We know this languge is not regular by the pumping lemma for regular languages.
It is, however, a context-free language (CFL).
What is a grammar for L?
G = ({S}, {a,b}, S, R) where the set of rules R is S -> a S b | a b
For regular languages we had two equivalent automata:
These are equivalent in the sense that the languages recognized by some DFA is the same as the set of languages recognized by some NFA.
So it would seem likely that the same situation might occur for context-free languages and corresponding automata; deterministic and non-deterministic versions.
Informally a push down automaton
For the input string aaabbb
So 3 x's are pushed on the stack.
Then 3 x's are popped off the stack.
The machine halts in state q2
The string is accepted.
What would happen for aaabbbb? or for aaabb?
For grammars that are LL(1) and even for a slightly larger class of context-free grammars, the languages can be recognized by some deterministic push down automaton.
However, this is not true for every context-free grammar.
The kind of automaton that is needed to recognized a CFL in general is non-deterministic.
BadGrammar[8] [top]
S -> a S a | b S b | ε The language is { wwR | where w is in {0,1}* and wR is the reverse of w } E.g, aabaabaa and abbbbbba Problem for the automaton: Where is themiddle?
A pushdown automaton is a 6-tuple (Q, ∑, Γ, δ, q0, F) where Q, ∑, Γ, and F are all finite sets, and
This definition of a Push Down Automaton (PDA) is non-deterministic since the transition function has values in the power set of Q x Γε
Where are the push and pop operations?
Is there a way for the automaton to specify the stack should be empty?
Is there a way for the automaton to specify 'eof', that is no more input remaining?
The notation and conventions in the diagram are specific to the JFLAP program.
JFLAP = Java Formal Language and Automata Package
JFLAP is by Professor Susan Rodger, Duke University, and her students. It is available at http://www.jflap.org
This is the notation Sipser uses.
Here e represents ε (JFLAP uses λ instead of ε) Transition label a, b -> c means 1. read input symbol a 2. the top of the stack should be 'b'; replace it with 'c' Note: either b or c can be ε a, ε -> c means 1. read a 2. push c a, b -> ε means 1. read a 2. pop b
The definition of the operation of the non-determinisitic PDA doesn't directly have a way of checking that the stack is empty when the input has all been read.
So this is simulated by initially pushing a sentinel
value on the stack without reading any input.
Add a new start state if necessary with this transition to the original intended start state ε, ε -> $
In JFLAP, instead of adding a new start state, that step is essentially done automatically.
1. Instead of $, JFLAP uses Z 2. Instead of beginning with an empty stack, JFLAP starts with Z on the stack.
Pushing on the stack must be formulated in terms of the transition function
How do you read 'a' and achieve the effect of popping 'S' and pushing three symbols x1 x2 x3 on the stack?
Formally a PDA accepts an input string w if
such that the 3 conditions are satisfied.
The sentinel, Z, that JFLAP places on the stack initially as a counterpart in context-free grammars.
It is called augmenting the grammar.
S -> a S a | b S b | ε Agumented grammar: 1. Add a new start symbol, P, the sentinel, Z, and 2. One new rule P P -> S Z Revised grammar: P -> S Z S -> a S a | b S b | ε
We can use JFLAP with the grammar above to see the non-determinism in action.
The PDA for any context free grammar is constructed like this:
Give a derivation for aabbaa using the grammar:
P -> S Z S -> a S a | b S b | ε
Now construct the PDA with JFLAP and run it on input aabbaa
A -> BAB | B | ε B -> 00 | ε