first usable version
This commit is contained in:
File diff suppressed because one or more lines are too long
1
IBAF-Editor/trans/cbs-gen/IBAF-Expressions.meta
Normal file
1
IBAF-Editor/trans/cbs-gen/IBAF-Expressions.meta
Normal file
@@ -0,0 +1 @@
|
||||
Meta([Syntax("Stratego-IBAF")])
|
||||
100
IBAF-Editor/trans/cbs-gen/IBAF-Expressions.str
Normal file
100
IBAF-Editor/trans/cbs-gen/IBAF-Expressions.str
Normal file
@@ -0,0 +1,100 @@
|
||||
module IBAF-Expressions
|
||||
|
||||
imports
|
||||
libstratego-gpp
|
||||
signatures/-
|
||||
pp/IBAF-parenthesize
|
||||
pp/IBAF-pp
|
||||
|
||||
imports
|
||||
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
rules
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Id:) :] ]| ->
|
||||
|[ assigned (bound (id[: (:Id:) :])) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Int:) :] ]| ->
|
||||
|[ int-val[: (:Int:) :] ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: true :] ]| ->
|
||||
|[ true ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: false :] ]| ->
|
||||
|[ false ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)+(:Exp2:) :] ]| ->
|
||||
|[ int-add (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)-(:Exp2:) :] ]| ->
|
||||
|[ int-sub (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)*(:Exp2:) :] ]| ->
|
||||
|[ int-mul (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)/(:Exp2:) :] ]| ->
|
||||
|[ checked int-div (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)%(:Exp2:) :] ]| ->
|
||||
|[ checked int-mod (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)&&(:Exp2:) :] ]| ->
|
||||
|[ and (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)||(:Exp2:) :] ]| ->
|
||||
|[ and (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)==(:Exp2:) :] ]| ->
|
||||
|[ is-equal (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)>=(:Exp2:) :] ]| ->
|
||||
|[ is-greater-or-equal (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)>(:Exp2:) :] ]| ->
|
||||
|[ is-greater (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)<=(:Exp2:) :] ]| ->
|
||||
|[ is-less-or-equal (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: (:Exp1:)<(:Exp2:) :] ]| ->
|
||||
|[ is-less (eval-exp[: (:Exp1:) :],
|
||||
eval-exp[: (:Exp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-exp[: ((:Exp:)) :] ]| ->
|
||||
|[ eval-exp[: (:Exp:) :] ]|
|
||||
to-funcons-lex:
|
||||
FCTDoubleQuoted(L-id(LEX-id(str))) ->
|
||||
FCTString(<double-quote> str)
|
||||
to-funcons:
|
||||
|[ id[: (:Id:) :] ]| ->
|
||||
|[ \"(:Id:)\" ]|
|
||||
to-funcons:
|
||||
|[ int-val[: (:Dec:) :] ]| ->
|
||||
|[ dec-val[: (:Dec:) :] ]|
|
||||
to-funcons:
|
||||
|[ int-val[: -(:Dec:) :] ]| ->
|
||||
|[ integer-negate (dec-val[: (:Dec:) :]) ]|
|
||||
to-funcons-lex:
|
||||
FCTDoubleQuoted(L-decimal(LEX-decimal(str))) ->
|
||||
FCTString(<double-quote> str)
|
||||
to-funcons:
|
||||
|[ dec-val[: (:Dec:) :] ]| ->
|
||||
|[ decimal-natural (\"(:Dec:)\") ]|
|
||||
|
||||
@@ -7,48 +7,26 @@ imports
|
||||
pp/IBAF-pp
|
||||
|
||||
imports
|
||||
|
||||
cbs-gen/IBAF-Expressions
|
||||
cbs-gen/IBAF-Statements
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
rules
|
||||
to-funcons:
|
||||
|[ start[: (:AExp:) :] ]| ->
|
||||
|[ initialise-binding finalise-failing eval-arith[: (:AExp:) :] ]|
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
to-funcons:
|
||||
|[ eval-arith[: (:N:) :] ]| ->
|
||||
|[ int-val[: (:N:) :] ]|
|
||||
to-funcons:
|
||||
|[ eval-arith[: (:I:) :] ]| ->
|
||||
|[ assigned (bound (id[: (:I:) :])) ]|
|
||||
to-funcons:
|
||||
|[ eval-arith[: (:AExp1:)+(:AExp2:) :] ]| ->
|
||||
|[ integer-add (eval-arith[: (:AExp1:) :],
|
||||
eval-arith[: (:AExp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-arith[: (:AExp1:)/(:AExp2:) :] ]| ->
|
||||
|[ checked integer-divide (eval-arith[: (:AExp1:) :],
|
||||
eval-arith[: (:AExp2:) :]) ]|
|
||||
to-funcons:
|
||||
|[ eval-arith[: ((:AExp:)) :] ]| ->
|
||||
|[ eval-arith[: (:AExp:) :] ]|
|
||||
to-funcons-lex:
|
||||
FCTDoubleQuoted(L-decimal(LEX-decimal(str))) ->
|
||||
FCTString(<double-quote> str)
|
||||
to-funcons:
|
||||
|[ int-val[: (:D:) :] ]| ->
|
||||
|[ decimal-natural (\"(:D:)\") ]|
|
||||
to-funcons:
|
||||
|[ int-val[: -(:D:) :] ]| ->
|
||||
|[ integer-negate (int-val[: (:D:) :]) ]|
|
||||
to-funcons-lex:
|
||||
FCTDoubleQuoted(L-id(LEX-id(str))) ->
|
||||
FCTString(<double-quote> str)
|
||||
to-funcons:
|
||||
|[ id[: (:I:) :] ]| ->
|
||||
|[ \"(:I:)\" ]|
|
||||
|[ start[: (:Pgm:) :] ]| ->
|
||||
|[ initialise-binding finalise-failing run[: (:Pgm:) :] ]|
|
||||
to-funcons:
|
||||
|[ run[: int(:IL:);(:Stmt:) :] ]| ->
|
||||
|[ scope (collateral (declare-int-vars[: (:IL:) :]),
|
||||
execute[: (:Stmt:) :]) ]|
|
||||
to-funcons:
|
||||
|[ declare-int-vars[: (:Id:) :] ]| ->
|
||||
|[ bind (\"(:Id:)\",
|
||||
allocate-initialised-variable (integers,
|
||||
0)) ]|
|
||||
to-funcons:
|
||||
|[ declare-int-vars[: (:Id:),(:IL:) :] ]| ->
|
||||
|[ declare-int-vars[: (:Id:) :],
|
||||
declare-int-vars[: (:IL:) :] ]|
|
||||
|
||||
|
||||
1
IBAF-Editor/trans/cbs-gen/IBAF-Statements.meta
Normal file
1
IBAF-Editor/trans/cbs-gen/IBAF-Statements.meta
Normal file
@@ -0,0 +1 @@
|
||||
Meta([Syntax("Stratego-IBAF")])
|
||||
26
IBAF-Editor/trans/cbs-gen/IBAF-Statements.str
Normal file
26
IBAF-Editor/trans/cbs-gen/IBAF-Statements.str
Normal file
@@ -0,0 +1,26 @@
|
||||
module IBAF-Statements
|
||||
|
||||
imports
|
||||
libstratego-gpp
|
||||
signatures/-
|
||||
pp/IBAF-parenthesize
|
||||
pp/IBAF-pp
|
||||
|
||||
imports
|
||||
cbs-gen/IBAF-Expressions
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
rules
|
||||
to-funcons:
|
||||
|[ execute[: (:Typ:)(:Id:)=(:Exp:); :] ]| ->
|
||||
|[ assign (bound (id[: (:Id:) :]),
|
||||
eval-exp[: (:Exp:) :]) ]|
|
||||
to-funcons:
|
||||
|[ execute[: print((:Exp:)); :] ]| ->
|
||||
|[ print (eval-exp[: (:Exp:) :]) ]|
|
||||
to-funcons:
|
||||
|[ execute[: (:Stmt1:)(:Stmt2:) :] ]| ->
|
||||
|[ sequential (execute[: (:Stmt1:) :],
|
||||
execute[: (:Stmt2:) :]) ]|
|
||||
|
||||
@@ -7,6 +7,7 @@ imports
|
||||
libstratego-lib
|
||||
|
||||
imports
|
||||
|
||||
completion/completion
|
||||
pp
|
||||
outline
|
||||
|
||||
Reference in New Issue
Block a user