first usable version

This commit is contained in:
Peter
2023-11-09 09:46:07 +01:00
parent 70b3e9c722
commit 6b5ab857cb
22 changed files with 675 additions and 153 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
Meta([Syntax("Stratego-IBAF")])

View 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:)\") ]|

View File

@@ -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:) :] ]|

View File

@@ -0,0 +1 @@
Meta([Syntax("Stratego-IBAF")])

View 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:) :]) ]|

View File

@@ -7,6 +7,7 @@ imports
libstratego-lib
imports
completion/completion
pp
outline