control flow
This commit is contained in:
@@ -53,6 +53,16 @@ context-free syntax // Language
|
||||
"return" L-exp? ";"
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-L-block =
|
||||
"fun" L-id "(" L-params ")" L-block
|
||||
L-statement.L-statement--R-if-LPAREN-L-exp-RPAREN-L-block-C-R-else-L-block-D-Q =
|
||||
"if" "(" L-exp ")" L-block L-R-else-L-block?
|
||||
L-statement.L-statement--R-while-LPAREN-L-exp-RPAREN-L-block =
|
||||
"while" "(" L-exp ")" L-block
|
||||
L-statement.L-statement--R-for-LPAREN-R-int-L-id-EQUALS-L-exp-SEMI-L-exp-RPAREN-L-block =
|
||||
"for" "(" "int" L-id "=" L-exp ";" L-exp ")" L-block
|
||||
|
||||
L-R-else-L-block.L-R-else-L-block--R-else-L-block =
|
||||
"else" L-block
|
||||
|
||||
|
||||
L-block.L-block--LBRACE-L-statement-S-RBRACE =
|
||||
"{" L-statement* "}"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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:) :] ]|
|
||||
|
||||
@@ -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 ]|
|
||||
|
||||
Reference in New Issue
Block a user