简体   繁体   English

无法使用RegEx的Context Free Grammar

[英]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∈ℕ) 因此,对于状态机来说,识别以下表达式是不可能的: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 ℕ. 您可以为n≤x生成这样的机器,其中x∈ℕ,但是没有状态机可以为every的每个可能值执行此操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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