【发布时间】:2022-01-13 06:22:28
【问题描述】:
我想找到这个 a^n b^3m c d^m e f^2n with m, n > 0 的 CFG
我目前拥有的东西
S -> A B C
A -> a A ff
B -> bbb B d
C -> c e
这有意义吗?
【问题讨论】:
标签: context-free-grammar context-free-language
我想找到这个 a^n b^3m c d^m e f^2n with m, n > 0 的 CFG
我目前拥有的东西
S -> A B C
A -> a A ff
B -> bbb B d
C -> c e
这有意义吗?
【问题讨论】:
标签: context-free-grammar context-free-language
我认为这是语法:
; this rule generates "a" first and "ff" last
S = a A ff
; allow more "a" first and "ff" last
A = S
; between "a^n" and "f^2n" there will be "b^3m c d^m" followed by "e"
A = B e
; this rule generates "bbb" first and "d" last
B = bbb C d
; allow more "bbb" first and "d" last
C = B
; this rules generates "c" between "b^3m" and "d^m"
C = c
【讨论】:
到目前为止,您的语法允许 c 出现在违反规则的 d 之后。
以下应该可以工作
S = a S ff | a bbb B d e ff
B = bbb B d | c
第一条规则保证,对于开头的每个a,最后都有两个f。它至少强制执行一个a。后半部分强制执行序列d e ff...。
第二条规则强制执行正确数量的b 和d,并且单个c 位于bs 和cs 之间
【讨论】: