[英]Generating CFG for a Language
Consider the language {a n b m c p | n <= p OR m <= p}
考虑一下语言
{a n b m c p | n <= p OR m <= p}
{a n b m c p | n <= p OR m <= p}
, create a CFG for this language. {a n b m c p | n <= p OR m <= p}
,为此语言创建CFG。
I have started this with S -> aA | aB
我从
S -> aA | aB
S -> aA | aB
, but am unsure how I should go about defining A or B. The "OR" seems quite difficult to incorporate into the language's definition as it doesn't seem necessary to track both n and m and compare them against p, yet I don't know which one I want to track S -> aA | aB
,但不确定如何定义A或B。“ OR”似乎很难纳入语言的定义中,因为似乎不必同时跟踪n和m并将它们与p进行比较,但是我没有不知道我要追踪哪一个
In order to maintain that constraint, for every 'a' you need to add a 'c'. 为了维持该约束,您需要为每个“ a”添加一个“ c”。 Similarly for every 'b' you should add a 'c'.
同样,对于每个“ b”,您都应添加一个“ c”。
A -> aAC | aC | B
B -> bB | bC
C -> cC | c
I could be wrong here. 我在这里可能是错的。 But that's how you should think while creating a CFG.
但这就是创建CFG时应该考虑的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.