编译原理龙书答案完整性高第二章2.2ExercisesforSection2.22.2.1Considerthecontext-freegrammar:S->SS+|SS*|aShowhowthestringaa+a*canbegeneratedbythisgrammar.Constructaparsetreeforthisstring.Whatlanguagedoesthisgrammargenerate?Justifyyouranswer.answerS->SS*->SS+S*->aS+S*->aa+S*->aa+a*L={Postfixexpressionconsistingofdigits,plusandmultiplesigns}2.2.2Whatlanguageisgeneratedbythefollowinggrammars?Ineachcasejustifyyouranswer.S->0S1|01S->+SS|-SS|aS->S(S)S|εS->aSbS|bSaS|ε⧗S->a|S+S|SS|S*|(S)answerL={0n1n|n>=1}L={Prefixexpressionconsistingofplusandminussigns}L={Matchedbracketsofarbitraryarrangementandnesting,includesε}L={Stringhasthesameamountofaandb,includesε}?2.2.3WhichofthegrammarsinExercise2.2.2areambiguousanswerNoNoYesYesYes2.2.4Constructunambiguouscontext-freegrammarsforeachofthefollowinglanguages.Ineachcaseshowthatyourgrammariscorrect.Arithmeticexpressionsinpostfixnotation.Left-associativelistsofidentifiersseparatedbycommas.Right-associativelistsofidentifiersseparatedbycommas.Arithmeticexpressionsofintegersandidentifierswiththefourbinaryoperators+,-,*,/.answer1.E->EEop|num2.list->list,id|id3.list->id,list|id4.expr->expr+term|expr-term|termterm->term*factor|term/factor|factorfactor->id|num|(expr)5.expr->expr+term|expr-term|termterm->term*unary|term/unary|unaryunary->+factor|-factorfactor->id|num|(expr)2.2.5Showthatallbinarystringsgeneratedbythefollowinggrammarhavevaluesdivisibleby3.Hint.Useinductiononthenumberofnodesinaparsetree.num->11|1001|num0|numnumDoesthegrammargenerateallbinarystringswithvaluesdivisibleby3?answerproveanystringderivedfromthegrammarcanbeconsideredtobeasequenceconsistingof11,1001and0,andnotprefixedwith0.thesumofthisstringis:sum=Σn(21+20)*2n+Σm(23+20)*2m=Σn3*2n+Σm9*2mItisobviouslycandivisibleby3.No.Considerstring"10101",itisdivisibleby3,butcannotderivedfromthegrammar.Question:anygeneralprove?2.2.6Constructacontext-freegrammarforromannumerals.Note:wejustconsiderasubsetofromannumeralswhichislessthan4k.answerwikipedia:Roman_numeralsviawikipedia,wecancategorizethesinglenomannumeralsinto4groups:I,II,III|IV|V,VI,VII,VIII|IXthengettheproduction:digit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|εandwecanfindasimplewaytomapromantoarabicnumerals.Forexample:XII=>X,II=>10+2=>12CXCIX=>C,XC,IX=>100+90+9=>199MDCCCLXXX=>M,DCCC,LXXX=>1000+800+80=>1880viatheuppertworules,wecanderivetheproduction:romanNum->thousandhundredtendigitthousand->M|MM|MMM|εhundred->smallHundred|CD|DsmallHundred|CMsmallHundred->C|CC|CCC|εten->smallTen|XL|LsmallTen|XCsmallTen->X|XX|XXX|εdigit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|ε2.3ExercisesforSection2.32.3.1Constructasyntax-directedtranslationschemethattrans­latesarithmeticexpressionsfrominfixnotationintoprefixnotationinwhichanoperatorappearsbeforeitsoperands;e.g.,-xyistheprefixnotationforx-y.Giveannotatedparsetreesfortheinputs9-5+2and9-5*2.。
answerproductions:expr->expr+term|expr-term|termterm->term*factor|term/factor|factorfactor->digit|(expr)translationschemes:expr->{print("+")}expr+term|{print("-")}expr-term|termterm->{print("*")}term*factor|{print("/")}term/factor|factorfactor->digit{print(digit)}|(expr)2.3.2Constructasyntax-directedtranslationschemethattrans­latesarithmeticexpressionsfrompostfixnotationintoinfixnotation.Giveannotatedparsetreesfortheinputs95-2*and952*-.answerproductions:expr->exprexpr+|exprexpr-|exprexpr*|exprexpr/|digittranslationschemes:expr->expr{print("+")}expr+|expr{print("-")}expr-|{print("(")}expr{print(")*(")}expr{print(")")}*|{print("(")}expr{print(")/(")}expr{print(")")}/|digit{print(digit)}AnotherreferenceanswerE->{print("(")}E{print(op)}E{print(")"}}op|digit{print(digit)}2.3.3Constructasyntax-directedtranslationschemethattrans­latesintegersintoromannumeralsanswerassistantfunction:repeat(sign,times)//repeat('a',2)='aa'translationschemes:num->thousandhundredtendigit{num.roman=thousand.roman||hundred.roman||ten.roman||digit.roman;print(num.roman)}thousand->low{thousand.roman=repeat('M',low.v)}hundred->low{hundred.roman=repeat('C',low.v)}|4{hundred.roman='CD'}|high{hundred.roman='D'||repeat('X',high.v-5)}|9{hundred.roman='CM'}ten->low{ten.roman=repeat('X',low.v)}|4{ten.roman='XL'}|high{ten.roman='L'||repeat('X',high.v-5)}|9{ten.roman='XC'}digit->low{digit.roman=repeat('I',low.v)}|4{digit.roman='IV'}|high{digit.roman='V'||repeat('I',high.v-5)}|9{digit.roman='IX'}low->0{low.v=0}|1{low.v=1}|2{low.v=2}|3{low.v=3}high->5{high.v=5}|6{high.v=6}|7{high.v=7}|8{high.v=8}2.3.4Constructasyntax-directedtranslationschemethattrans­latesromannumeralsintointegers.answerproductions:romanNum->thousandhundredtendigitthousand->M|MM|MMM|εhundred->smallHundred|CD|DsmallHundred|CMsmallHundred->C|CC|CCC|εten->smallTen|XL|LsmallTen|XCsmallTen->X|XX|XXX|εdigit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|εtranslationschemes:romanNum->thousandhundredtendigit{romanNum.v=thousand.v||hundred.v||ten.v||digit.v;print(romanNun.v)}thousand->M{thousand.v=1}|MM{thousand.v=2}|MMM{thousand.v=3}|ε{thousand.v=0}hundred->smallHundred{hundred.v=smallHundred.v}|CD{hundred.v=smallHundred.v}|DsmallHundred{hundred.v=5+smallHundred.v}|CM{hundred.v=9}smallHundred->C{smallHundred.v=1}|CC{smallHundred.v=2}|CCC{smallHundred.v=3}|ε{hundred.v=0}ten->smallTen{ten.v=smallTen.v}|XL{ten.v=4}|LsmallTen{ten.v=5+smallTen.v}|XC{ten.v=9}smallTen->X{smallTen.v=1}|XX{smallTen.v=2}|XXX{smallTen.v=3}|ε{smallTen.v=0}digit->smallDigit{digit.v=smallDigit.v}|IV{digit.v=4}|VsmallDigit{digit.v=5+smallDigit.v}|IX{digit.v=9}smallDigit->I{smallDigit.v=1}|II{smallDigit.v=2}|III{smallDigit.v=3}|ε{smallDigit.v=0}2.3.5Constructasyntax-directedtranslationschemethattrans­latespostfixarithmeticexpressionsintoequivalentprefixarithmeticexpressions.answerproduction:expr->exprexprop|digittranslationscheme:expr->{print(op)}exprexprop|digit{print(digit)}ExercisesforSection2.42.4.1Constructrecursive-descentparsers,startingwiththefollow­inggrammars:S->+SS|-SS|aS->S(S)S|εS->0S1|01Answer1)S->+SS|-SS|avoidS(){switch(lookahead){case"+":match("+");S();S();break;case"-":match("-");S();S();break;case"a":match("a");break;default:thrownewSyntaxException();}}voidmatch(Terminalt){if(lookahead=t){lookahead=nextTerminal();}else{thrownewSyntaxException()}}2)S->S(S)S|εvoidS(){if(lookahead=="("){S();match("(");S();match(")");S();}}3)S->0S1|01voidS(){switch(lookahead){case"0":match("0");S();match("1");break;case"1"://match(epsilon);break;default:thrownewSyntaxException();}}ExercisesforSection2.62.6.1ExtendthelexicalanalyzerinSection2.6.5toremovecom­ments,definedasfollows:Acommentbeginswith//andincludesallcharactersuntiltheendofthatline.Acommentbeginswith/*andincludesallcharactersthroughthenextoccurrenceofthecharactersequence*/.2.6.2ExtendthelexicalanalyzerinSection2.6.5torecognizetherelationaloperators.2.6.3ExtendthelexicalanalyzerinSection2.6.5torecognizefloat­ingpointnumberssuchas2.,3.14,and.5.AnswerSourcecode:commit8dd1a9aCodesnippet(src/lexer/Lexer.java):publicTokenscan()throwsIOException,SyntaxException{for(;;peek=(char)stream.read()){if(peek==''||peek=='\t'){continue;}elseif(peek=='\n'){line=line+1;}else{break;}}//handlecommentif(peek=='/'){peek=(char)stream.read();if(peek=='/'){//singlelinecommentfor(;;peek=(char)stream.read()){if(peek=='\n'){break;}}}elseif(peek=='*'){//blockcommentcharprevPeek='';for(;;prevPeek=peek,peek=(char)stream.read()){if(prevPeek=='*'&&peek=='/'){break;}}}else{thrownewSyntaxException();}}//handlerelationsignif("".indexOf(peek)>-1){StringBufferb=newStringBuffer();b.append(peek);peek=(char)stream.read();if(peek=='='){b.append(peek);}returnnewRel(b.toString());}//handlenumber,notypesensitiveif(Character.isDigit(peek)||peek=='.'){BooleanisDotExist=false;StringBufferb=newStringBuffer();do{if(peek=='.'){isDotExist=true;}b.append(peek);peek=(char)stream.read();}while(isDotExist==true?Character.isDigit(peek):Character.isDigit(peek)||peek=='.');returnnewNum(newFloat(b.toString()));}//handlewordif(Character.isLetter(peek)){StringBufferb=newStringBuffer();do{b.append(peek);peek=(char)stream.read();}while(Character.isLetterOrDigit(peek));Strings=b.toString();Wordw=words.get(s);if(w==null){w=newWord(Tag.ID,s);words.put(s,w);}returnw;}Tokent=newToken(peek);peek='';returnt;}ExercisesforSection2.82.8.1For-statementsinCandJavahavetheform:for(exprl;expr2;expr3)stmtThefirstexpressionisexecutedbeforetheloop;itistypicallyusedforinitializ­ingtheloopindex.Thesecondexpressionisatestmadebeforeeachiterationoftheloop;theloopisexitediftheexpressionbecomesO.Theloopitselfcanbethoughtofasthestatement{stmtexpr3;}.Thethirdexpressionisexecutedattheendofeachiteration;itistypicallyusedtoincrementtheloopindex.Themeaningofthefor-statementissimilartoexpr1;while(expr2){stmtexpr3;}DefineaclassForforfor-statements,similartoclassIfinFig.2.43.AnswerclassForextendsStmt{ExprE1;ExprE2;ExprE3;StmtS;publicFor(Exprexpr1,Exprexpr2,Exprexpr3,Stmtstmt){E1=expr1;E2=expr2;E3=expr3;S=stmt;}publicvoidgen(){E1.gen();Labelstart=newLable();Lalelend=newLable();emit("ifFalse"+E2.rvalue().toString()+"goto"+end);S.gen();E3.gen();emit("goto"+start);emit(end+":")}}2.8.2TheprogramminglanguageCdoesnothaveabooleantype.ShowhowaCcompilermighttranslateanif-statementintothree-addresscode.AnswerReplaceemit("isFalse"+E.rvalue().toString()+"goto"+after);withemit("ifNotEqual"+E.rvalue().toString()+"0goto"+after);oremit("isNotEqualZero"+E.rvalue().toString()+"goto"+after);
2025/11/27 8:37:48 658KB 龙书答案 完整性高
1
fs2-grpc-FS2/cats效果的gRPC实现SBT配置project/plugins.sbt:addSbtPlugin("org.lyranthe.fs2-grpc"%"sbt-java-gen"%"")build.sbt:enablePlugins(Fs2Grpc)协议缓冲文件protobuf文件应存储在/src/main/protobuf。
多个项目如果生成的代码被多个项目使用,则可以在其他项目所依赖的公共项目中构建客户端/服务器代码。
例如:lazyvalprotobuf=project.in(file("protobuf")).enablePlugins(Fs2Grpc)lazyvalclient=
2025/10/5 17:38:12 38KB Scala
1
用于lua下的protobuf转化工具,可以很方便的转化为*_pb.lua文件
2025/9/12 1:26:29 25KB protoc gen lua protobuf
1
个人学习Erlang的时候自己写的一个基于gen_tcp的聊天室,功能有注册,登陆,获得登陆时间,聊天次数,上次登陆时间等等,资源里有完整代码,注释也很详细.
2025/8/17 1:32:35 3KB 聊天室
1
图像对抗生成网络素描上色gen.h5
2025/6/26 11:44:47 207.73MB tensorflow
1
epg_gen:我的使用简单HTMLDOM的个人XMLTV(EPG)生成器
2025/6/12 21:09:58 4KB PHP
1
数据结构算法演示(Windows版)使用手册一、功能简介本课件是一个动态演示数据结构算法执行过程的辅助教学软件,它可适应读者对算法的输入数据和过程执行的控制方式的不同需求,在计算机的屏幕上显示算法执行过程中数据的逻辑结构或存储结构的变化状况或递归算法执行过程中栈的变化状况。
整个系统使用菜单驱动方式,每个菜单包括若干菜单项。
每个菜单项对应一个动作或一个子菜单。
系统一直处于选择菜单项或执行动作状态,直到选择了退出动作为止。
二、系统内容本系统内含84个算法,分属13部分内容,由主菜单显示,与《数据结构》教科书中自第2章至第11章中相对应。
各部分演示算法如下:1.顺序表(1)在顺序表中插入一个数据元素(ins_sqlist)(2)删除顺序表中一个数据元素(del_sqlist)(3)合并两个有序顺序表(merge_sqlist)2.链表(1)创建一个单链表(Crt_LinkList)(2)在单链表中插入一个结点(Ins_LinkList)(3)删除单链表中的一个结点(Del_LinkList)(4)两个有序链表求并(Union)(5)归并两个有序链表(MergeList_L)(6)两个有序链表求交(ListIntersection_L)(7)两个有序链表求差(SubList_L)3.栈和队列(1)计算阿克曼函数(AckMan)(2)栈的输出序列(Gen、Perform)(3)递归算法的演示汉诺塔的算法(Hanoi)解皇后问题的算法(Queen)解迷宫的算法(Maze)解背包问题的算法(Knap)(4)模拟银行(BankSimulation)(5)表达式求值(Exp_reduced)4.串的模式匹配(1)古典算法(Index_BF)(2)求Next函数值(Get_next)和按Next函数值进行匹配(Index_KMP(next))(3)求Next修正值(Get_nextval)和按Next修正值进行匹配(Index_KMP(nextval))5.稀疏矩阵(1)矩阵转置(Trans_Sparmat)(2)快速矩阵转置(Fast_Transpos)(3)矩阵乘法(Multiply_Sparmat)6.广义表(1)求广义表的深度(Ls_Depth)(2)复制广义表(Ls_Copy)(3)创建广义表的存储结构(Crt_Lists)7.二叉树(1)遍历二叉树二叉树的线索化先序遍历(Pre_order)中序遍历(In_order)后序遍历(Post_order)(2)按先序建二叉树(CrtBT_PreOdr)(3)线索二叉树二叉树的线索化生成先序线索(前驱或后继)(Pre_thre)中序线索(前驱或后继)(In_thre)后序线索(前驱或后继)(Post_thre)遍历中序线索二叉树(Inorder_thlinked)中序线索树的插入(ins_lchild_inthr)和删除(del_lchild_inthr)结点(4)建赫夫曼树和求赫夫曼编码(HuffmanCoding)(5)森林转化成二叉树(Forest2BT)(6)二叉树转化成森林(BT2Forest)(7)按表达式建树(ExpTree)并求值(CalExpTreeByPostOrderTrav)8.图(1)图的遍历深度优先搜索(Travel_DFS)广度优先搜索(Travel_BFS)(2)求有向图的强连通分量(Strong_comp)(3)有向无环图的两个算法拓扑排序(Toposort)关键路径(Critical_path)(4)求最小生成树普里姆算法(Prim)克鲁斯卡尔算法(Kruscal)(5)求关节点和重连通分量(Get_artical)(6)求最短路径弗洛伊德算法(shortpath_Floyd)迪杰斯特拉算法(shortpath_DIJ)9.存储管理(1)边界标识法(Boundary_tag_method)(2)伙伴系统(Buddy_system)(3)紧缩无用单元(Storage_compaction)10.静态查找(1)顺序查找(Search_Seq)(2)折半查找(Serch_Bin)(3)插值查找(Search_Ins)(4)斐波那契查找(Searc
2025/4/23 10:46:30 3.17MB 数据结构 演示 软件 c
1
可用平台很多,在macos下运行此软件
2025/3/30 9:35:17 19.2MB 黑苹果oc
1
TheoryandApplicationsofDigitalSpeechProcessing[2010]LawrenceR.RabinerRonaldW.Schafer英文文字版。
没有积分的同学可以从这里下。
http://gen.lib.rus.ec
2024/12/4 15:12:16 14.07MB Digital Spee
1
geetestjs无感反混淆,用抓包工具替换上即可。
记得启动方式为忽略跨域。
具体操作百度,抓包工具建议为Charles。


安装好本地证书,开启本地抓包即可。


1
共 21 条记录 首页 上一页 下一页 尾页
在日常工作中,钉钉打卡成了我生活中不可或缺的一部分。然而,有时候这个看似简单的任务却给我带来了不少烦恼。 每天早晚,我总是得牢记打开钉钉应用,点击"工作台",再找到"考勤打卡"进行签到。有时候因为工作忙碌,会忘记打卡,导致考勤异常,影响当月的工作评价。而且,由于我使用的是苹果手机,有时候系统更新后,钉钉的某些功能会出现异常,使得打卡变得更加麻烦。 另外,我的家人使用的是安卓手机,他们也经常抱怨钉钉打卡的繁琐。尤其是对于那些不太熟悉手机操作的长辈来说,每次打卡都是一次挑战。他们总是担心自己会操作失误,导致打卡失败。 为了解决这些烦恼,我开始思考是否可以通过编写一个全自动化脚本来实现钉钉打卡。经过一段时间的摸索和学习,我终于成功编写出了一个适用于苹果和安卓系统的钉钉打卡脚本。
2024-04-09 15:03 15KB 钉钉 钉钉打卡