0

We define the language ABC inductively as:

  1. epsilon is in ABC.
  2. if x is in ABC then so are [x] and (x),
  3. if x and y are both in ABC then so is xy.

Describe a PDA for this language which accepts by empty stack. Give all transitions.

1 Answers1

0

First, we recognize that we need an accepting state q0. Because epsilon is in the language, we can consider q0 to be accepting (and accept by empty stack as well as accepting state, simultaneously). We will arrange that q0 represent the state of the PDA whenever the prefix of input we have processed so far has balanced braces and parentheses; all strings in the language will end up here, and with empty stack. If we're ever in q0 and we do not see the bottom-of-stack symbol Z0 on top of the stack, we can safely crash and reject the input (though we will arrange it so this never occurs).

If q0 corresponds to having seen a string in the language, and because there can be prefixes not in the language which, nevertheless, can return to the language, we deduce we need at least one additional state. Call this q1. We can add transitions from q0 to q1 on either [ or ( and push these to the stack so we remember what they were. We can go ahead and crash if we see ] or ) in state q0 since we are arranging it so that being in state q0 means we have seen a prefix of the input which is a string in the language, and seeing closing braces and parentheses at such a stage cannot be fixed.

In state q1, we have seen some opening braces and/or parentheses which have not been matched by corresponding closing braces and/or parentheses. At any point, we may accept opening braces or parentheses by returning to q1 and pushing the symbols encountered to the top of the stack. However, when encountering closing parentheses, we must be careful to make sure we are matching the right thing. Therefore, we only need transitions to handle matched pairs; we can crash on unmatched pairs.

If ever in state q1 we are looking at an empty stack, we recognize that we have matched everything in the current segment and are looking at a string in the language; we can add an epsilon transition back to q0 in this case.

The completed PDA looks like this:

Q    s    S    Q'    S'
-    -    -    -     -
q0   [    Z0x  q1    [Z0x
q0   (    Z0x  q1    (Z0x
q1   [    x    q1    [x
q1   (    x    q1    (x
q1   ]    [x   q1    x
q1   )    (x   q1    x
q1   e    Z0   q0    Z0

In the above:

  • e is epsilon, the empty string
  • x is an arbitrary string over the input alphabet
  • Z0 is the bottom-of-stack symbol
Patrick87
  • 27,682
  • 3
  • 38
  • 73