add parameters to functions
This commit is contained in:
@@ -24,13 +24,17 @@ to-funcons:
|
||||
|[ execute[: print((:Exp:)); :] ]| ->
|
||||
|[ print eval-exp[: (:Exp:) :] ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Id:); :] ]| ->
|
||||
|[ execute[: int(:Id:); :] ]| ->
|
||||
|[ assign (bound id[: (:Id:) :],
|
||||
0) ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Id:)=(:Exp:); :] ]| ->
|
||||
|[ assign (bound id[: (:Id:) :],
|
||||
eval-exp[: (:Exp:) :]) ]|
|
||||
to-funcons:
|
||||
|[ execute[: int(:Id:)=(:Exp:); :] ]| ->
|
||||
|[ assign (bound id[: (:Id:) :],
|
||||
eval-exp[: (:Exp:) :]) ]|
|
||||
to-funcons:
|
||||
|[ execute[: return(:Exp:); :] ]| ->
|
||||
|[ return eval-exp[: (:Exp:) :] ]|
|
||||
@@ -38,7 +42,7 @@ to-funcons:
|
||||
|[ execute[: return; :] ]| ->
|
||||
|[ return null ]|
|
||||
to-funcons:
|
||||
|[ execute[: fun(:Id:)(){(:Stmt*:)} :] ]| ->
|
||||
|[ execute[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
||||
|[ null ]|
|
||||
to-funcons:
|
||||
|[ execute[: :] ]| ->
|
||||
@@ -48,21 +52,37 @@ to-funcons:
|
||||
|[ sequential (execute[: (:Stmt:) :],
|
||||
execute[: (:Stmt+:) :]) ]|
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ collect-params[: (:Id:) :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
allocate-initialised-variable (integers,
|
||||
checked head given)) ]|
|
||||
to-funcons:
|
||||
|[ collect-params[: (:Id:),(:Params:) :] ]| ->
|
||||
|[ collect-params[: (:Id:) :],
|
||||
give (checked tail given,
|
||||
collect-params[: (:Params:) :]) ]|
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: (:Id:)=(:Exp:); :] ]| ->
|
||||
|[ collect-declared-vars[: int(:Id:)=(:Exp:); :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
allocate-variable (integers)) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: (:Id:); :] ]| ->
|
||||
|[ collect-declared-vars[: int(:Id:); :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
allocate-variable (integers)) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: fun(:Id:)(){(:Stmt*:)} :] ]| ->
|
||||
|[ collect-declared-vars[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
||||
|[ bind (id[: (:Id:) :],
|
||||
function abstraction (execute[: {(:Stmt*:)} :])) ]|
|
||||
function abstraction (scope (collateral (collect-declared-vars[: (:Stmt*:) :],
|
||||
collect-params[: (:Params:) :]),
|
||||
execute[: (:Stmt*:) :]))) ]|
|
||||
to-funcons:
|
||||
|[ collect-declared-vars[: :] ]| ->
|
||||
|[ map () ]|
|
||||
|
||||
Reference in New Issue
Block a user