add parameters to functions
This commit is contained in:
@@ -66,11 +66,18 @@ context-free syntax // Language
|
||||
L-exp "<=" L-exp
|
||||
L-exp.L-exp--L-exp-LESS-L-exp =
|
||||
L-exp "<" L-exp
|
||||
L-exp.L-exp--L-id-LPAREN-RPAREN =
|
||||
L-id "(" ")"
|
||||
L-exp.L-exp--L-id-LPAREN-L-paramvalues-Q-RPAREN =
|
||||
L-id "(" L-paramvalues? ")"
|
||||
L-exp.L-exp--LPAREN-L-exp-RPAREN =
|
||||
"(" L-exp ")"
|
||||
|
||||
L-paramvalues.L-paramvalues--L-exp-C-COMMA-L-paramvalues-D-Q =
|
||||
L-exp L-COMMA-L-paramvalues?
|
||||
|
||||
L-COMMA-L-paramvalues.L-COMMA-L-paramvalues--COMMA-L-paramvalues =
|
||||
"," L-paramvalues
|
||||
|
||||
|
||||
L-id.LEX-id =
|
||||
LEX-id
|
||||
L-decimal.LEX-decimal =
|
||||
@@ -83,6 +90,8 @@ context-free syntax // Semantics
|
||||
|
||||
FCT.T-eval-exp =
|
||||
"eval-exp" "[:" L-exp ":]"
|
||||
FCT.T-eval-params =
|
||||
"eval-params" "[:" L-paramvalues? ":]"
|
||||
FCT-Quoted.L-id = L-id
|
||||
FCT.T-id =
|
||||
"id" "[:" L-id ":]"
|
||||
@@ -107,6 +116,10 @@ variables // Meta-variables
|
||||
L-exp? = "(:Exp" [1-9]? "?:)" {prefer}
|
||||
L-exp* = "(:Exp" [1-9]? "*:)" {prefer}
|
||||
L-exp+ = "(:Exp" [1-9]? "+:)" {prefer}
|
||||
L-paramvalues = "(:ParamValues" [1-9]? ":)" {prefer}
|
||||
L-paramvalues? = "(:ParamValues" [1-9]? "?:)" {prefer}
|
||||
L-paramvalues* = "(:ParamValues" [1-9]? "*:)" {prefer}
|
||||
L-paramvalues+ = "(:ParamValues" [1-9]? "+:)" {prefer}
|
||||
L-id = "(:Id" [1-9]? ":)" {prefer}
|
||||
L-id? = "(:Id" [1-9]? "?:)" {prefer}
|
||||
L-id* = "(:Id" [1-9]? "*:)" {prefer}
|
||||
|
||||
@@ -12,6 +12,10 @@ lexical syntax // Language
|
||||
|
||||
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
@@ -22,6 +26,10 @@ syntax // Language
|
||||
|
||||
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
@@ -35,14 +43,27 @@ context-free syntax // Language
|
||||
"{" L-statement* "}"
|
||||
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||
"print" "(" L-exp ")" ";"
|
||||
L-statement.L-statement--L-id-SEMI =
|
||||
L-id ";"
|
||||
L-statement.L-statement--R-int-L-id-SEMI =
|
||||
"int" L-id ";"
|
||||
L-statement.L-statement--L-id-EQUALS-L-exp-SEMI =
|
||||
L-id "=" L-exp ";"
|
||||
L-statement.L-statement--R-int-L-id-EQUALS-L-exp-SEMI =
|
||||
"int" L-id "=" L-exp ";"
|
||||
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
||||
"return" L-exp? ";"
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-RPAREN-LBRACE-L-statement-S-RBRACE =
|
||||
"fun" L-id "(" ")" "{" L-statement* "}"
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-LBRACE-L-statement-S-RBRACE =
|
||||
"fun" L-id "(" L-params ")" "{" L-statement* "}"
|
||||
|
||||
L-params.L-params--L-id-C-COMMA-L-params-D-Q =
|
||||
L-id L-COMMA-L-params?
|
||||
|
||||
L-COMMA-L-params.L-COMMA-L-params--COMMA-L-params =
|
||||
"," L-params
|
||||
|
||||
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
@@ -57,6 +78,12 @@ context-free syntax // Semantics
|
||||
FCT.T-execute =
|
||||
"execute" "[:" L-statement* ":]"
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
FCT-SEQ.T-collect-params =
|
||||
"collect-params" "[:" L-params ":]"
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
@@ -69,6 +96,10 @@ context-free syntax // Desugaring
|
||||
|
||||
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
@@ -84,6 +115,14 @@ variables // Meta-variables
|
||||
L-statement+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-params = "(:Params" [1-9]? ":)" {prefer}
|
||||
L-params? = "(:Params" [1-9]? "?:)" {prefer}
|
||||
L-params* = "(:Params" [1-9]? "*:)" {prefer}
|
||||
L-params+ = "(:Params" [1-9]? "+:)" {prefer}
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
@@ -95,6 +134,10 @@ variables // Meta-variables
|
||||
|
||||
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
|
||||
// # Handling variable declarations
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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)
|
||||
|
||||
@@ -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