An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
句子的派生(推导)___根据规则 句子主语谓语 冠词形容词名词谓语 the 形容词名词谓语 the gray名词谓语 the gray wolf 谓语 the gray wolf 动词直接宾语 the gray wolf 助动词动词原形直接宾语 the gray wolf will 动词原形直接宾语 the gray wolf will eat 直接宾语 the gray wolf will eat 冠词名词 the gray wolf will eat the 名词 the gray wolf will eat the goat
还可以“得出”其他的句子 句子the gray wolf will eat the goat the gray wolf will eat the wolf the gray goat will eat the wolf the gray goat will eat the gray 符合语法且符合语义的句子仅是: the gray wolf will eat the goat
1 E→E+E • 2 E→E*E • 3 E→(E) • 4 E→id • 5 E→E-E • 6 E→E/E 文法使用举例 E E + E (1) id + E (4) id + E * E (2) id + id * E (4) id + id * id (4) E 5 id + id * id
直接推导与归约 • 根据产生式对符号串进行变换的过程 • A→γ是文法G的一个产生式, • 且α、β∈(VT∪VN)*, • 称αAβ的直接推导/派生(Derive)出αγβ,也称 αγβ直接归约(Reduce)为αAβ。 • 记为 αAβαγβ • 例: • id + Eid + E * E
1 E→E+E • 2 E→E*E • 3 E→(E) • 4 E→id 推导/归约举例 E E + E (1) 串中含有变量 • id + E (4) 串中含有变量 • id + E * E (2) 串中含有变量 • id + id * E (4) 串中含有变量 • id + id * id (4) 串中没有变量 • 到此串中已经没有(语法)变量了,不能再推了——得到句子
句型与句子 • E 5 id + id * id • 定义:如果S * x,且x∈VT* ,则称x是G产生的一个句子(Sentence) • E E + E E + E * E • E 4 id + id * E • 定义:如果S*α,α∈(VT∪VN)*则称α是G产生的一个句型(Sentential Form)
例2-3 标识符的文法2 • S →L|LT T → L|N|TL|TN L → a|b|c|d N → 0|1|2|3|4|5 • S → a|b|c|d • S → aT|bT|cT|dT • T → a|b|c|d|0|1|2|3|4|5 • T → aT|bT|cT|dT|0T • T →1T|2T|3T|4T|5T