algorithm - 正则文法产生字符串?

标签 algorithm parsing grammar

我有一篇论文指出:

(...) languajes such as strings of x's followed by the same number of y's (for example xxxxyyyy) cannot be specified by a regular grammar or Finite States Automaton because these devices have no mechanism for remembering how many x's were generated when the time comes to derive the y's. This shortcoming is remedied by means of rules such as S → xSy, which always generate an x and a y at the same time. (...)

所以,我不明白这个说法,据我所知,这样的字符串可以用生产规则的常规语法生成:

S → xS

S → yS

S → y

其中 x,y 是终结符,S 是起始唯一非终结符。这个文法产生推导

S→xS→xxS→xxxS→xxxxS→xxxxyS→xxxxyyS→xxxxyyyS→xxxxyyyy

最佳答案

语法必须生成语言中的每个字符串,并且没有非语言的字符串。

您的语法还会在第三个产生式或 xxyxyxy 中生成无效字符串 y,因此您可以NOT 说这是你的语言的语法。

关于algorithm - 正则文法产生字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43696780/

相关文章:

algorithm - Knuth-Morris-Pratt 的转换表

python - 从字符串中读取数据,区分元素是数字还是数组

c++ - 搜索快速/高效的直方图算法(使用预先指定的 bin)

java - 为什么我的 ANTLR4 语法中的这一添加会破坏不相关的规则替代方案?

ios - 如何读取本地 JSON 文件进行测试

c++ - 代码的最优解,使其可以执行最多 10^18 的计算

algorithm - "one or more"带 LL 解析器

python - 如何使 pyparsing 语法依赖于实例属性?

regex - 为什么 Perl 6 语法原型(prototype)的正文中不能有任何内容?

c - 如何解析 C 中的十进制 UUID 字符串?