简体   繁体   中英

Context Free Grammar for which a RegEx is impossible

我试图找出是否可能有一个CFG的例子,因为它不可能给出一个可以接受相同语言的正则表达式。

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: a n b n (n∈ℕ)

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

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 -> ε

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM