简体   繁体   English

构造一个CFG

[英]Construct a CFG for

L1 = { a^ib^j | L1 = {a ^ ib ^ j | i,j>=0 } i,j> = 0}

My attempt: 我的尝试:

S = SA|e

A = aAB|e

B = bB|e

I have no way to confirm my answer, is this correct? 我无法确认我的答案,这是对的吗?

It's not correct because there's no way to get a single "b" (or any number of "b"s without any "a"s). 这是不正确的,因为无法获得单个“ b”(或任何数量的“ b”而没有任何“ a”)。

(And I think you can fix it by changing just one letter ;o) (我认为您只需更改一个字母即可解决它; o)

PS Sorry for earlier incorrect reply; PS对不起早先的错误回复; thought it was for i=j. 以为这是为了i = j。

You define L1 = {a^ib^j | 你定义L1 = {a ^ ib ^ j | i, j >= 0}. 我,j> = 0}。 In words, this is the language of all strings which begin with zero or more a's, and which end with zero or more b's. 换句话说,这是所有字符串的语言,以零或多个a开头,以零或多个b结尾。 This is a regular language; 这是一种常规语言; a regular expression for it is a*b*. 它的正则表达式是* b *。 A regular grammar (also a context-free grammar) is the following: 常规语法(也是无上下文语法)如下:

S := lambda | aS | bT
T := lambda | bT

Another context-free grammar is the following: 另一个无上下文语法如下:

S := lambda | aS | Sb

Sorry if I'm missing something and your language is more complicated than what I'm reading. 对不起,如果我错过了什么,你的语言比我正在读的更复杂。 If you have some reason to believe that L1 so defined is different from the language I have described, please explain. 如果您有理由相信如此定义的L1与我所描述的语言不同,请解释。

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

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