Context Free Grammar for which a RegEx is impossible

牧云@^-^@ 提交于 2019-12-13 07:28:33

问题


I'm trying to find out if its possible to have an example of a CFG for which it is impossible to give a Regular Expression which can accept the same language.


回答1:


Any language which requires counting/remembering can't be expressed as a regular expression.

For example, a language which checks balanced parenthesis:

S -> { S } S

S -> ε



回答2:


Since a regular machine/expression has only a limited (pre-defined) number of states, it cannot "remember" (infinitely) earlier parts of the input.

As such recognizing the following expression is impossible for a state-machine: anbn (n∈ℕ)

You could make such a machine for n ≤ x, where x∈ℕ, but no state-machine can do it for every possible value from ℕ.



来源:https://stackoverflow.com/questions/5120170/context-free-grammar-for-which-a-regex-is-impossible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!