7.6.分支
\(7.6.\)Branching
1.Branching implementation
Take the following program as example:
1 | //return x * y |
This program can be translated into pseudo VM code as below:
1 | function mult(x,y) |
Notice that we have three new symbols: label
,
if-goto
, goto
:
label LABEL
declare the label.if-goto LABEL
: if the statement is true, then jump toLABEL
.goto LABEL
: jump toLABEL
with no condition.
With these three statement, we can translate the branching expression into VM code.