欢迎来到天天文库
浏览记录
ID:10794287
大小:551.50 KB
页数:18页
时间:2018-07-08
《编译原理实验二 ;语法分析》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、福州大学数学与计算机科学(软件)学院编译原理——语法分析器成员:杨霞030802107王日日030802139方艳丽03080210218福州大学数学与计算机科学(软件)学院实验二:语法分析实验一、实验目的根据给出的文法编制LR(1)分析程序,以便对任意输入的符号串进行分析。本次实验的目的主要是加深对LR(1)分析法的理解。二、实验内容对已给语言文法,构造LR(1)分析表,编制语法分析程序,要求将错误信息输出到语法错误文件中,并输出分析句子的过程(显示栈的内容)LR(1)分析法的功能是利用LR(
2、1)分析表,对输入符号串自下而上的分析过程。LR(1)分析表的构造及分析过程。三.实验文法::=::=::=const;ε::==,=3、decl>::=var;ε::=,::=procedure;;ε::=:=callbeginendifthenwhiledoε4、ent-list>::=;::=odd::==<><><=>=::=::=+-::=5、tor>::=/::=()18福州大学数学与计算机科学(软件)学院文法缩略版:P->SS->BDB->varH;H->idH,idD->i=Ecall(k)if(k)DelseDwhile(K)doDK->ERER-><>>=<=<>==E->EOTTT->TQFFO->+-Q->/F->idnunber(E)<6、programe>::=P::=S::=B::=H::=D::=K::=E::=T::=F18福州大学数学与计算机科学(软件)学院实验环境:windowsmicrosoftvisualc++实验原理:构造项集Setofltemsclosure(I){repeatforeachA®a.Bb,ainJandeachprodutcionB®gofGs7、uchthatB®.g,eachoffirst(ba)isnotinJ:ADDB®.g,btoIuntil…nomoreitemscanbeaddedtoIreturnI}Setofltemsgoto(I,X):{IfIisasetofLR(1)itemsandXisagrammarsymbol(terminalornon-terminal),thengoto(I,X)isdefinedasfollows:IfA.X,ainItheneveryiteminclosure({AX.,a})will8、beingoto(I,X).}Voiditems(){Cis{closure({S’®.S,$})}repeatthefollowingsuntilnomoresetofLR(1)itemscanbeaddedtoC.foreachIinCandeachgrammarsymbolXifgoto(I,X)isnotemptyandnotinCaddgoto(I,X)toC简略分析表:0123456789101112202122232425idnumcallifelsewhiledo>()@DHKE
3、decl>::=var;ε::=,::=procedure;;ε::=:=callbeginendifthenwhiledoε4、ent-list>::=;::=odd::==<><><=>=::=::=+-::=5、tor>::=/::=()18福州大学数学与计算机科学(软件)学院文法缩略版:P->SS->BDB->varH;H->idH,idD->i=Ecall(k)if(k)DelseDwhile(K)doDK->ERER-><>>=<=<>==E->EOTTT->TQFFO->+-Q->/F->idnunber(E)<6、programe>::=P::=S::=B::=H::=D::=K::=E::=T::=F18福州大学数学与计算机科学(软件)学院实验环境:windowsmicrosoftvisualc++实验原理:构造项集Setofltemsclosure(I){repeatforeachA®a.Bb,ainJandeachprodutcionB®gofGs7、uchthatB®.g,eachoffirst(ba)isnotinJ:ADDB®.g,btoIuntil…nomoreitemscanbeaddedtoIreturnI}Setofltemsgoto(I,X):{IfIisasetofLR(1)itemsandXisagrammarsymbol(terminalornon-terminal),thengoto(I,X)isdefinedasfollows:IfA.X,ainItheneveryiteminclosure({AX.,a})will8、beingoto(I,X).}Voiditems(){Cis{closure({S’®.S,$})}repeatthefollowingsuntilnomoresetofLR(1)itemscanbeaddedtoC.foreachIinCandeachgrammarsymbolXifgoto(I,X)isnotemptyandnotinCaddgoto(I,X)toC简略分析表:0123456789101112202122232425idnumcallifelsewhiledo>()@DHKE
4、ent-list>::=;::=odd::==<><><=>=::=::=+-::=5、tor>::=/::=()18福州大学数学与计算机科学(软件)学院文法缩略版:P->SS->BDB->varH;H->idH,idD->i=Ecall(k)if(k)DelseDwhile(K)doDK->ERER-><>>=<=<>==E->EOTTT->TQFFO->+-Q->/F->idnunber(E)<6、programe>::=P::=S::=B::=H::=D::=K::=E::=T::=F18福州大学数学与计算机科学(软件)学院实验环境:windowsmicrosoftvisualc++实验原理:构造项集Setofltemsclosure(I){repeatforeachA®a.Bb,ainJandeachprodutcionB®gofGs7、uchthatB®.g,eachoffirst(ba)isnotinJ:ADDB®.g,btoIuntil…nomoreitemscanbeaddedtoIreturnI}Setofltemsgoto(I,X):{IfIisasetofLR(1)itemsandXisagrammarsymbol(terminalornon-terminal),thengoto(I,X)isdefinedasfollows:IfA.X,ainItheneveryiteminclosure({AX.,a})will8、beingoto(I,X).}Voiditems(){Cis{closure({S’®.S,$})}repeatthefollowingsuntilnomoresetofLR(1)itemscanbeaddedtoC.foreachIinCandeachgrammarsymbolXifgoto(I,X)isnotemptyandnotinCaddgoto(I,X)toC简略分析表:0123456789101112202122232425idnumcallifelsewhiledo>()@DHKE
5、tor>::=/::=()18福州大学数学与计算机科学(软件)学院文法缩略版:P->SS->BDB->varH;H->idH,idD->i=Ecall(k)if(k)DelseDwhile(K)doDK->ERER-><>>=<=<>==E->EOTTT->TQFFO->+-Q->/F->idnunber(E)<
6、programe>::=P::=S::=B::=H::=D::=K::=E::=T::=F18福州大学数学与计算机科学(软件)学院实验环境:windowsmicrosoftvisualc++实验原理:构造项集Setofltemsclosure(I){repeatforeachA®a.Bb,ainJandeachprodutcionB®gofGs
7、uchthatB®.g,eachoffirst(ba)isnotinJ:ADDB®.g,btoIuntil…nomoreitemscanbeaddedtoIreturnI}Setofltemsgoto(I,X):{IfIisasetofLR(1)itemsandXisagrammarsymbol(terminalornon-terminal),thengoto(I,X)isdefinedasfollows:IfA.X,ainItheneveryiteminclosure({AX.,a})will
8、beingoto(I,X).}Voiditems(){Cis{closure({S’®.S,$})}repeatthefollowingsuntilnomoresetofLR(1)itemscanbeaddedtoC.foreachIinCandeachgrammarsymbolXifgoto(I,X)isnotemptyandnotinCaddgoto(I,X)toC简略分析表:0123456789101112202122232425idnumcallifelsewhiledo>()@DHKE
此文档下载收益归作者所有