Assessed Exercise 2, Task 3 |
Implement PROG → DEC | DEC; PROG DEC → def ID (VARDEC) = E VARDEC → ε | VARDECNE VARDECNE → ID | VARDECNE, ID ID → ... (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 | continue ARGS → ε | ARGSNE ARGSNE → E | ARGSNE, E COMP → == | < | > | <= | >= BINOP → + | - | * | / Recall that the relevant definitions are
here, here
and here (and in the Zip file /
Github given on the parent page).
If you don't want to implement a feature, simply throw
This task is more difficult than the previous two in the sense that we
have not discussed how to implement division, Meaning of When inside a loop, def f ( x ) = ( while x > 0 do if x > 500 then break else x := (x-1) endif endwhile; x )
With this definition, while x > 0 do ( repeat ( break; x := (x+1) ) until x > 0 endrepeat; x := (x-1) ) endwhile will be executed exactly x times (assuming x ≥ 0). When inside a
loop, repeat ( continue; x = ( x - 1 ) ) until x < 0 endrepeat
Both, Important side-condition.
The grammar allows us to have expressions like |