Functions v0.1
This commit is contained in:
@@ -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