2

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
Rurou2
  • 167
  • 1
  • 1
  • 7

1 Answers1

2

A general method for getting an NPDA out of a CFG is the following:

  1. Convert the grammar G to Chomsky Normal Form (CNF); call the resulting grammar G'.
  2. Make the NPDA push G's start symbol S' onto the stack and transition to a second state.
  3. In this second state, there are two cases:
    • If the stack symbol is a nonterminal in G', then nondeterministically choose one of the productions for that nonterminal in G' and replace the nonterminal with that production's right-hand side
    • If the stack symbol is a terminal in G', consume that terminal symbol in the NPDA and simply pop it off the stack

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.

Patrick87
  • 27,682
  • 3
  • 38
  • 73