下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 【精品】编译原理JAVA模拟LL(1)文法分析过程(整理)

【精品】编译原理JAVA模拟LL(1)文法分析过程(整理).doc

【精品】编译原理JAVA模拟LL(1)文法分析过程(整理)

韩松梅
2017-10-19 0人阅读 举报 0 0 暂无简介

简介:本文档为《【精品】编译原理JAVA模拟LL(1)文法分析过程(整理)doc》,可适用于工程科技领域

【精品】编译原理JAVA模拟LL()文法分析过程(整理)importjavautilArrayListlshimportjavautilScanner***ÌâĺLL()ÖÎöýÌÄÄâ*author:Áõsh×ÔºÀÁÍêÉ,ÁÖÆó*time:ÔÂÈÕ*Äܺ*ÊÊÓÔÂú×ãLLÄÒÎĵÄÊäÈëÖÎö*ÊÊÓÊäÈëÖÐåÈëÕñ*ÓÐòµµÄíÎóÌáÊ*ÙÎÄÈçϺ*EúTE*EúTEòÅ*TúFT*Tú*FTòÅ*Fú(E)òi*publicclassLLAnalysis{publicstaticvoidmain(Stringa){intid=intindex=ÇÂÕ×îºóÒöÇÖÕáûµÄÎÖÃStringtopStack,topIn,operationStringBufferinString=ArrayList<String>list=newArrayList<String>()Systemoutprintln("ÇëÊäÈëÒöÓïä:")Scannerin=newScanner(Systemin)Stringins=innextLine()trim()if(insindexOf("#")<)ÙÈç×îºóÍêÁËÊäÈë#ºÅÒÃÊÂins="#"elseins=inssubstring(,insindexOf("#"))ØÈ#ºÅÔÚÄÚµÄÇinString=newStringBuffer(ins)intkong=inStringindexOf("")while(kong>=)ȵôÊäÈëíïÊÖеÄÕñ{inStringdelete(kong,kong)kong=inStringindexOf("")}StringBufferstack=newStringBuffer("#E")ÖÎöÕõÊÅÈëEStringll={{"","i","","*","(",")","#"},{"E","ETP","","","ETP","",""},{"E","","ETN","","","ÅP","ÅP"},{"T","TFP","","","TFP","",""},{"T","","ÅP","TFN","","ÅP","ÅP"},{"F","ÅN","","",")EN","",""},{")","","","","","ÅN",""},{"#","","","","","","acc"}}ll()ÖÎöØÕóSystemoutprintln("LL()ÖÎöýÌÈçϺ")Systemoutprintln("nÐòºÅtÖÎöÕ"getBlank()"ÊäÈëÊýÝ"getBlank()"×")StringBufferliutemp=while(stacklength()>){intx=,y=ÇÂÔÚÖÎöíÖеĵĺá×Ý×øêif(stacktoString()endsWith("'")||stacktoString()endsWith(""))ÖÃÊÇøÁËÒƵÄÇÖÕáûindex=stacklength()elseindex=stacklength()topStack=StringvalueOf(stacksubstring(index,stacklength()))ÕÔªËØif(inStringlength()>)topIn=StringvalueOf(inStringcharAt())ÊÓàÊäÈëµÄµÚÒöÔªËØelsetopIn=""for(inti=i<lllengthi)ÆËãÔÓÖÎöíµÄÄÄÒÐÐif(topStackequals(lli)){x=ibreak}for(inti=i<lllengthi)ÆËãÔÓÖÎöíµÄÁÐÊýif(topInequals(lli)){y=ibreak}operation=llxy×ÃüÁîif(operationlength()>=){Stringfirst=operationsubstring(,operationlength())ÌæÖStringlast=operationsubstring(operationlength(),operationlength())ÊÇñÐÐÖif(firstequals("Å"))first=""if(operationequals("acc")){if(stacklength()==inStringlength()==){Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringgetBlank(operationlength())operation)stackdelete(,)inStringdelete(,)Systemoutprintln("ÆÅäÉ")}else{Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringgetBlank()"error")Systemoutprintln("ÄÜÍêÕûÆÅä")}}elseif(lastequals("P")){Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringgetBlank(operationlength())operation)stackreplace(index,indextopStacklength(),first)ÑÕÔªËØÌæΪÖÎöíÖÐÖµif(firstequals(""))listadd(llx">Å")else{liutemp=newStringBuffer(first)listadd(llx">"reverse(liutemp))}id}elseif(lastequals("N")){Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringgetBlank(operationlength())operation)stackreplace(index,indextopStacklength(),first)inStringdelete(,)ÏàµÓÚÁÏÂÒöÔªËØliutemp=newStringBuffer(first)listadd(llx">"topInreverse(liutemp))if(stacktoString()endsWith("'")||stacktoString()endsWith(""))index=stacklength()ÖØÐÂÉèÖÃindexÖµelseindex=stacklength()id}else{Systemoutprintln("ÖÎöíÔìöí")Systemexit()}}elseif(y==){Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringgetBlank()"error")Systemoutprintln("ÊäÈëµÄûºÅûºÏæÎÄ")Systemexit()}elseif(x!=y!=operationlength()==){Systemoutprintln(id"t"stackgetBlank(stacklength()inStringlength())inStringinStringgetBlank()"error")Systemoutprintln("ÊäÈëûºÅÍêÕû")Systemexit()}}Systemoutprintln("nÃÓïä×ÔÏòÏÂÓïÊý̺")for(inti=i<listsize()i)Systemoutprintln(listget(i))}publicstaticStringBufferreverse(StringBufferbuffer){×ÖÄÔËËãûµÖÃStringBufferbuf=newStringBuffer()intix=intlength=if(bufferindexOf("'")<bufferindexOf("")<)bufappend(bufferreverse())else{while(bufferlength()>){length=bufferlength()if(buffercharAt(length)=='''||buffercharAt(length)==''){bufappend(buffersubstring(length,length))bufferdelete(length,length)}else{bufappend(buffercharAt(length))bufferdelete(length,length)}}}returnbuf}publicstaticStringgetBlank(intn){µÃµnöÁÐøÕñStringblank=""for(inti=i<ni)blank=""returnblank}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/8

【精品】编译原理JAVA模拟LL(1)文法分析过程(整理)

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利