make blocks
This commit is contained in:
@@ -39,8 +39,8 @@ context-free syntax // Language
|
|||||||
// # Statements
|
// # Statements
|
||||||
|
|
||||||
|
|
||||||
L-statement.L-statement--LBRACE-L-statement-S-RBRACE =
|
L-statement.L-statement--L-block =
|
||||||
"{" L-statement* "}"
|
L-block
|
||||||
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
L-statement.L-statement--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||||
"print" "(" L-exp ")" ";"
|
"print" "(" L-exp ")" ";"
|
||||||
L-statement.L-statement--R-int-L-id-SEMI =
|
L-statement.L-statement--R-int-L-id-SEMI =
|
||||||
@@ -51,8 +51,11 @@ context-free syntax // Language
|
|||||||
"int" L-id "=" L-exp ";"
|
"int" L-id "=" L-exp ";"
|
||||||
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
L-statement.L-statement--R-return-L-exp-Q-SEMI =
|
||||||
"return" L-exp? ";"
|
"return" L-exp? ";"
|
||||||
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-LBRACE-L-statement-S-RBRACE =
|
L-statement.L-statement--R-fun-L-id-LPAREN-L-params-RPAREN-L-block =
|
||||||
"fun" L-id "(" L-params ")" "{" L-statement* "}"
|
"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-params.L-params--L-id-C-COMMA-L-params-D-Q =
|
||||||
L-id L-COMMA-L-params?
|
L-id L-COMMA-L-params?
|
||||||
@@ -77,6 +80,8 @@ context-free syntax // Semantics
|
|||||||
|
|
||||||
FCT.T-execute =
|
FCT.T-execute =
|
||||||
"execute" "[:" L-statement* ":]"
|
"execute" "[:" L-statement* ":]"
|
||||||
|
FCT.T-execute-block =
|
||||||
|
"execute-block" "[:" L-block ":]"
|
||||||
|
|
||||||
// # Handling parameter declarations
|
// # 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* = "(: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-statement* = "..." [1-9]? {prefer}
|
||||||
L-params = "(:Params" [1-9]? ":)" {prefer}
|
L-params = "(:Params" [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
|
rules
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ start[: (:Stmt*:) :] ]| ->
|
|[ start[: (:Stmt*:) :] ]| ->
|
||||||
|[ initialise-binding execute[: {(:Stmt*:)} :] ]|
|
|[ initialise-binding execute-block[: {(:Stmt*:)} :] ]|
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ rules
|
|||||||
|
|
||||||
|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: {(:Stmt*:)} :] ]| ->
|
|[ execute[: (:Block:) :] ]| ->
|
||||||
|[ scope (collateral (collect-declared-vars[: (:Stmt*:) :]),
|
|[ execute-block[: (:Block:) :] ]|
|
||||||
execute[: (:Stmt*:) :]) ]|
|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: print((:Exp:)); :] ]| ->
|
|[ execute[: print((:Exp:)); :] ]| ->
|
||||||
|[ print eval-exp[: (:Exp:) :] ]|
|
|[ print eval-exp[: (:Exp:) :] ]|
|
||||||
@@ -42,7 +41,7 @@ to-funcons:
|
|||||||
|[ execute[: return; :] ]| ->
|
|[ execute[: return; :] ]| ->
|
||||||
|[ return null ]|
|
|[ return null ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|
|[ execute[: fun(:Id:)((:Params:))(:Block:) :] ]| ->
|
||||||
|[ null ]|
|
|[ null ]|
|
||||||
to-funcons:
|
to-funcons:
|
||||||
|[ execute[: :] ]| ->
|
|[ execute[: :] ]| ->
|
||||||
@@ -51,6 +50,10 @@ to-funcons:
|
|||||||
|[ execute[: (:Stmt:)(:Stmt+:) :] ]| ->
|
|[ execute[: (:Stmt:)(:Stmt+:) :] ]| ->
|
||||||
|[ sequential (execute[: (:Stmt:) :],
|
|[ sequential (execute[: (:Stmt:) :],
|
||||||
execute[: (:Stmt+:) :]) ]|
|
execute[: (:Stmt+:) :]) ]|
|
||||||
|
to-funcons:
|
||||||
|
|[ execute-block[: {(:Stmt*:)} :] ]| ->
|
||||||
|
|[ scope (collateral (collect-declared-vars[: (:Stmt*:) :]),
|
||||||
|
execute[: (:Stmt*:) :]) ]|
|
||||||
|
|
||||||
// # Handling parameter declarations
|
// # 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*
|
Syntax START:start ::= statement*
|
||||||
Semantics start[[ _:start ]] : =>null-type
|
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
|
# Statements
|
||||||
|
|
||||||
Syntax Stmt: statement ::= '{' statement* '}'
|
Syntax Stmt: statement ::= block
|
||||||
| 'print' '(' exp ')' ';'
|
| 'print' '(' exp ')' ';'
|
||||||
| 'int' id ';'
|
| 'int' id ';'
|
||||||
| id '=' exp ';'
|
| id '=' exp ';'
|
||||||
| 'int' id '=' exp ';'
|
| 'int' id '=' exp ';'
|
||||||
| 'return' exp? ';'
|
| 'return' exp? ';'
|
||||||
| 'fun' id '(' params ')' '{' statement* '}'
|
| 'fun' id '(' params ')' block
|
||||||
|
|
||||||
|
Syntax Block: block ::= '{' statement* '}'
|
||||||
|
|
||||||
Syntax Params: params ::= id (',' params)?
|
Syntax Params: params ::= id (',' params)?
|
||||||
|
|
||||||
Semantics execute[[ Stmt*:statement* ]] : => null-type
|
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[[ 'print' '(' Exp ')' ';' ]] = print eval-exp[[ Exp ]]
|
||||||
Rule execute[[ 'int' Id ';' ]] = assign(bound id[[ Id ]], 0)
|
Rule execute[[ 'int' Id ';' ]] = assign(bound id[[ Id ]], 0)
|
||||||
Rule execute[[ Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
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[[ 'int' Id '=' Exp ';' ]] = assign(bound id[[ Id ]], eval-exp[[ Exp ]])
|
||||||
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
Rule execute[[ 'return' Exp ';' ]] = return eval-exp[[ Exp ]]
|
||||||
Rule execute[[ 'return' ';' ]] = return null
|
Rule execute[[ 'return' ';' ]] = return null
|
||||||
Rule execute[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = null
|
Rule execute[[ 'fun' Id '(' Params ')' Block ]] = null
|
||||||
|
|
||||||
Rule execute[[ ]] = null
|
Rule execute[[ ]] = null
|
||||||
Rule execute[[ Stmt Stmt+ ]] = sequential(execute[[ Stmt ]], execute[[ Stmt+ ]])
|
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)+
|
Semantics collect-declared-vars[[ Stmt*:statement* ]] : (=>environments)+
|
||||||
|
|
||||||
Rule collect-declared-vars[[ 'int' Id '=' Exp ';' ]] = bind(id[[ Id ]],
|
Rule collect-declared-vars[[ 'int' Id '=' Exp ';' ]] = bind(id[[ Id ]], allocate-variable(integers))
|
||||||
allocate-variable(integers)
|
Rule collect-declared-vars[[ 'int' Id ';' ]] = 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 ]],
|
Rule collect-declared-vars[[ 'fun' Id '(' Params ')' '{' Stmt* '}' ]] = bind(id[[ Id ]],
|
||||||
function abstraction(
|
function abstraction(
|
||||||
scope(
|
scope(
|
||||||
|
|||||||
Reference in New Issue
Block a user