Functions v0.1
This commit is contained in:
@@ -17,6 +17,7 @@ Syntax Exp:exp ::= id
|
||||
| exp '>' exp
|
||||
| exp '<=' exp
|
||||
| exp '<' exp
|
||||
| id '(' ')'
|
||||
| '(' exp ')'
|
||||
|
||||
Semantics eval-exp[[ _:exp ]] : => values
|
||||
@@ -36,6 +37,7 @@ 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-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[[ Id '(' ')' ]] = enact id[[ Id ]]
|
||||
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ Syntax Stmt: statement ::= '{' statement* '}'
|
||||
| type id ';'
|
||||
| type id '=' exp ';'
|
||||
| id '=' exp ';'
|
||||
| 'return' exp? ';'
|
||||
| 'fun' id '(' ')' '{' statement* '}'
|
||||
|
||||
Syntax Typ:type ::= 'int'
|
||||
| 'bool'
|
||||
@@ -20,6 +22,9 @@ Rule execute[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
|
||||
Rule execute[[ Typ Id ';' ]] = null
|
||||
Rule execute[[ Typ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||
Rule execute[[ 'return' Exp ';' ]] = return exal-exp[[ Exp ]]
|
||||
Rule execute[[ 'return' ';' ]] = return null
|
||||
Rule execute[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] = null
|
||||
|
||||
Rule execute[[ ]] = null
|
||||
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
||||
@@ -47,6 +52,11 @@ Rule collect-declared-vars[[ Typ Id ';' ]] =
|
||||
0 //TODO: use correct default value for type
|
||||
)
|
||||
)
|
||||
Rule collect-declared-vars[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] =
|
||||
bind(
|
||||
\"Id\",
|
||||
handle-return function abstraction execute[[ '{' Stmt* '}' ]]
|
||||
)
|
||||
Rule collect-declared-vars[[ ]] = map()
|
||||
Rule collect-declared-vars[[ Stmt ]] = map()
|
||||
Rule collect-declared-vars[[ Stmt1 Stmt2 Stmt* ]] = collect-declared-vars[[ Stmt1 ]], collect-declared-vars[[ Stmt2 ]], collect-declared-vars[[ Stmt* ]]
|
||||
|
||||
Reference in New Issue
Block a user