讲解:Github、Java、JavaMatlab|R

Assessed Exercise 2, Task 3Implement codegenTask3 for the whole language.PROG → DEC | DEC; PROGDEC → def ID (VARDEC) = EVARDEC → ε | VARDECNEVARDECNE → ID | VARDECNE, IDID → ... (identifiers)INT → ... (Integers)E → INT | ID | if E COMP E then E else E endif | (E BINOP E) | (E) | skip | (E; E) | while E COMP E do E endwhile | repeat E until E COMP E endrepeat | ID := E | ID(ARGS) | break | continueARGS → ε | ARGSNEARGSNE → E | ARGSNE, ECOMP → == | | =BINOP → + | - | * | /Recall that the relevant definitions are here, here and here (and in the Zip file / Github given on theparent page). If you dont want to implement a feature, simply throw CodegenException whenthe code generator encounters this feature.This task is more difficult than the previous two in the sense that we have not discussed how toimplement division, break and continue in the lectures. The actual changes to the codegenerator are small and simple. Note that / is integer division, i.e. remainders are ignored (e.g.17/5 = 3).Meaning of break and continue. The commands break and continue work just as theeponymous statements do in Java, see e.g. here in their unlabelled versions). They always occurwithin a while o代写Github留学生作业、代做Java程序语言作业、代写Java实验作业 调试Matlab程序|帮做R语言编程r repeat loop. This is checked by semantic analysis. You can assume that thetest suite will only contain correct uses of break and continue.When inside a loop, break will immediately break out of the innermost containing loop andexecute the command following that innermost loop. For example consider the followingdeclaration.def f ( x ) = ( while x > 0 do if x > 500 then break else x := (x-1) endif endwhile; x )With this definition, f ( 1000 ) will return 1000, while f ( 432 ) will return 0. Relatedly, theouter loop inwhile x > 0 do ( repeat ( break; x := (x+1) ) until x > 0 endrepeat; x := (x-1) )endwhilewill be executed exactly x times (assuming x ≥ 0).When inside a loop, continue will immediately abandon the current round of the innermostcontaining loop and go to checking the condition. So the following loop never terminates wheneverx ≥ 0.repeat ( continue; x = ( x - 1 ) )until x Both, break and continue, can leave anything in the accumulator.Important side-condition. The grammar allows us to have expressions like 1 + break. You donot have to cater for this. All uses of break and continue will be normal, subject to therestrictions break and continue must meet in Java.转自:http://www.6daixie.com/contents/9/4674.html

你可能感兴趣的:(讲解:Github、Java、JavaMatlab|R)