正则表达式
首先,我不知道这是否是我所要求的正确翻译。
在我的一门课程中,我们只是开始学习正则表达式、形式语言等。
Alphabet {1,0,S,R}
Terminals {1,0}
Rules:
S ::= 0
S ::= 1
S ::= 1R
R ::= 1R
R ::= 0R
R ::= 1
R ::= 0
在这种情况下,假设我从 1R 开始,然后我可以继续使用 1R 或 0R。
如果我从 1R 开始,那么只有 1...那么这个句子(在本例中是二进制数)就完整了,对吗?因为我不能事后“追加”一些东西,比如说1R,然后我选择1,然后我再次选择1R?
预先感谢,如果不正确,请重新标记/移动帖子。
添加:
0 at rule S ::= 0
1 with S ::= 1
10 with S ::= 1R, so R ::= 0
如何生成1100110?
这不是作业,而是幻灯片中的示例/问题。我不明白这是怎么做到的。
First of all I do not know if this is the correct translation for what I am asking.
In one of my courses we just stared learning about regular expressions, formal languages and so on.
Alphabet {1,0,S,R}
Terminals {1,0}
Rules:
S ::= 0
S ::= 1
S ::= 1R
R ::= 1R
R ::= 0R
R ::= 1
R ::= 0
In this case let say that I start with the 1R, then I could keep on going with either 1R or 0R.
If I start with 1R, then just a 1....then the sentence(in this case its binary numbers) is complete right? Because I can't "append" something afterwards, say 1R then I choose 1 and then I choose 1R again?
Thanks in advance, and please retag/move post if its uncorrect.
ADDED:
0 at rule S ::= 0
1 with S ::= 1
10 with S ::= 1R, so R ::= 0
How to generate 1100110?
This is not homework, it is an example/question from the powerpoint. I do not get how that is done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你所拥有的是一种常规语言,使用上下文无关语法定义。定义相同语言的正则表达式是
(0)U(1{0,1}*)
。在简单的英语中,常规语言包含以 1 开头的所有 0 和 1 字符串以及字符串 0。上下文无关语法以一些初始非终结符开头,在本例中它似乎是 S。然后您可以替换根据列出的产生规则,任何带有符号字符串的非终结符号。当字符串不包含非终结符时,它就“完成”了。
在您的示例中,如果字符串中当前有 S 或 R 需要替换,您只能“选择 1R”。与此语法一样,第一次将 R 替换为 1 时,不再需要替换任何非终结符,字符串的生成就完成了。
编辑:这是 1100110 的生产痕迹。
What you have there is a regular language, defined using a context free grammar. A regular expression that defines the same language is
(0)U(1{0,1}*)
. In plain english, the regular language contains all strings of 0s and 1s that start with 1, and the string 0.A context free grammar starts with some initial non-terminal symbol, in this case it appears to be S. You then can replace any non-terminal symbols with a string of symbols according to the production rules listed. It is "done" when the string contains no non-terminal symbols.
In your example, you can only "choose 1R" if there is currently an S or an R in the string to replace. As it happens with this grammar, the first time you replace R with 1, you no longer have any non-terminals to replace, and that production of a string is finished.
Edit: Here is a trace of the production of 1100110.
你是对的。不允许追加,只能替换。然而,使用这种语言,您可以通过选择“R ::= 1R”或“R ::= 0R”,然后再次替换 R 来不断使字符串更长。
You are correct. Appending is not allowed, only substitution. However with this language, you could continually make your string longer by choosing "R ::= 1R" or "R ::= 0R", and then substituting for R once again.
是的,这是正确的。句子 11 匹配 S = 1R = 11。
但是,使用此语法,您始终可以使用 R = 1R 或 R= 0R 在句子中添加越来越多的数字。
编辑:回应问题编辑:
1100110 = S = 1R = 11R = 110R = 1100R = 11001R = 110011R = 1100110
希望有助于您理解。
祝你好运!
Yes, this is correct. The sentence 11 matches S = 1R = 11.
However with this grammar you could always use R = 1R or R= 0R to add more and more digits to your sentence.
Edit: In response to the question edit:
1100110 = S = 1R = 11R = 110R = 1100R = 11001R = 110011R = 1100110
Hope that helps you understand.
Good Luck!