add parameters to functions

This commit is contained in:
Peter
2023-12-13 15:27:55 +01:00
parent c4f9bbcbfa
commit c7bf88c33a
9 changed files with 190 additions and 41 deletions

View File

@@ -77,12 +77,22 @@ to-funcons:
|[ is-less (eval-exp[: (:Exp1:) :],
eval-exp[: (:Exp2:) :]) ]|
to-funcons:
|[ eval-exp[: (:Id:)() :] ]| ->
|[ eval-exp[: (:Id:)((:ParamValues?:)) :] ]| ->
|[ handle-return apply (bound id[: (:Id:) :],
null) ]|
eval-params[: (:ParamValues?:) :]) ]|
to-funcons:
|[ eval-exp[: ((:Exp:)) :] ]| ->
|[ eval-exp[: (:Exp:) :] ]|
to-funcons:
|[ eval-params[: :] ]| ->
|[ [] ]|
to-funcons:
|[ eval-params[: (:Exp:) :] ]| ->
|[ list (eval-exp[: (:Exp:) :]) ]|
to-funcons:
|[ eval-params[: (:Exp:),(:ParamValues:) :] ]| ->
|[ cons (eval-exp[: (:Exp:) :],
eval-params[: (:ParamValues:) :]) ]|
to-funcons-lex:
FCTDoubleQuoted(L-id(LEX-id(str))) ->
FCTString(<double-quote> str)

View File

@@ -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 () ]|