I wanna construct NPDA corresponding to the below grammar. Please tell me the idea of the construction.
S -> aABB|aAA
A -> aBB|a
B -> bBB|A
I wanna construct NPDA corresponding to the below grammar. Please tell me the idea of the construction.
S -> aABB|aAA
A -> aBB|a
B -> bBB|A
A general method for getting an NPDA out of a CFG is the following:
So our NPDA might look like this:
states: q0, q1
alphabet: a, b
stack alphabet: Z, a, b, S, A, B
start state: q0
final state: q1
transitions:
(q0, e, Z) -> (q1, SZ)
(q1, e, S) -> (q1, aABB)
(q1, e, S) -> (q1, aAA)
(q1, e, A) -> (q1, aBB)
(q1, e, A) -> (q1, a)
(q1, e, B) -> (q1, bBB)
(q1, e, B) -> (q1, A)
(q1, a, a) -> (q1, e)
(q1, b, b) -> (q1, e)
Here's an execution trace processing the string aaaa:
state: q0, stack: Z , remaining input: aaaa
state: q1, stack: SZ , remaining input: aaaa
state: q1, stack: aABBZ , remaining input: aaaa
state: q1, stack: ABBZ , remaining input: aaa
state: q1, stack: aBBZ , remaining input: aaa
state: q1, stack: BBZ , remaining input: aa
state: q1, stack: ABZ , remaining input: aa
state: q1, stack: aBZ , remaining input: aa
state: q1, stack: BZ , remaining input: a
state: q1, stack: AZ , remaining input: a
state: q1, stack: aZ , remaining input: a
state: q1, stack: Z , remaining input: e
Thus, the string aaaa is accepted since there is one path through the NPDA that accepts.