Implement basic functions (no parameters yet)

This commit is contained in:
Peter
2023-12-10 16:29:29 +01:00
parent f594027de5
commit 165be5cfdb
12 changed files with 150 additions and 6 deletions

View File

@@ -37,7 +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[[ Id '(' ')' ]] = handle-return apply(bound id[[ Id ]], null)
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]

View File

@@ -0,0 +1,31 @@
//Syntax
//MD:
// method-declaration ::=
// 'public' type identifier '(' formal-list? ')' '{'
// var-declaration*
// statement*
// 'return' expression ';'
// '}'
//
//Type
// methods
// ~> functions(tuples(references(objects), minijava-values*), minijava-values)
//
//Semantics
// declare-methods[[MD*:method-declaration*]] : => envs
//Rule
// declare-methods[['public' T ID '(' FL? ')' '{' VD* S* 'return' E ';' '}']] =
// { id[[ID]] |->
// function closure scope (
// collateral ( // variables not allowed to shadow visible fields
// match ( given,
// tuple (
// pattern abstraction { "this" |-> allocate-initialised-variable ( pointers(objects), given ) },
// bind-formals[[FL?]]
// )
// ),
// object-single-inheritance-feature-map checked dereference first tuple-elements given,
// declare-variables[[VD*]] ),
//
// sequential ( execute[[S*]], evaluate[[E]] ) ) }

View File

@@ -17,12 +17,12 @@ Syntax Typ:type ::= 'int'
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[[ 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' Exp ';' ]] = return eval-exp[[ Exp ]]
Rule execute[[ 'return' ';' ]] = return null
Rule execute[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] = null
@@ -55,7 +55,7 @@ Rule collect-declared-vars[[ Typ Id ';' ]] =
Rule collect-declared-vars[[ 'fun' Id '(' ')' '{' Stmt* '}' ]] =
bind(
\"Id\",
handle-return function abstraction execute[[ '{' Stmt* '}' ]]
function abstraction(execute[[ '{' Stmt* '}' ]])
)
Rule collect-declared-vars[[ ]] = map()
Rule collect-declared-vars[[ Stmt ]] = map()