Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I gotta make a CFG and PDA for the grammar that has perfectly nested parentheses and brackets.

$\qquad\begin{align} S &\to [S] \\ S &\to (S) \\ S &\to SS \\ S &\to \varepsilon \end{align}$

Not sure if this is correct, or how to make the PDA from it?

share|cite|improve this question
Try using the standard construction from the proof that CFG and NPDA are equally powerful! Does "perfectly nested" exclude $([)]$ here? – Raphael Nov 19 '12 at 18:11

The language you study is a classic, the one-sided Dyck language (on two pairs of brackets). You can directly make a PDA by considering the following property of nested strings: every symbol closing bracket you read should match the last unmatched opening bracket. Keep the unmatched $[$ and $($ on the stack and you are ready to go.

share|cite|improve this answer

A: your CFG looks good.

B: There is a very well-known method of converting CFGs to PDAs.


Or the Wikipedia article on Pushdown automata

also this question has some interesting details.

But mainly - google "Converting CFG ro PDA".

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.