control flow

This commit is contained in:
Peter
2024-01-15 08:30:03 +01:00
parent 1b4d8d622d
commit 613fa9ab1a
16 changed files with 400 additions and 23 deletions

View File

@@ -99,6 +99,9 @@ to-funcons-lex:
to-funcons:
|[ id[: (:Id:) :] ]| ->
|[ \"(:Id:)\" ]|
to-funcons:
|[ int-val[: 0 :] ]| ->
|[ 0 ]|
to-funcons:
|[ int-val[: (:Dec:) :] ]| ->
|[ dec-val[: (:Dec:) :] ]|

View File

@@ -43,6 +43,30 @@ to-funcons:
to-funcons:
|[ execute[: fun(:Id:)((:Params:))(:Block:) :] ]| ->
|[ null ]|
to-funcons:
|[ execute[: if((:Exp:))(:Block:) :] ]| ->
|[ if-else (eval-exp[: (:Exp:) :],
execute-block[: (:Block:) :],
null) ]|
to-funcons:
|[ execute[: if((:Exp:))(:Block1:)else(:Block2:) :] ]| ->
|[ if-else (eval-exp[: (:Exp:) :],
execute-block[: (:Block1:) :],
execute-block[: (:Block2:) :]) ]|
to-funcons:
|[ execute[: while((:Exp:))(:Block:) :] ]| ->
|[ while (eval-exp[: (:Exp:) :],
execute-block[: (:Block:) :]) ]|
to-funcons:
|[ execute[: for(int(:Id:)=(:Exp1:);(:Exp2:))(:Block:) :] ]| ->
|[ scope (bind (id[: (:Id:) :],
allocate-initialised-variable (integers,
eval-exp[: (:Exp1:) :])),
while (eval-exp[: (:Exp2:) :],
sequential (execute-block[: (:Block:) :],
assign (bound id[: (:Id:) :],
int-add (1,
assigned bound id[: (:Id:) :]))))) ]|
to-funcons:
|[ execute[: :] ]| ->
|[ null ]|