简体   繁体   English

我怎样才能推导出这些语法

[英]How can I derivate these Grammar

G = (V={S,X,Y}, T={0,1,2},P,S)

S -> 0X1
X ->S | 00S2 | Y | ε
Y ->X | 1

The Problem is I don´t know how to derivate numbers..问题是我不知道如何推导数字..

How can I derivate this here: 00111 ∈ L(G)我怎样才能在这里推导:00111 ∈ L(G)

And here I have to give a derivation three: 0000121 ∈ L(G)在这里我必须给出推导三:0000121 ∈ L(G)

To do a derivation you start with the start symbol (in this case S ) which is the fourth item in the grammar tuple).要进行推导,您从开始符号(在本例中为S )开始,它是语法元组中的第四项)。 You then apply the production rules ( P ) in whatever order seems appropriate to you.然后,您可以按照适合您的任何顺序应用生产规则 ( P )。

A production like:像这样的生产:

X → S | 00S2 | Y | ε

means that you can replace an X with表示您可以将X替换为

  • S , or S
  • 00S2 , or 00S2 ,或
  • Y , or Y , 或
  • nothing.没有什么。

In other words, you read production rules as follows:换句话说,您阅读生产规则如下:

  • means "can be replaced with". 表示“可以替换为”。
  • | means "or"意思是“或”
  • ε means "nothing" (Replacing a symbol with nothing means deleting it from the current string.) ε表示“无”(用无替换符号意味着将其从当前字符串中删除。)

Everything else is just a possible symbol in the string.其他一切都只是字符串中的一个可能符号。 You keep doing replacements, one at a time, until you reach the string you are trying to derive.你一直在做替换,一次一个,直到你找到你想要导出的字符串。

Here's a quick example:这是一个简单的例子:

S
 → 0X1      (using S → 0X1)
 → 000S21   (using X → 00S2)
 → 0000X121 (using S → 0X1)
 → 0000121  (using X → ε)

That's it.而已。 Nothing complicated at all.一点都不复杂。 Just a bunch of search and replace operations.只是一堆搜索和替换操作。 (You don't need to replace the first occurrence, if there is more than one possibility. You can do the replacements in any order you like. But it's convenient to be systematic.) (如果有多个可能性,则不需要替换第一个出现的位置。您可以按照自己喜欢的任何顺序进行替换。但是系统化很方便。)

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

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