简体   繁体   English

CFG for a^nb^3m c d^mef^2n 与 m, n > 0

[英]CFG for a^n b^3m c d^m e f^2n with m, n > 0

I want to find the CFG for this a^nb^3m c d^mef^2n with m, n > 0我想找到这个 a^nb^3m c d^mef^2n 的 CFG,m, n > 0

What I have so far到目前为止我所拥有的

S -> A B C
A -> a A ff
B -> bbb B d
C -> c e

Does this make any sense?这有道理吗?

I think that this is the grammar:我认为这是语法:

; 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

Your grammar so far allows the c to come after the d which violates the rules.到目前为止,您的语法允许c出现在违反规则的d之后。

The following should work以下应该工作

S = a S ff | a bbb B d e ff
B = bbb B d | c

The first rule guarantees, that for every a in the beginning there are two f in the end.第一条规则保证,对于开头的每个a ,最后都有两个f It enforces at least one a .它至少强制执行一个a The second half enforces the sequence de ff... .后半部分强制执行顺序de ff...

The second rule enforces the correct number of b and d and also that the single c is between the b s and the c s第二条规则强制bd的正确数量,并且单个cb s 和c s 之间

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

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