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.L-exp--L-exp-LESS-L-exp =
|
L-exp.L-exp--L-exp-LESS-L-exp =
|
||||||
L-exp "<" L-exp
|
L-exp "<" L-exp
|
||||||
L-exp.L-exp--L-id-LPAREN-RPAREN =
|
L-exp.L-exp--L-id-LPAREN-L-paramvalues-Q-RPAREN =
|
||||||
L-id "(" ")"
|
L-id "(" L-paramvalues? ")"
|
||||||
L-exp.L-exp--LPAREN-L-exp-RPAREN =
|
L-exp.L-exp--LPAREN-L-exp-RPAREN =
|
||||||
"(" L-exp ")"
|
"(" 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 =
|
L-id.LEX-id =
|
||||||
LEX-id
|
LEX-id
|
||||||
L-decimal.LEX-decimal =
|
L-decimal.LEX-decimal =
|
||||||
@@ -83,6 +90,8 @@ context-free syntax // Semantics
|
|||||||
|
|
||||||
FCT.T-eval-exp =
|
FCT.T-eval-exp =
|
||||||
"eval-exp" "[:" L-exp ":]"
|
"eval-exp" "[:" L-exp ":]"
|
||||||
|
FCT.T-eval-params =
|
||||||
|
"eval-params" "[:" L-paramvalues? ":]"
|
||||||
FCT-Quoted.L-id = L-id
|
FCT-Quoted.L-id = L-id
|
||||||
FCT.T-id =
|
FCT.T-id =
|
||||||
"id" "[:" L-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-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}
|
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
|
// # Handling variable declarations
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +26,10 @@ syntax // Language
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// # Handling parameter declarations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// # Handling variable declarations
|
// # Handling variable declarations
|
||||||
|
|
||||||
|
|
||||||
@@ -35,14 +43,27 @@ context-free syntax // Language
|
|||||||
"{" L-statement* "}"
|
"{" L-statement* "}"
|
||||||
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||||
"print" "(" L-exp ")" ";"
|
"print" "(" L-exp ")" ";"
|
||||||
L-statement.L-statement--L-id-SEMI =
|
L-statement.L-statement--R-int-L-id-SEMI =
|
||||||
L-id ";"
|
"int" L-id ";"
|
||||||
L-statement.L-statement--L-id-EQUALS-L-exp-SEMI =
|
L-statement.L-statement--L-id-EQUALS-L-exp-SEMI =
|
||||||
L-id "=" L-exp ";"
|
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 =
|
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
||||||
"return" L-exp? ";"
|
"return" L-exp? ";"
|
||||||
L-statement.L-statement--R-fun-L-id-LPAREN-RPAREN-LBRACE-L-statement-S-RBRACE =
|
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-LBRACE-L-statement-S-RBRACE =
|
||||||
"fun" L-id "(" ")" "{" L-statement* "}"
|
"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
|
// # Handling variable declarations
|
||||||
@@ -57,6 +78,12 @@ context-free syntax // Semantics
|
|||||||
FCT.T-execute =
|
FCT.T-execute =
|
||||||
"execute" "[:" L-statement* ":]"
|
"execute" "[:" L-statement* ":]"
|
||||||
|
|
||||||
|
// # Handling parameter declarations
|
||||||
|
|
||||||
|
|
||||||
|
FCT-SEQ.T-collect-params =
|
||||||
|
"collect-params" "[:" L-params ":]"
|
||||||
|
|
||||||
// # Handling variable declarations
|
// # Handling variable declarations
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +96,10 @@ context-free syntax // Desugaring
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// # Handling parameter declarations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// # Handling variable declarations
|
// # Handling variable declarations
|
||||||
|
|
||||||
|
|
||||||
@@ -84,6 +115,14 @@ variables // Meta-variables
|
|||||||
L-statement+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
L-statement+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
||||||
L-statement* = "..." [1-9]? {prefer}
|
L-statement* = "..." [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
|
// # Handling variable declarations
|
||||||
|
|
||||||
@@ -95,6 +134,10 @@ variables // Meta-variables
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// # Handling parameter declarations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// # Handling variable 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:) :],
|
|[ is-less (eval-exp[: (:Exp1:) :],
|
||||||
eval-exp[: (:Exp2:) :]) ]|
|
eval-exp[: (:Exp2:) :]) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ eval-exp[: (:Id:)() :] ]| ->
|
|[ eval-exp[: (:Id:)((:ParamValues?:)) :] ]| ->
|
||||||
|[ handle-return apply (bound id[: (:Id:) :],
|
|[ handle-return apply (bound id[: (:Id:) :],
|
||||||
null) ]|
|
eval-params[: (:ParamValues?:) :]) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ eval-exp[: ((:Exp:)) :] ]| ->
|
|[ eval-exp[: ((:Exp:)) :] ]| ->
|
||||||
|[ 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:
|
to-funcons-lex:
|
||||||
FCTDoubleQuoted(L-id(LEX-id(str))) ->
|
FCTDoubleQuoted(L-id(LEX-id(str))) ->
|
||||||
FCTString(<double-quote> str)
|
FCTString(<double-quote> str)
|
||||||
|
|||||||
@@ -24,13 +24,17 @@ to-funcons:
|
|||||||
|[ execute[: print((:Exp:)); :] ]| ->
|
|[ execute[: print((:Exp:)); :] ]| ->
|
||||||
|[ print eval-exp[: (:Exp:) :] ]|
|
|[ print eval-exp[: (:Exp:) :] ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: (:Id:); :] ]| ->
|
|[ execute[: int(:Id:); :] ]| ->
|
||||||
|[ assign (bound id[: (:Id:) :],
|
|[ assign (bound id[: (:Id:) :],
|
||||||
0) ]|
|
0) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: (:Id:)=(:Exp:); :] ]| ->
|
|[ execute[: (:Id:)=(:Exp:); :] ]| ->
|
||||||
|[ assign (bound id[: (:Id:) :],
|
|[ assign (bound id[: (:Id:) :],
|
||||||
eval-exp[: (:Exp:) :]) ]|
|
eval-exp[: (:Exp:) :]) ]|
|
||||||
|
to-funcons:
|
||||||
|
|[ execute[: int(:Id:)=(:Exp:); :] ]| ->
|
||||||
|
|[ assign (bound id[: (:Id:) :],
|
||||||
|
eval-exp[: (:Exp:) :]) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: return(:Exp:); :] ]| ->
|
|[ execute[: return(:Exp:); :] ]| ->
|
||||||
|[ return eval-exp[: (:Exp:) :] ]|
|
|[ return eval-exp[: (:Exp:) :] ]|
|
||||||
@@ -38,7 +42,7 @@ to-funcons:
|
|||||||
|[ execute[: return; :] ]| ->
|
|[ execute[: return; :] ]| ->
|
||||||
|[ return null ]|
|
|[ return null ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: fun(:Id:)(){(:Stmt*:)} :] ]| ->
|
|[ execute[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
||||||
|[ null ]|
|
|[ null ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: :] ]| ->
|
|[ execute[: :] ]| ->
|
||||||
@@ -48,21 +52,37 @@ to-funcons:
|
|||||||
|[ sequential (execute[: (:Stmt:) :],
|
|[ sequential (execute[: (:Stmt:) :],
|
||||||
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
|
// # Handling variable declarations
|
||||||
|
|
||||||
|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ collect-declared-vars[: (:Id:)=(:Exp:); :] ]| ->
|
|[ collect-declared-vars[: int(:Id:)=(:Exp:); :] ]| ->
|
||||||
|[ bind (id[: (:Id:) :],
|
|[ bind (id[: (:Id:) :],
|
||||||
allocate-variable (integers)) ]|
|
allocate-variable (integers)) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ collect-declared-vars[: (:Id:); :] ]| ->
|
|[ collect-declared-vars[: int(:Id:); :] ]| ->
|
||||||
|[ bind (id[: (:Id:) :],
|
|[ bind (id[: (:Id:) :],
|
||||||
allocate-variable (integers)) ]|
|
allocate-variable (integers)) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ collect-declared-vars[: fun(:Id:)(){(:Stmt*:)} :] ]| ->
|
|[ collect-declared-vars[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
||||||
|[ bind (id[: (:Id:) :],
|
|[ bind (id[: (:Id:) :],
|
||||||
function abstraction (execute[: {(:Stmt*:)} :])) ]|
|
function abstraction (scope (collateral (collect-declared-vars[: (:Stmt*:) :],
|
||||||
|
collect-params[: (:Params:) :]),
|
||||||
|
execute[: (:Stmt*:) :]))) ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ collect-declared-vars[: :] ]| ->
|
|[ collect-declared-vars[: :] ]| ->
|
||||||
|[ map () ]|
|
|[ map () ]|
|
||||||
|
|||||||
@@ -1,28 +1,65 @@
|
|||||||
initialise-binding scope
|
initialise-binding scope
|
||||||
(collateral
|
(collateral
|
||||||
(bind
|
(bind
|
||||||
|
("a",
|
||||||
|
allocate-variable
|
||||||
|
(integers)),
|
||||||
|
bind
|
||||||
("test",
|
("test",
|
||||||
function abstraction
|
function abstraction
|
||||||
(scope
|
(scope
|
||||||
(collateral
|
(collateral
|
||||||
(map
|
(map
|
||||||
( )),
|
( ),
|
||||||
return decimal-natural
|
bind
|
||||||
("3")))),
|
("a",
|
||||||
|
allocate-initialised-variable
|
||||||
|
(integers,
|
||||||
|
checked head
|
||||||
|
given)),
|
||||||
|
give
|
||||||
|
(checked tail
|
||||||
|
given,
|
||||||
|
bind
|
||||||
|
("b",
|
||||||
|
allocate-initialised-variable
|
||||||
|
(integers,
|
||||||
|
checked head
|
||||||
|
given)))),
|
||||||
|
return int-mul
|
||||||
|
(assigned
|
||||||
|
(bound
|
||||||
|
("a")),
|
||||||
|
assigned
|
||||||
|
(bound
|
||||||
|
("b")))))),
|
||||||
bind
|
bind
|
||||||
("x",
|
("b",
|
||||||
allocate-initialised-variable
|
allocate-variable
|
||||||
(integers,
|
(integers)),
|
||||||
0)),
|
map
|
||||||
|
( ),
|
||||||
map
|
map
|
||||||
( )),
|
( )),
|
||||||
sequential
|
sequential
|
||||||
(null,
|
(assign
|
||||||
|
(bound "a",
|
||||||
|
decimal-natural
|
||||||
|
("20")),
|
||||||
|
null,
|
||||||
assign
|
assign
|
||||||
(bound "x",
|
(bound "b",
|
||||||
handle-return apply
|
handle-return apply
|
||||||
(bound "test",
|
(bound "test",
|
||||||
null)),
|
cons
|
||||||
|
(decimal-natural
|
||||||
|
("6"),
|
||||||
|
list
|
||||||
|
(decimal-natural
|
||||||
|
("3"))))),
|
||||||
print assigned
|
print assigned
|
||||||
(bound
|
(bound
|
||||||
("x"))))
|
("a")),
|
||||||
|
print assigned
|
||||||
|
(bound
|
||||||
|
("b"))))
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
int a =20;
|
||||||
|
|
||||||
|
fun test(a, b) {
|
||||||
fun test() {
|
return a*b;
|
||||||
return 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x = test();
|
int b =test(6, 3);
|
||||||
|
|
||||||
print(x);
|
|
||||||
|
print(a);
|
||||||
|
print(b);
|
||||||
@@ -17,9 +17,11 @@ Syntax Exp:exp ::= id
|
|||||||
| exp '>' exp
|
| exp '>' exp
|
||||||
| exp '<=' exp
|
| exp '<=' exp
|
||||||
| exp '<' exp
|
| exp '<' exp
|
||||||
| id '(' ')'
|
| id '(' paramvalues? ')'
|
||||||
| '(' exp ')'
|
| '(' exp ')'
|
||||||
|
|
||||||
|
Syntax ParamValues: paramvalues ::= exp (',' paramvalues)?
|
||||||
|
|
||||||
Semantics eval-exp[[ _:exp ]] : => values
|
Semantics eval-exp[[ _:exp ]] : => values
|
||||||
Rule eval-exp[[ Id ]] = assigned(bound(id[[ Id ]]))
|
Rule eval-exp[[ Id ]] = assigned(bound(id[[ Id ]]))
|
||||||
Rule eval-exp[[ Int ]] = int-val[[ Int ]]
|
Rule eval-exp[[ Int ]] = int-val[[ Int ]]
|
||||||
@@ -37,9 +39,13 @@ Rule eval-exp[[ Exp1 '>=' Exp2 ]] = is-greater-or-equal(eval-exp[[ Exp1 ]], eval
|
|||||||
Rule eval-exp[[ Exp1 '>' Exp2 ]] = is-greater(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
Rule eval-exp[[ Exp1 '>' Exp2 ]] = is-greater(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||||
Rule eval-exp[[ Exp1 '<=' Exp2 ]] = is-less-or-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
Rule eval-exp[[ Exp1 '<=' Exp2 ]] = is-less-or-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||||
Rule eval-exp[[ Exp1 '<' Exp2 ]] = is-less(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
Rule eval-exp[[ Exp1 '<' Exp2 ]] = is-less(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||||
Rule eval-exp[[ Id '(' ')' ]] = handle-return apply(bound id[[ Id ]], null)
|
Rule eval-exp[[ Id '(' ParamValues? ')' ]] = handle-return apply(bound id[[ Id ]], eval-params[[ ParamValues? ]])
|
||||||
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
||||||
|
|
||||||
|
Semantics eval-params[[ _:paramvalues? ]] : lists(values)
|
||||||
|
Rule eval-params[[ ]] = []
|
||||||
|
Rule eval-params[[ Exp ]] = list(eval-exp[[ Exp ]])
|
||||||
|
Rule eval-params[[ Exp ',' ParamValues ]] = cons(eval-exp[[ Exp ]], eval-params[[ ParamValues ]])
|
||||||
|
|
||||||
|
|
||||||
Lexis Id:id ::= ('a'-'z' | 'A'-'Z') ('a'-'z' | 'A'-'Z' | '0'-'9')*
|
Lexis Id:id ::= ('a'-'z' | 'A'-'Z') ('a'-'z' | 'A'-'Z' | '0'-'9')*
|
||||||
|
|||||||
@@ -4,20 +4,24 @@ Language "IBAFlang"
|
|||||||
|
|
||||||
Syntax Stmt: statement ::= '{' statement* '}'
|
Syntax Stmt: statement ::= '{' statement* '}'
|
||||||
| 'print' '(' exp ')' ';'
|
| 'print' '(' exp ')' ';'
|
||||||
| id ';'
|
| 'int' id ';'
|
||||||
| id '=' exp ';'
|
| id '=' exp ';'
|
||||||
|
| 'int' id '=' exp ';'
|
||||||
| 'return' exp? ';'
|
| 'return' exp? ';'
|
||||||
| 'fun' id '(' ')' '{' statement* '}'
|
| 'fun' id '(' params ')' '{' statement* '}'
|
||||||
|
|
||||||
|
Syntax Params: params ::= id (',' params)?
|
||||||
|
|
||||||
Semantics execute[[ Stmt*:statement* ]] : => null-type
|
Semantics execute[[ Stmt*:statement* ]] : => null-type
|
||||||
|
|
||||||
Rule execute[[ '{' Stmt* '}' ]] = scope(collateral(collect-declared-vars[[ Stmt* ]]), execute[[ Stmt* ]])
|
Rule execute[[ '{' Stmt* '}' ]] = scope(collateral(collect-declared-vars[[ Stmt* ]]), execute[[ Stmt* ]])
|
||||||
Rule execute[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
|
Rule execute[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
|
||||||
Rule execute[[ Id ';' ]] = assign(bound id[[ Id ]], 0)
|
Rule execute[[ 'int' Id ';' ]] = assign(bound id[[ Id ]], 0)
|
||||||
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||||
|
Rule execute[[ 'int' Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||||
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
||||||
Rule execute[[ 'return' ';' ]] = return null
|
Rule execute[[ 'return' ';' ]] = return null
|
||||||
Rule execute[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] = null
|
Rule execute[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = null
|
||||||
|
|
||||||
Rule execute[[ ]] = null
|
Rule execute[[ ]] = null
|
||||||
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
||||||
@@ -25,18 +29,32 @@ Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Handling parameter declarations
|
||||||
|
|
||||||
|
Semantics collect-params[[ Params:params ]] : (=>environments)+
|
||||||
|
Rule collect-params[[ Id ]] = bind(
|
||||||
|
id[[ Id ]],
|
||||||
|
allocate-initialised-variable(integers, checked head given)
|
||||||
|
)
|
||||||
|
Rule collect-params[[ Id ',' Params ]] = collect-params[[ Id ]], give(checked tail given, collect-params[[ Params ]])
|
||||||
|
|
||||||
# Handling variable declarations
|
# Handling variable declarations
|
||||||
|
|
||||||
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
|
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
|
||||||
|
|
||||||
Rule collect-declared-vars[[ Id '=' Exp ';' ]] = bind(id[[ Id ]],
|
Rule collect-declared-vars[[ 'int' Id '=' Exp ';' ]] = bind(id[[ Id ]],
|
||||||
allocate-variable(integers)
|
allocate-variable(integers)
|
||||||
)
|
)
|
||||||
Rule collect-declared-vars[[ Id ';' ]] = bind(id[[ Id ]],
|
Rule collect-declared-vars[[ 'int' Id ';' ]] = bind(id[[ Id ]],
|
||||||
allocate-variable(integers)
|
allocate-variable(integers)
|
||||||
)
|
)
|
||||||
Rule collect-declared-vars[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] = bind(id[[ Id ]],
|
Rule 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* ]]
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
Rule collect-declared-vars[[ ]] = map()
|
Rule collect-declared-vars[[ ]] = map()
|
||||||
Rule collect-declared-vars[[ Stmt ]] = map()
|
Rule collect-declared-vars[[ Stmt ]] = map()
|
||||||
|
|||||||
Reference in New Issue
Block a user