Files
IBAFLang/IBAF-Editor/trans/cbs-gen/IBAF-Statements.str

128 lines
3.7 KiB
Plaintext

module IBAF-Statements
imports
libstratego-gpp
signatures/-
pp/IBAF-parenthesize
pp/IBAF-pp
imports
cbs-gen/IBAF-Expressions
// Language "IBAFlang"
rules
// # Statements
to-funcons:
|[ execute[: (:Block:) :] ]| ->
|[ execute-block[: (:Block:) :] ]|
to-funcons:
|[ execute[: print(:Exp:); :] ]| ->
|[ print (to-string eval-exp[: (:Exp:) :],
"\n") ]|
to-funcons:
|[ execute[: int(:Id:); :] ]| ->
|[ initialise-variable (bound id[: (:Id:) :],
0) ]|
to-funcons:
|[ execute[: (:Id:)=(:Exp:); :] ]| ->
|[ assign (bound id[: (:Id:) :],
eval-exp[: (:Exp:) :]) ]|
to-funcons:
|[ execute[: int(:Id:)=(:Exp:); :] ]| ->
|[ initialise-variable (bound id[: (:Id:) :],
eval-exp[: (:Exp:) :]) ]|
to-funcons:
|[ execute[: return(:Exp:); :] ]| ->
|[ return eval-exp[: (:Exp:) :] ]|
to-funcons:
|[ execute[: return; :] ]| ->
|[ return null ]|
to-funcons:
|[ execute[: fun(:Id:)((:Params:))(:Block:) :] ]| ->
|[ null ]|
to-funcons:
|[ execute[: if((:Exp:))(:Block:) :] ]| ->
|[ if-else (eval-exp[: (:Exp:) :],
execute-block[: (:Block:) :],
null) ]|
to-funcons:
|[ execute[: if((:Exp:))(:Block1:)else(:Block2:) :] ]| ->
|[ if-else (eval-exp[: (:Exp:) :],
execute-block[: (:Block1:) :],
execute-block[: (:Block2:) :]) ]|
to-funcons:
|[ execute[: while((:Exp:))(:Block:) :] ]| ->
|[ while (eval-exp[: (:Exp:) :],
execute-block[: (:Block:) :]) ]|
to-funcons:
|[ execute[: :] ]| ->
|[ null ]|
to-funcons:
|[ execute[: (:Stmt:)(:Stmt+:) :] ]| ->
|[ sequential (execute[: (:Stmt:) :],
execute[: (:Stmt+:) :]) ]|
to-funcons:
|[ execute-block[: {(:Stmt*:)} :] ]| ->
|[ execute[: (:Stmt*:) :] ]|
// # Handling parameter declarations
to-funcons:
|[ collect-params[: (:Id:) :] ]| ->
|[ bind (id[: (:Id:) :],
allocate-initialised-variable (integers,
checked head given)) ]|
to-funcons:
|[ collect-params[: (:Id:),(:Params:) :] ]| ->
|[ collect-params[: (:Id:) :],
give (checked tail given,
collect-params[: (:Params:) :]) ]|
// # Handling variable declarations
to-funcons:
|[ collect-declared-vars[: int(:Id:)=(:Exp:); :] ]| ->
|[ bind (id[: (:Id:) :],
allocate-variable (integers)) ]|
to-funcons:
|[ collect-declared-vars[: int(:Id:); :] ]| ->
|[ bind (id[: (:Id:) :],
allocate-variable (integers)) ]|
to-funcons:
|[ collect-declared-vars[: fun(:Id:)((:Params:)){(:Stmt*:)} :] ]| ->
|[ bind (id[: (:Id:) :],
function abstraction (scope (collateral (collect-declared-vars[: (:Stmt*:) :],
collect-params[: (:Params:) :]),
execute[: (:Stmt*:) :]))) ]|
to-funcons:
|[ collect-declared-vars[: {(:Stmt*:)} :] ]| ->
|[ collect-declared-vars[: (:Stmt*:) :] ]|
to-funcons:
|[ collect-declared-vars[: if((:Exp:))(:Block:) :] ]| ->
|[ collect-declared-vars[: (:Block:) :] ]|
to-funcons:
|[ collect-declared-vars[: if((:Exp:))(:Block1:)else(:Block2:) :] ]| ->
|[ collect-declared-vars[: (:Block1:) :],
collect-declared-vars[: (:Block2:) :] ]|
to-funcons:
|[ collect-declared-vars[: while((:Exp:))(:Block:) :] ]| ->
|[ collect-declared-vars[: (:Block:) :] ]|
to-funcons:
|[ collect-declared-vars[: :] ]| ->
|[ map () ]|
to-funcons:
|[ collect-declared-vars[: (:Stmt:) :] ]| ->
|[ map () ]|
to-funcons:
|[ collect-declared-vars[: (:Stmt1:)(:Stmt2:)(:Stmt*:) :] ]| ->
|[ collect-declared-vars[: (:Stmt1:) :],
collect-declared-vars[: (:Stmt2:) :],
collect-declared-vars[: (:Stmt*:) :] ]|