在无上下文的语法中,我们在替换过程中是否替换所有变量?还是我们只能将替代规则仅适用于同一类型的变量?
想象一下,我们有一个免费的语言语法,CFG,如下:
S-> A ...(1)
S-> )
中得出一个字符串,如下:
,我在指定的语言
2
ss ... ( 在1个变量上而不是所有相同变量上的施加规则?
因此,我的问题是我是否要在“ SS”上应用规则(1),我是否可以选择(1)将(1)应用于“ SS”的1秒钟,还是我必须对两个s申请?
Imagine we have a Context Free Grammer, CFG, as follows:
S -> a ...(1)
S -> SS ...(2)
And i derive a string in the specified language as follows:
S ..start state
SS ..using (2)
aS ...using (1) <- is this valid, like only applying the subsititution rule on 1 variable instead of all same variables?
So my question is if i were to apply rule (1) on "SS", do i have the option to apply (1) to only 1 S of the "SS" or do i have to apply to both of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只能将规则应用于一个S,也可以按照自己的方式应用。这是一个更复杂的例子,可以更好地说明这个想法:
那么,这种语言中有什么字符串?这是带有派生的前几个字符串:
无论如何,我们发现语法会产生A和B的所有非空字符串,包括那些混合A和B的弦。如果我们必须用相同的规则替换所有S,那么如果我们有一种(非空)的语言,我们将获得更小得多的语言。
You can apply the rule to only one S, or as many as you like. Here is a slightly more complicated example that maybe better illustrates the idea:
So, what strings are in this language? Here are the first few strings with derivations:
Anyway, we find that the grammar generates all non-empty strings of a's and b's, including those with mixed up a's and b's. If we had to replace all S's with the same rule, we would get a much, much smaller language, if we'd get a (non-empty) language at all.