1

Im trying to design the NDPA for the following grammar. I'm confused. Can you help me?

∑ = {a,b}    

G = (V,∑,R,S)
V = {S,T,X}

S -> aTXb
T -> XTS|ε
X -> a|b
broomba
  • 109
  • 7
VolkanK
  • 11
  • 2

1 Answers1

1

There are at least two approaches: try to figure out what the language is and then write down an efficient PDA that works for that language; or, if you're lazy, you can cheat and use the construction that proves NPDAs are at least as powerful as CFGs. Let's do the latter, since this language doesn't appear to be super easy to describe.

To use the construction, build a NPDA that does the following:

  1. first, push the nonterminal start symbol S
  2. next, pop from the stack
    • if the symbol is a terminal, consume that symbol from the NPDA's input and push nothing
    • if the symbol is a nonterminal, nondeterministically push the right-hand side of every production for the symbol, and do not consume any input
  3. repeat step 2 until you crash (you cannot consume from input a symbol matching the popped terminal symbol) or you run out of input. If you run out of input with an empty stack, then accept. Otherwise, if you crash or if the stack still has stuff in it at the end, reject.

This construction works by nondeterministically constructing every possible derivation in the grammar. NPDAs accept a string if and only if some nondeterministic path accepts it; and that would only happen for our NPDA if there were a valid derivation according to the grammar. By definition, the language of a grammar is exactly the set of strings that have a valid derivation, so we're done.

Patrick87
  • 27,682
  • 3
  • 38
  • 73