make blocks
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
//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]] ) ) }
|
||||
|
||||
@@ -2,7 +2,7 @@ Language "IBAFlang"
|
||||
|
||||
Syntax START:start ::= statement*
|
||||
Semantics start[[ _:start ]] : =>null-type
|
||||
Rule start[[ Stmt* ]] = initialise-binding execute[[ '{' Stmt* '}' ]]
|
||||
Rule start[[ Stmt* ]] = initialise-binding execute-block[[ '{' Stmt* '}' ]]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,30 +2,34 @@ Language "IBAFlang"
|
||||
|
||||
# Statements
|
||||
|
||||
Syntax Stmt: statement ::= '{' statement* '}'
|
||||
| 'print' '(' exp ')' ';'
|
||||
| 'int' id ';'
|
||||
| id '=' exp ';'
|
||||
| 'int' id '=' exp ';'
|
||||
| 'return' exp? ';'
|
||||
| 'fun' id '(' params ')' '{' statement* '}'
|
||||
Syntax Stmt: statement ::= block
|
||||
| 'print' '(' exp ')' ';'
|
||||
| 'int' id ';'
|
||||
| id '=' exp ';'
|
||||
| 'int' id '=' exp ';'
|
||||
| 'return' exp? ';'
|
||||
| 'fun' id '(' params ')' block
|
||||
|
||||
Syntax Block: block ::= '{' statement* '}'
|
||||
|
||||
Syntax Params: params ::= id (',' params)?
|
||||
|
||||
Semantics execute[[ Stmt*:statement* ]] : => null-type
|
||||
|
||||
Rule execute[[ '{' Stmt* '}' ]] = scope(collateral(collect-declared-vars[[ Stmt* ]]), execute[[ Stmt* ]])
|
||||
Rule execute[[ Block ]] = execute-block[[ Block ]]
|
||||
Rule execute[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
|
||||
Rule execute[[ 'int' Id ';' ]] = assign(bound id[[ Id ]], 0)
|
||||
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' ';' ]] = return null
|
||||
Rule execute[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = null
|
||||
Rule execute[[ 'fun' Id '(' Params ')' Block ]] = null
|
||||
|
||||
Rule execute[[ ]] = null
|
||||
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
||||
|
||||
Semantics execute-block[[ _:block ]] : => null-type
|
||||
Rule execute-block[[ '{' Stmt* '}' ]] = scope(collateral(collect-declared-vars[[ Stmt* ]]), execute[[ Stmt* ]])
|
||||
|
||||
|
||||
|
||||
@@ -42,12 +46,8 @@ Rule collect-params[[ Id ',' Params ]] = collect-params[[ Id ]], give(checked ta
|
||||
|
||||
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
|
||||
|
||||
Rule collect-declared-vars[[ 'int' Id '=' Exp ';' ]] = bind(id[[ Id ]],
|
||||
allocate-variable(integers)
|
||||
)
|
||||
Rule collect-declared-vars[[ 'int' Id ';' ]] = bind(id[[ Id ]],
|
||||
allocate-variable(integers)
|
||||
)
|
||||
Rule collect-declared-vars[[ 'int' Id '=' Exp ';' ]] = bind(id[[ Id ]], allocate-variable(integers))
|
||||
Rule collect-declared-vars[[ 'int' Id ';' ]] = bind(id[[ Id ]], allocate-variable(integers))
|
||||
Rule collect-declared-vars[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = bind(id[[ Id ]],
|
||||
function abstraction(
|
||||
scope(
|
||||
|
||||
Reference in New Issue
Block a user