make blocks
This commit is contained in:
@@ -39,8 +39,8 @@ context-free syntax // Language
|
||||
// # Statements
|
||||
|
||||
|
||||
L-statement.L-statement--LBRACE-L-statement-S-RBRACE =
|
||||
"{" L-statement* "}"
|
||||
L-statement.L-statement--L-block =
|
||||
L-block
|
||||
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||
"print" "(" L-exp ")" ";"
|
||||
L-statement.L-statement--R-int-L-id-SEMI =
|
||||
@@ -51,8 +51,11 @@ context-free syntax // Language
|
||||
"int" L-id "=" L-exp ";"
|
||||
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
||||
"return" L-exp? ";"
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-LBRACE-L-statement-S-RBRACE =
|
||||
"fun" L-id "(" L-params ")" "{" L-statement* "}"
|
||||
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-L-block =
|
||||
"fun" L-id "(" L-params ")" L-block
|
||||
|
||||
L-block.L-block--LBRACE-L-statement-S-RBRACE =
|
||||
"{" L-statement* "}"
|
||||
|
||||
L-params.L-params--L-id-C-COMMA-L-params-D-Q =
|
||||
L-id L-COMMA-L-params?
|
||||
@@ -77,6 +80,8 @@ context-free syntax // Semantics
|
||||
|
||||
FCT.T-execute =
|
||||
"execute" "[:" L-statement* ":]"
|
||||
FCT.T-execute-block =
|
||||
"execute-block" "[:" L-block ":]"
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
@@ -113,7 +118,10 @@ variables // Meta-variables
|
||||
L-statement? = "(:Stmt" [1-9]? "?:)" {prefer}
|
||||
L-statement* = "(:Stmt" [1-9]? "*:)" {prefer}
|
||||
L-statement+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-block = "(:Block" [1-9]? ":)" {prefer}
|
||||
L-block? = "(:Block" [1-9]? "?:)" {prefer}
|
||||
L-block* = "(:Block" [1-9]? "*:)" {prefer}
|
||||
L-block+ = "(:Block" [1-9]? "+:)" {prefer}
|
||||
L-statement* = "..." [1-9]? {prefer}
|
||||
L-params = "(:Params" [1-9]? ":)" {prefer}
|
||||
L-params? = "(:Params" [1-9]? "?:)" {prefer}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -15,5 +15,5 @@ imports
|
||||
rules
|
||||
to-funcons:
|
||||
|[ start[: (:Stmt*:) :] ]| ->
|
||||
|[ initialise-binding execute[: {(:Stmt*:)} :] ]|
|
||||
|[ initialise-binding execute-block[: {(:Stmt*:)} :] ]|
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@ rules
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ execute[: {(:Stmt*:)} :] ]| ->
|
||||
|[ scope (collateral (collect-declared-vars[: (:Stmt*:) :]),
|
||||
execute[: (:Stmt*:) :]) ]|
|
||||
|[ execute[: (:Block:) :] ]| ->
|
||||
|[ execute-block[: (:Block:) :] ]|
|
||||
to-funcons:
|
||||
|[ execute[: print((:Exp:)); :] ]| ->
|
||||
|[ print eval-exp[: (:Exp:) :] ]|
|
||||
@@ -42,7 +41,7 @@ to-funcons:
|
||||
|[ execute[: return; :] ]| ->
|
||||
|[ return null ]|
|
||||
to-funcons:
|
||||
|[ execute[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
||||
|[ execute[: fun(:Id:)((:Params:))(:Block:) :] ]| ->
|
||||
|[ null ]|
|
||||
to-funcons:
|
||||
|[ execute[: :] ]| ->
|
||||
@@ -51,6 +50,10 @@ to-funcons:
|
||||
|[ execute[: (:Stmt:)(:Stmt+:) :] ]| ->
|
||||
|[ sequential (execute[: (:Stmt:) :],
|
||||
execute[: (:Stmt+:) :]) ]|
|
||||
to-funcons:
|
||||
|[ execute-block[: {(:Stmt*:)} :] ]| ->
|
||||
|[ scope (collateral (collect-declared-vars[: (:Stmt*:) :]),
|
||||
execute[: (:Stmt*:) :]) ]|
|
||||
|
||||
// # Handling parameter declarations
|
||||
|
||||
|
||||
@@ -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