(4.5.1)--3.5.1ReductionsandHandle-.pdf

上传人:刘静 文档编号:57971759 上传时间:2022-11-06 格式:PDF 页数:28 大小:805.16KB
返回 下载 相关 举报
(4.5.1)--3.5.1ReductionsandHandle-.pdf_第1页
第1页 / 共28页
(4.5.1)--3.5.1ReductionsandHandle-.pdf_第2页
第2页 / 共28页
点击查看更多>>
资源描述

《(4.5.1)--3.5.1ReductionsandHandle-.pdf》由会员分享,可在线阅读,更多相关《(4.5.1)--3.5.1ReductionsandHandle-.pdf(28页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Compilers TechniquesSyntaxA n a l y s i sReviewContext-free grammarsTop-downBottom-upLL(1)grammarsTwo functionsRecursive-descent prediction parsingNonrecursive predictive parsingLeftmost derivationsRightmost derivations!Top-down Parsing corresponds to the process of constructing a syntax tree using

2、leftmost derivationE lmTE lmFT E lmid T E lm id*F T E lmid*id T E lmid*id E lmid*idETE E +TE|TFT T *FT|F(E)|idinput:id*idETE id*T Fid FT Leftmost Derivations and Top-down ParsingCan the rightmost derivation be used for top-down parsing?E lmTE lmFT E lmid T E lm id*F T E lmid*id T E lmid*id E lmid*id

3、ETE E +TE|TFT T *FT|F(E)|idinput:id*idETE id*T Fid FT Read the input string from left to right,but do the rightmost derivations.Its difficult to use the character on the left to decide the expansion ofnon-terminal on the right.Rightmost derivations:not suitable for top-down parsing tree construction

4、Leftmost Derivations and Top-down ParsingStarting from the given sentence,hope to turn sentences into start symbols Rightmost derivations,used for bottom-up parsingNext part Bottom-up parsing,corresponds to the inverse process of rightmost derivationsIntroducing the concept of reductions Reduction i

5、s an inverse process of derivation.Eid+id*idBottom-Up ParsingImportantConceptReductionsHandle PruningOverview of Bottom-Up ParsingReducting:an important action in bottom-up parsingS aABeA Abc|bB dReductions correspond to the inverse process of the rightmost derivationsabbcdeaAbcdeaAdeaABeSrmrmrmrmGr

6、ammar:a b b c d eAABSReductionsReductione.g.S aABeA Abc|bB dabbcdeaAbcdeeabbdcAabbcdeaAbcde rmBottom-Up ParsingReductione.g.S aABeA Abc|bB dabbcdeaAbcdeaAdeeabbdcAAabbcdeaAde rmaAbcde rmBottom-Up ParsingReductione.g.S aABeA Abc|bB dabbcdeaAbcdeaAdeaABeeabbdcAABabbcdeaABe rmaAde rmaAbcde rmBottom-Up

7、ParsingReductione.g.S aABeA Abc|bB dabbcdeaAbcdeaAdeaABeSeabbdcabbcdeAABSSrmaABe rmaAde rmaAbcde rmBottom-Up ParsingHandle:A substring that matches the right of a productionS aABeA Abc|bB dS rmaABe rmaAde rmaAbcde rmabbcde A handle is a substring of a right-sentential form.Reducing the handle to a n

8、on-terminal represents one step along the reverse of a rightmost derivation.Bottom-Up ParsingProperties of handlese.g.E E+E|E*E|(E)|idE rmE*EE rmE+ErmE*E+ErmE+id3rmE*E+id3rmE*E+id3rmE*id2+id3rmE*id2+id3rmid1*id2+id3rmid1*id2+id3In the pattern E*E+id3,the handle is not unique.S rmaABe rmaAde rmaAbcde

9、 rmabbcde The right side of the handle contains only the terminal If the grammar is ambiguous,the handle may not be uniqueBottom-Up ParsingInformal definition of handlesThe handle of a sentential form is the string that matches the right of a production in the sentential form.Grammar:S aABeA Abc|bB

10、dWhat are the possible handles in the rightmost derivation?aABeAbcbdHandlesHandlesPrecise definition of handle The handle of the right-sentential form is the right part of a production.After replacing handle in with a,the former sentential form in rightmost derivation is obtained Let =,can be reduce

11、d to sentential form A through production form A-abbcdeaAbcde rmaAAcde rmaAAcdeis not the grammars right patternIs ba handle?So bis not a handle of aAbcdeIf bis a handle,this step of derivation exists.Grammar:S aABe A Abc|bB dAll the sentential formsthat appear in the rightmost derivations are calle

12、d right-sententialformsS*X is the handle of X In the shift-reduce parsing,the handle always appears at the top of the stack.Bottom-up parsing is based on identifying handles.Handlese.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmr

13、mrmrmBottom-Up Parsingabbcdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up Parsingabbcdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmB

14、ottom-Up Parsingbabcdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingAabcdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-

15、Up ParsingbAacdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingAacdee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up Pars

16、ingcAadee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingdcAaee.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingBcAae

17、e.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingeBcAae.g.Grammar G(S):(1)S aAcBe(2)A b(3)A Ab(4)B dTry to carry out shift-reduce parsing on abbcdeabbcdeaAbcdeaAcdeaAcBeSrmrmrmrmBottom-Up ParsingSCompilers TechniquesSyntaxA n a l y s i s

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁