编译原理龙书答案完整性高第二章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

在Android应用开发中,集成百度地图API是一项常见的需求,它能为用户提供丰富的地图服务功能,如定位、导航、路线规划等。
本篇文章将详细介绍如何在Android项目中进行百度地图的开发,以及一些关键的技术点。
我们需要在百度地图开放平台(http://lbsyun.baidu.com/)注册账号并创建应用,获取API密钥。
这个API密钥是连接我们应用与百度地图服务的关键,确保了应用的合法性。
完成注册后,根据应用的包名和签名信息生成相应的密钥,并在项目中正确配置。
接下来,我们将在AndroidManifest.xml文件中添加必要的权限。
包括访问网络、读写外部存储、获取地理位置等,例如:```xml<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />```同时,添加百度地图SDK所需的库依赖:```xml<meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="你的API_KEY" />```然后,在布局文件中加入MapView组件,这是显示百度地图的核心组件:```xml<com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" />```在Activity或Fragment中初始化MapView,并设置地图的显示样式和级别:```javaMapView mapView = findViewById(R.id.bmapView);BaiduMap baiduMap = mapView.getMap();baiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); // 设置为普通地图baiduMap.setZoom(15); // 设置地图缩放级别```为了让应用能够获取用户的位置信息,我们需要开启定位服务:```javaLocationClient locationClient = new LocationClient(this);locationClient.registerListener(new MyLocationListener()); // 自定义监听器locationClient.start(); // 开启定位```编写`MyLocationListener`类,重写`onReceiveLocation`方法,接收定位结果:```javapublic class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { if (location != null) { // 使用获得的经纬度设置地图中心点 LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(myLocation); baiduMap.setMapStatus(update); } }}```为了给用户提供更丰富的地图交互体验,可以添加覆盖物(Overlay)、信息窗口(InfoWindow)等功能。
例如,自定义一个Marker来表示用户当前位置:```javaOverlayOptions markerOption = new MarkerOptions() .position(myLocation) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));baiduMap.addOverlay(markerOption);```此外,还可以通过百度地图API实现路线规划,比如驾车、步行、公交等。
调用`DrivingRoutePlanOption`、`WalkingRou
2025/6/15 22:19:09 5.65MB
1
全是代码用户登录注册先关程序代码注册页面//去空格String.prototype.Trim=function(){varm=this.match(/^\s*(\S+(\s+\S+)*)\s*$/);return(m==null)?"":m[1];}//验证手机号String.prototype.isMobile=function(){return(/^(?:13\d|15[189])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
2025/4/27 18:34:57 14KB Asp+access
1
此项目仅供学习使用1.安装前提:推荐Centos7系统,apache2.4+php5.5+mysql5.6+伪静态+定时计划任务2.创建站点创建一个网站和数据库,并导入数据库my1993mobi20190326.sql,修改数据库信息:1993.mobi/index.php3.修改域名:需要更改域名地方有四个地方,run.php、match.php、autojy.php、tokencover.phpindex.php这个文件修改数据库用户名密码链接4.定时计划任务:设置第三步修改php文件计划任务,每隔3分钟自动执行一次,执行成功根目录会生成txt文件。
5.伪静态:该网站伪静态请选择thinkphp。







2024/12/8 3:04:37 168.31MB PHP 数字货币 猫力币 区块链
1
PDF.JS源码修改,已经结合网上诸位大神给出的跨域解决方案,本版采用的是php版。
个人测试遇到网站上行速度跟不上,如果pdf比较大,比较尴尬,要等pdf完全加载才能打开,看上去很慢。
本版已经完美跨域,并汉化viewer.html及相关js。
去除语言包,只保留中文语言包以防出现bug。
如果想保留语言包,请把view.php,index.php复制到完整版的web目录下,并且在viewer.html下端紧挨《/body》上加入下列代码:[此处为script请自行修改,描述不允许html语言]varDEFAULT_URL='./view.php?pdf='+getQueryStringByName('pdf');functiongetQueryStringByName(name){varresult=location.search.match(newRegExp("[\?\&]"+name+"=([^\&]+)","i"));if(result==null||result.length<1){return"";}returnresult[1];}[此处为/script请自行修改,描述不允许html语言]此懒人包采用的是PDF.jsv1.9.426(build:2558a58d)本人属于业余爱好,纯属拼凑,如有疑问,请问度娘
2024/12/1 20:43:45 2.2MB pdf pdfjs pdf.js 跨域
1
要对文本文件的进行比较的时候,可以考虑使用google-diff-match-patch,它可以进行比较、匹配和生成补丁的操作google-diff-match-patch这个类库提供了强大的算法用于纯文本内容的差异比较,匹配,打补丁,实现同步纯文本所需要执行一些操作。
支持多种语言包括:Java、JavaScript、C++、C#、ObjectiveC、Lua和Python。
2024/9/13 14:51:27 304KB diff match 文本比较
1
gmapping是目前应用最广的2Dslam方法,利用RBPF方法,故需要了解粒子滤波算法。
scan-match方法在于估计机器人位置(pose),利用梯度下降的方法,在当前构建的地图,与当前的激光点,和机器人位置(pose)为初始估计值。
2024/7/30 11:03:46 477KB gmapping 激光雷达建图
1
本课程主要讲解PHP8.0新特性和新功能核心精选内容。
PHP8.0是PHP语言的一个主版本更新,它包含了很多新功能与优化项,包括命名参数、联合类型、注解、构造器属性提升、Match表达式、Nullsafe运算符、JIT,并改进了类型系统、错误处理、语法一致性。
课程配有大量代码实例,方便大家轻松学习。
1.21MB php8
1
SIFT源代码,C/C++代码,match为main函数
2024/3/14 20:43:10 55KB SIFT C/C++
1
function[PSNR,y_est]=BM3D(y,z,sigma,profile,print_to_screen,N2,N2_wiener,Ns,Ns_wiener,tau_match)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BM3DisanalgorithmforattenuationofadditivewhiteGaussiannoisefrom%grayscaleimages.Thisalgorithmreproducestheresultsfromthearticle:%%[1]K.Dabov,A.Foi,V.Katkovnik,andK.Egiazarian,"ImageDenoising%bySparse3DTransform-DomainCollaborativeFiltering,"%IEEETransactionsonImageProcessing,vol.16,no.8,August,2007.%preprintathttp://www.cs.tut.fi/~foi/GCF-BM3D.%%%FUNCTIONINTERFACE:%%[PSNR,y_est]=BM3D(y,z,sigma,profile,print_to_screen)%%!Thefunctioncanworkwithoutanyoftheinputarguments,%inwhichcase,theinternaldefaultonesareused!%%BASICUSAGEEXAMPLES:%%Case1)Usingthedefaultparameters(i.e.,imagename,sigma,etc.)%%[PSNR,y_est]=BM3D;%%Case2)Usinganexternalnoisyimage:
2023/12/29 9:31:37 2.76MB BM3D MATLAB
1
共 20 条记录 首页 上一页 下一页 尾页
在日常工作中,钉钉打卡成了我生活中不可或缺的一部分。然而,有时候这个看似简单的任务却给我带来了不少烦恼。 每天早晚,我总是得牢记打开钉钉应用,点击"工作台",再找到"考勤打卡"进行签到。有时候因为工作忙碌,会忘记打卡,导致考勤异常,影响当月的工作评价。而且,由于我使用的是苹果手机,有时候系统更新后,钉钉的某些功能会出现异常,使得打卡变得更加麻烦。 另外,我的家人使用的是安卓手机,他们也经常抱怨钉钉打卡的繁琐。尤其是对于那些不太熟悉手机操作的长辈来说,每次打卡都是一次挑战。他们总是担心自己会操作失误,导致打卡失败。 为了解决这些烦恼,我开始思考是否可以通过编写一个全自动化脚本来实现钉钉打卡。经过一段时间的摸索和学习,我终于成功编写出了一个适用于苹果和安卓系统的钉钉打卡脚本。
2024-04-09 15:03 15KB 钉钉 钉钉打卡