Let's say I have a formal language,

a^n b^n which mean ab,aabb,aaabbb

Can I write any regular expression or grammar to create a language like this? I am positive not entirely sure that there is not regex possible, however have no idea about the grammar part?


1 Answer 1


This language is context-free but not regular. It is isomorphic to the problem of matching open and closed parentheses: (n)n which is a well-known non-regular language. To prove this yourself, you would use the pumping lemma for regular languages.

Every regular grammar describes a regular language.
This language is not regular.
Therefore, there cannot be a regular grammar that describes it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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