简体   繁体   English

如何构建生成语言L的语法?

[英]How to construct a grammar that generates language L?

I'm in a Formal languages class and have a grammar quiz coming up. 我正在上一门正式语言课,并且即将进行语法测验。 I'm assuming something like this will appear. 我假设这样的事情会出现。

Consider the alphabet ∑ = {a, b, c}. 考虑字母∑ = {a,b,c}。 Construct a grammar that generates the language L = {bab^nabc^na^p : n ≥ 0, p ≥ 1}. 构造一个生成语言L = {bab ^ nabc ^ na ^ p:n≥0,p≥1}的语法。 Assume that the start variable is S. 假设起始变量是S。

It was a very long time since I worked with formal languages for the last time, so, please, forgive my rustyness, but this would be the language: We divide S to a prefix variable ( A ) and a suffix variable ( B ). 自从我上次使用正式语言以来已经很长时间了,因此,请原谅我的生疏,但这就是语言:我们将S分为前缀变量( A )和后缀变量( B )。 Then, we handle the prefix and the suffix separately, both of them have a possible rule of further recursion, and an end sign of empty, where no occurrence is required and the constant where at least an occurrence is required. 然后,我们分别处理前缀和后缀,它们都有进一步递归的可能规则,并且结尾符号为空(其中不需要出现)和常数(至少需要出现)。

{bab^nabc^na^p : n ≥ 0, p ≥ 1}

S -> ASB
A -> babAabc
A -> {empty}
B -> Ba
B -> a

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

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