1
我在讀Dick Grune的Parsing Techniques - A Practical Guide,我被卡在一個正式語法的例子上(起始頁22)。他開始用這樣的:(書中圖2.2)以上對創建正式語法的例子感到困惑
0. Name -> tom
Name -> dick
Name -> harry
1. Sentence -> Name
Sentence -> List End
2. List -> Name
List -> List , Name
3. , Name End -> and Name
4. the start symbol is Sentence
重新編寫引入了「清單」:
0. Name may be replaced by 「tom」
Name may be replaced by 「dick」
Name may be replaced by 「harry」
1. Sentence may be replaced by Name
2. Sentence may be replaced by Sentence, Name
3. 「, Name」 at the end of a Sentence must be replaced by 「and Name」
before Name is replaced by any of its replacements
4. a sentence is finished only when it no longer contains non-terminals
5. we start our replacement procedure with Sentence
然後,他更正式如下重新寫這個。我認爲列表是一個非終端,但我不知道它來自哪裏或它的意思。另外,除非我誤讀文本,否則圖2.2與第一個圖應該是相同的,但它們並不完全匹配。例如,圖1中第一個數字的規則#2(「句子可以被句子替換,名稱」)在哪裏。 2.2?
感謝您指出錯字。但是,這並不能讓我在那裏。 「列表」只是一個符號,如「結束」和「名稱」? – WebUserLearner
是的。它不是終端。唯一的終端是「湯姆」,「迪克」和「哈里」。 您可以在規則1.2和2.2的組合中找到規則#2,因爲「語句」可能被「列表結尾」替換,「列表」可能會被替換爲「列表,名稱」。因此,您可以在上面的文本中獲得對應於句子,名稱的「List,Name End」。 – Pluto