first usable version
This commit is contained in:
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/.cache
|
||||
/bin
|
||||
/src-gen
|
||||
/target
|
||||
|
||||
/.classpath
|
||||
/.settings
|
||||
/.factorypath
|
||||
|
||||
/.polyglot.metaborg.yaml
|
||||
128
IBAF-Editor/syntax/cbs-gen/IBAF-Expressions.sdf3
Normal file
128
IBAF-Editor/syntax/cbs-gen/IBAF-Expressions.sdf3
Normal file
@@ -0,0 +1,128 @@
|
||||
module IBAF-Expressions
|
||||
|
||||
imports
|
||||
|
||||
Funcons
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
lexical syntax // Language
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
LEX-id = ( [a-z] | [A-Z] ) ( [a-z] | [A-Z] | [0-9] )*
|
||||
LEX-DASH = "-"
|
||||
LEX-decimal = [1-9] ( [0-9] )*
|
||||
|
||||
syntax // Language
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
L-int-CF.L-int--R-0 =
|
||||
"0"
|
||||
L-int-CF.L-int--C-DASH-Q-L-decimal-D =
|
||||
L-DASH-Q-L-decimal-CF
|
||||
L-DASH-Q-L-decimal-CF.L-DASH-Q-L-decimal--DASH-Q-L-decimal =
|
||||
LEX-DASH-CF? L-decimal-CF
|
||||
|
||||
|
||||
|
||||
context-free syntax // Language
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
L-exp.L-exp--L-id =
|
||||
L-id
|
||||
L-exp.L-exp--L-int =
|
||||
L-int
|
||||
L-exp.L-exp--R-true =
|
||||
"true"
|
||||
L-exp.L-exp--R-false =
|
||||
"false"
|
||||
L-exp.L-exp--L-exp-PLUS-L-exp =
|
||||
L-exp "+" L-exp
|
||||
L-exp.L-exp--L-exp-DASH-L-exp =
|
||||
L-exp "-" L-exp
|
||||
L-exp.L-exp--L-exp-STAR-L-exp =
|
||||
L-exp "*" L-exp
|
||||
L-exp.L-exp--L-exp-SLASH-L-exp =
|
||||
L-exp "/" L-exp
|
||||
L-exp.L-exp--L-exp-PERCENT-L-exp =
|
||||
L-exp "%" L-exp
|
||||
L-exp.L-exp--L-exp-AMPERSAND-AMPERSAND-L-exp =
|
||||
L-exp "&&" L-exp
|
||||
L-exp.L-exp--L-exp-BAR-BAR-L-exp =
|
||||
L-exp "||" L-exp
|
||||
L-exp.L-exp--L-exp-EQUALS-EQUALS-L-exp =
|
||||
L-exp "==" L-exp
|
||||
L-exp.L-exp--L-exp-GREATER-EQUALS-L-exp =
|
||||
L-exp ">=" L-exp
|
||||
L-exp.L-exp--L-exp-GREATER-L-exp =
|
||||
L-exp ">" L-exp
|
||||
L-exp.L-exp--L-exp-LESS-EQUALS-L-exp =
|
||||
L-exp "<=" L-exp
|
||||
L-exp.L-exp--L-exp-LESS-L-exp =
|
||||
L-exp "<" L-exp
|
||||
L-exp.L-exp--LPAREN-L-exp-RPAREN =
|
||||
"(" L-exp ")"
|
||||
|
||||
L-id.LEX-id =
|
||||
LEX-id
|
||||
L-decimal.LEX-decimal =
|
||||
LEX-decimal
|
||||
|
||||
context-free syntax // Semantics
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
FCT.T-eval-exp =
|
||||
"eval-exp" "[:" L-exp ":]"
|
||||
FCT-Quoted.L-id = L-id
|
||||
FCT.T-id =
|
||||
"id" "[:" L-id ":]"
|
||||
FCT.T-int-val =
|
||||
"int-val" "[:" L-int ":]"
|
||||
FCT-Quoted.L-decimal = L-decimal
|
||||
FCT.T-dec-val =
|
||||
"dec-val" "[:" L-decimal ":]"
|
||||
|
||||
context-free syntax // Desugaring
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
|
||||
variables // Meta-variables
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
L-exp = "(:Exp" [1-9]? ":)" {prefer}
|
||||
L-exp? = "(:Exp" [1-9]? "?:)" {prefer}
|
||||
L-exp* = "(:Exp" [1-9]? "*:)" {prefer}
|
||||
L-exp+ = "(:Exp" [1-9]? "+:)" {prefer}
|
||||
L-id = "(:Id" [1-9]? ":)" {prefer}
|
||||
L-id? = "(:Id" [1-9]? "?:)" {prefer}
|
||||
L-id* = "(:Id" [1-9]? "*:)" {prefer}
|
||||
L-id+ = "(:Id" [1-9]? "+:)" {prefer}
|
||||
L-int = "(:Int" [1-9]? ":)" {prefer}
|
||||
L-int? = "(:Int" [1-9]? "?:)" {prefer}
|
||||
L-int* = "(:Int" [1-9]? "*:)" {prefer}
|
||||
L-int+ = "(:Int" [1-9]? "+:)" {prefer}
|
||||
L-decimal = "(:Dec" [1-9]? ":)" {prefer}
|
||||
L-decimal? = "(:Dec" [1-9]? "?:)" {prefer}
|
||||
L-decimal* = "(:Dec" [1-9]? "*:)" {prefer}
|
||||
L-decimal+ = "(:Dec" [1-9]? "+:)" {prefer}
|
||||
|
||||
// SDF comments
|
||||
|
||||
// # 1: General expressions
|
||||
|
||||
|
||||
|
||||
sorts // ASTs
|
||||
T-start
|
||||
@@ -1,103 +1,81 @@
|
||||
module IBAF-Start
|
||||
|
||||
imports
|
||||
|
||||
IBAF-Expressions
|
||||
IBAF-Statements
|
||||
Funcons
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
lexical syntax // Language
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
LEX-DASH = "-"
|
||||
LEX-decimal = ( [0-9] )+
|
||||
LEX-id = ( [A-Z] | [a-z] )+
|
||||
LEX-keyword = "else"
|
||||
LEX-keyword = "false"
|
||||
LEX-keyword = "if"
|
||||
LEX-keyword = "true"
|
||||
LEX-keyword = "while"
|
||||
LEX-keyword = "int"
|
||||
|
||||
syntax // Language
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
|
||||
context-free syntax // Language
|
||||
L-start.L-start--L-aexp =
|
||||
L-aexp
|
||||
L-start.L-start--L-pgm =
|
||||
L-pgm
|
||||
|
||||
L-pgm.L-pgm--R-int-L-idlist-SEMI-L-stmt =
|
||||
"int" L-idlist ";" L-stmt
|
||||
|
||||
L-idlist.L-idlist--L-id-C-COMMA-L-idlist-D-Q =
|
||||
L-id L-COMMA-L-idlist?
|
||||
|
||||
L-COMMA-L-idlist.L-COMMA-L-idlist--COMMA-L-idlist =
|
||||
"," L-idlist
|
||||
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
L-aexp.L-aexp--L-num =
|
||||
L-num
|
||||
L-aexp.L-aexp--L-id =
|
||||
L-id
|
||||
L-aexp.L-aexp--L-aexp-PLUS-L-aexp =
|
||||
L-aexp "+" L-aexp
|
||||
L-aexp.L-aexp--L-aexp-SLASH-L-aexp =
|
||||
L-aexp "/" L-aexp
|
||||
L-aexp.L-aexp--LPAREN-L-aexp-RPAREN =
|
||||
"(" L-aexp ")"
|
||||
|
||||
L-decimal.LEX-decimal =
|
||||
LEX-decimal
|
||||
L-id.LEX-id =
|
||||
LEX-id
|
||||
L-keyword.LEX-keyword =
|
||||
LEX-keyword
|
||||
|
||||
context-free syntax // Semantics
|
||||
FCT.T-start =
|
||||
"start" "[:" L-start ":]"
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
FCT.T-eval-arith =
|
||||
"eval-arith" "[:" L-aexp ":]"
|
||||
FCT-Quoted.L-decimal = L-decimal
|
||||
FCT.T-int-val =
|
||||
"int-val" "[:" L-num ":]"
|
||||
FCT-Quoted.L-id = L-id
|
||||
FCT.T-id =
|
||||
"id" "[:" L-id ":]"
|
||||
FCT.T-run =
|
||||
"run" "[:" L-pgm ":]"
|
||||
FCT-SEQ.T-declare-int-vars =
|
||||
"declare-int-vars" "[:" L-idlist ":]"
|
||||
FCT-Quoted.LEX-keyword = LEX-keyword
|
||||
|
||||
context-free syntax // Desugaring
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
|
||||
variables // Meta-variables
|
||||
L-start = "(:START" [1-9]? ":)" {prefer}
|
||||
L-start? = "(:START" [1-9]? "?:)" {prefer}
|
||||
L-start* = "(:START" [1-9]? "*:)" {prefer}
|
||||
L-start+ = "(:START" [1-9]? "+:)" {prefer}
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
|
||||
L-aexp = "(:AExp" [1-9]? ":)" {prefer}
|
||||
L-aexp? = "(:AExp" [1-9]? "?:)" {prefer}
|
||||
L-aexp* = "(:AExp" [1-9]? "*:)" {prefer}
|
||||
L-aexp+ = "(:AExp" [1-9]? "+:)" {prefer}
|
||||
L-num = "(:N" [1-9]? ":)" {prefer}
|
||||
L-num? = "(:N" [1-9]? "?:)" {prefer}
|
||||
L-num* = "(:N" [1-9]? "*:)" {prefer}
|
||||
L-num+ = "(:N" [1-9]? "+:)" {prefer}
|
||||
L-decimal = "(:D" [1-9]? ":)" {prefer}
|
||||
L-decimal? = "(:D" [1-9]? "?:)" {prefer}
|
||||
L-decimal* = "(:D" [1-9]? "*:)" {prefer}
|
||||
L-decimal+ = "(:D" [1-9]? "+:)" {prefer}
|
||||
L-id = "(:I" [1-9]? ":)" {prefer}
|
||||
L-id? = "(:I" [1-9]? "?:)" {prefer}
|
||||
L-id* = "(:I" [1-9]? "*:)" {prefer}
|
||||
L-id+ = "(:I" [1-9]? "+:)" {prefer}
|
||||
L-pgm = "(:Pgm" [1-9]? ":)" {prefer}
|
||||
L-pgm? = "(:Pgm" [1-9]? "?:)" {prefer}
|
||||
L-pgm* = "(:Pgm" [1-9]? "*:)" {prefer}
|
||||
L-pgm+ = "(:Pgm" [1-9]? "+:)" {prefer}
|
||||
L-idlist = "(:IL" [1-9]? ":)" {prefer}
|
||||
L-idlist? = "(:IL" [1-9]? "?:)" {prefer}
|
||||
L-idlist* = "(:IL" [1-9]? "*:)" {prefer}
|
||||
L-idlist+ = "(:IL" [1-9]? "+:)" {prefer}
|
||||
|
||||
// SDF comments
|
||||
|
||||
// #1 Arithmetic expressions
|
||||
|
||||
lexical syntax
|
||||
LEX-id = LEX-keyword {reject}
|
||||
lexical restrictions
|
||||
LEX-id -/- [A-Za-z0-9]
|
||||
|
||||
context-free syntax
|
||||
L-exp.L-exp--L-exp-PLUS-L-exp =
|
||||
L-exp "+" L-exp
|
||||
{assoc}
|
||||
L-exp.L-exp--L-exp-AMPERSAND-AMPERSAND-L-exp =
|
||||
L-exp "&&" L-exp
|
||||
{assoc}
|
||||
L-stmt.L-stmt--L-stmt-L-stmt =
|
||||
L-stmt L-stmt
|
||||
{right}
|
||||
|
||||
sorts // ASTs
|
||||
T-start
|
||||
|
||||
48
IBAF-Editor/syntax/cbs-gen/IBAF-Statements.sdf3
Normal file
48
IBAF-Editor/syntax/cbs-gen/IBAF-Statements.sdf3
Normal file
@@ -0,0 +1,48 @@
|
||||
module IBAF-Statements
|
||||
|
||||
imports
|
||||
IBAF-Expressions
|
||||
Funcons
|
||||
|
||||
// Language "IBAFlang"
|
||||
|
||||
lexical syntax // Language
|
||||
|
||||
syntax // Language
|
||||
|
||||
context-free syntax // Language
|
||||
L-stmt.L-stmt--L-type-L-id-EQUALS-L-exp-SEMI =
|
||||
L-type L-id "=" L-exp ";"
|
||||
L-stmt.L-stmt--R-print-LPAREN-L-exp-RPAREN-SEMI =
|
||||
"print" "(" L-exp ")" ";"
|
||||
L-stmt.L-stmt--L-stmt-L-stmt =
|
||||
L-stmt L-stmt
|
||||
|
||||
L-type.L-type--R-int =
|
||||
"int"
|
||||
L-type.L-type--R-bool =
|
||||
"bool"
|
||||
L-type.L-type--L-id =
|
||||
L-id
|
||||
|
||||
|
||||
context-free syntax // Semantics
|
||||
FCT.T-execute =
|
||||
"execute" "[:" L-stmt ":]"
|
||||
|
||||
context-free syntax // Desugaring
|
||||
|
||||
variables // Meta-variables
|
||||
L-stmt = "(:Stmt" [1-9]? ":)" {prefer}
|
||||
L-stmt? = "(:Stmt" [1-9]? "?:)" {prefer}
|
||||
L-stmt* = "(:Stmt" [1-9]? "*:)" {prefer}
|
||||
L-stmt+ = "(:Stmt" [1-9]? "+:)" {prefer}
|
||||
L-type = "(:Typ" [1-9]? ":)" {prefer}
|
||||
L-type? = "(:Typ" [1-9]? "?:)" {prefer}
|
||||
L-type* = "(:Typ" [1-9]? "*:)" {prefer}
|
||||
L-type+ = "(:Typ" [1-9]? "+:)" {prefer}
|
||||
|
||||
// SDF comments
|
||||
|
||||
sorts // ASTs
|
||||
T-start
|
||||
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
|
||||
|
||||
17
IBAF-Tests/.project
Normal file
17
IBAF-Tests/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>IBAF-Tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.metaborg.spoofax.eclipse.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.metaborg.spoofax.eclipse.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
50
IBAF-Tests/IBAF-1/test.aterm
Normal file
50
IBAF-Tests/IBAF-1/test.aterm
Normal file
@@ -0,0 +1,50 @@
|
||||
L-start--L-pgm(
|
||||
L-pgm--R-int-L-idlist-SEMI-L-stmt(
|
||||
L-idlist--L-id-C-COMMA-L-idlist-D-Q(
|
||||
LEX-id("x")
|
||||
, Some(L-COMMA-L-idlist--COMMA-L-idlist(L-idlist--L-id-C-COMMA-L-idlist-D-Q(LEX-id("y"), None())))
|
||||
)
|
||||
, L-stmt--L-stmt-L-stmt(
|
||||
L-stmt--L-id-EQUALS-L-exp-SEMI(
|
||||
LEX-id("x")
|
||||
, L-exp--L-aexp(
|
||||
L-aexp--L-aexp-PERCENT-L-aexp(
|
||||
L-aexp--L-int(L-int--C-DASH-Q-L-decimal-D(L-DASH-Q-L-decimal--DASH-Q-L-decimal(None(), LEX-decimal("10"))))
|
||||
, L-aexp--L-int(L-int--C-DASH-Q-L-decimal-D(L-DASH-Q-L-decimal--DASH-Q-L-decimal(None(), LEX-decimal("3"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
, L-stmt--L-stmt-L-stmt(
|
||||
L-stmt--L-id-EQUALS-L-exp-SEMI(
|
||||
LEX-id("y")
|
||||
, L-exp--L-aexp(
|
||||
L-aexp--L-aexp-PLUS-L-aexp(
|
||||
L-aexp--L-id(LEX-id("x"))
|
||||
, L-aexp--L-int(L-int--C-DASH-Q-L-decimal-D(L-DASH-Q-L-decimal--DASH-Q-L-decimal(None(), LEX-decimal("10"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
, L-stmt--L-stmt-L-stmt(
|
||||
L-stmt--R-print-LPAREN-L-exp-RPAREN-SEMI(
|
||||
amb(
|
||||
[ amb(
|
||||
[L-exp--L-id(LEX-id("x")), L-exp--L-bexp(L-bexp--L-id(LEX-id("x")))]
|
||||
)
|
||||
, L-exp--L-aexp(L-aexp--L-id(LEX-id("x")))
|
||||
]
|
||||
)
|
||||
)
|
||||
, L-stmt--R-print-LPAREN-L-exp-RPAREN-SEMI(
|
||||
amb(
|
||||
[ amb(
|
||||
[L-exp--L-id(LEX-id("y")), L-exp--L-bexp(L-bexp--L-id(LEX-id("y")))]
|
||||
)
|
||||
, L-exp--L-aexp(L-aexp--L-id(LEX-id("y")))
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
64
IBAF-Tests/IBAF-1/test.fct
Normal file
64
IBAF-Tests/IBAF-1/test.fct
Normal file
@@ -0,0 +1,64 @@
|
||||
initialise-binding finalise-failing scope
|
||||
(collateral
|
||||
(bind
|
||||
("x",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
0)),
|
||||
bind
|
||||
("y",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
0))),
|
||||
sequential
|
||||
(assign
|
||||
(bound
|
||||
("x"),
|
||||
decimal-natural
|
||||
("10")),
|
||||
assign
|
||||
(bound
|
||||
("y"),
|
||||
checked int-mod
|
||||
(assigned
|
||||
(bound
|
||||
("x")),
|
||||
int-val [: 0 :])),
|
||||
print
|
||||
(assigned
|
||||
(bound
|
||||
("x"))),
|
||||
print
|
||||
(assigned
|
||||
(bound
|
||||
("y"))),
|
||||
print
|
||||
(is-equal
|
||||
(assigned
|
||||
(bound
|
||||
("x")),
|
||||
decimal-natural
|
||||
("1"))),
|
||||
print
|
||||
(is-equal
|
||||
(assigned
|
||||
(bound
|
||||
("x")),
|
||||
assigned
|
||||
(bound
|
||||
("y")))),
|
||||
print
|
||||
(is-less
|
||||
(assigned
|
||||
(bound
|
||||
("x")),
|
||||
assigned
|
||||
(bound
|
||||
("y")))),
|
||||
print
|
||||
(int-add
|
||||
(assigned
|
||||
(bound
|
||||
("x")),
|
||||
decimal-natural
|
||||
("2")))))
|
||||
13
IBAF-Tests/IBAF-1/test.ibaf
Normal file
13
IBAF-Tests/IBAF-1/test.ibaf
Normal file
@@ -0,0 +1,13 @@
|
||||
int x, y;
|
||||
|
||||
int x = 10;
|
||||
int y = x % 3;
|
||||
|
||||
print(x);
|
||||
print(y);
|
||||
|
||||
print(x == 1);
|
||||
print(x == y);
|
||||
print(x < y);
|
||||
|
||||
print(x + 2);
|
||||
1
IBAF-Tests/IBAF-1/test.pp.ibaf
Normal file
1
IBAF-Tests/IBAF-1/test.pp.ibaf
Normal file
@@ -0,0 +1 @@
|
||||
int x , y ; x = 10 % 3 ; y = x + 10 ; print ( x ) ; print ( y ) ;
|
||||
Binary file not shown.
66
IBAF-cbs/IBAF/IBAF-Start/IBAF-Expressions.cbs
Normal file
66
IBAF-cbs/IBAF/IBAF-Start/IBAF-Expressions.cbs
Normal file
@@ -0,0 +1,66 @@
|
||||
Language "IBAFlang"
|
||||
|
||||
# 1: General expressions
|
||||
Syntax Exp:exp ::= id
|
||||
| int
|
||||
| 'true'
|
||||
| 'false'
|
||||
| exp '+' exp
|
||||
| exp '-' exp
|
||||
| exp '*' exp
|
||||
| exp '/' exp
|
||||
| exp '%' exp
|
||||
| exp '&&' exp
|
||||
| exp '||' exp
|
||||
| exp '==' exp
|
||||
| exp '>=' exp
|
||||
| exp '>' exp
|
||||
| exp '<=' exp
|
||||
| exp '<' exp
|
||||
| '(' exp ')'
|
||||
|
||||
Semantics eval-exp[[ _:exp ]] : => values
|
||||
Rule eval-exp[[ Id ]] = assigned(bound(id[[ Id ]]))
|
||||
Rule eval-exp[[ Int ]] = int-val[[ Int ]]
|
||||
Rule eval-exp[[ 'true' ]] = true
|
||||
Rule eval-exp[[ 'false' ]] = false
|
||||
Rule eval-exp[[ Exp1 '+' Exp2 ]] = int-add(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '-' Exp2 ]] = int-sub(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '*' Exp2 ]] = int-mul(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '/' Exp2 ]] = checked int-div(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '%' Exp2 ]] = checked int-mod(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '&&' Exp2 ]] = and(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '||' Exp2 ]] = and(eval-exp[[ Exp1 ]], eval-exp[[ Exp2 ]])
|
||||
Rule eval-exp[[ Exp1 '==' Exp2 ]] = is-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '>=' Exp2 ]] = is-greater-or-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '>' Exp2 ]] = is-greater(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '<=' Exp2 ]] = is-less-or-equal(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ Exp1 '<' Exp2 ]] = is-less(eval-exp[[ Exp1 ]], eval-exp[[ Exp2]] )
|
||||
Rule eval-exp[[ '(' Exp ')' ]] = eval-exp[[ Exp ]]
|
||||
|
||||
|
||||
|
||||
Lexis Id:id ::= ('a'-'z' | 'A'-'Z') ('a'-'z' | 'A'-'Z' | '0'-'9')*
|
||||
|
||||
Semantics id[[ _:id ]] : ids
|
||||
Rule id[[ Id ]] = \"Id\"
|
||||
|
||||
|
||||
Syntax Int:int ::= '0' | ('-'?_decimal)
|
||||
|
||||
Semantics int-val[[ _:int ]] : ints
|
||||
Rule int-val[[ '0' ]] = decimal-natural(\"0\")
|
||||
Rule int-val[[ Dec ]] = dec-val[[ Dec ]]
|
||||
Rule int-val[[ '-' Dec ]] = integer-negate(dec-val[[ Dec ]])
|
||||
|
||||
|
||||
Lexis Dec:decimal ::= '1'-'9'('0'-'9')*
|
||||
|
||||
Semantics dec-val[[ _:decimal ]] : ints
|
||||
Rule dec-val[[ Dec ]] = decimal-natural(\"Dec\")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,55 +1,47 @@
|
||||
Language "IBAFlang"
|
||||
|
||||
Syntax START:start ::= aexp
|
||||
Syntax START:start ::= pgm
|
||||
|
||||
Semantics start[[ _:start ]] : =>values
|
||||
Semantics start[[ _:start ]] : =>null-type
|
||||
|
||||
Rule start[[ AExp ]] =
|
||||
Rule start[[ Pgm ]] =
|
||||
initialise-binding
|
||||
finalise-failing
|
||||
eval-arith[[ AExp ]]
|
||||
|
||||
|
||||
#1 Arithmetic expressions
|
||||
run [[ Pgm ]]
|
||||
|
||||
|
||||
Syntax
|
||||
AExp : aexp ::= num
|
||||
| id
|
||||
| aexp '+' aexp
|
||||
| aexp '/' aexp
|
||||
| '(' aexp ')'
|
||||
|
||||
Semantics
|
||||
eval-arith[[ _:aexp ]] : =>integers
|
||||
Rule
|
||||
eval-arith[[ N ]] = int-val[[ N ]]
|
||||
Rule
|
||||
eval-arith[[ I ]] = assigned(bound(id[[ I ]]))
|
||||
Rule
|
||||
eval-arith[[ AExp1 '+' AExp2 ]] =
|
||||
integer-add(eval-arith[[ AExp1 ]], eval-arith[[ AExp2 ]])
|
||||
Rule
|
||||
eval-arith[[ AExp1 '/' AExp2 ]] =
|
||||
checked integer-divide(eval-arith[[ AExp1 ]], eval-arith[[ AExp2 ]])
|
||||
Rule
|
||||
eval-arith[[ '(' AExp ')' ]] = eval-arith[[ AExp ]]
|
||||
|
||||
Syntax
|
||||
N : num ::= '-'?_decimal
|
||||
Lexis
|
||||
D : decimal ::= ('0'-'9')+
|
||||
Semantics
|
||||
int-val[[ _:num ]] : integers
|
||||
Rule
|
||||
int-val[[ D ]] = decimal-natural(\"D\")
|
||||
Rule
|
||||
int-val[[ '-' D ]] = integer-negate(int-val[[ D ]])
|
||||
|
||||
Lexis
|
||||
I : id ::= ('A'-'Z'|'a'-'z')+
|
||||
Semantics
|
||||
id[[ _:id ]] : ids
|
||||
Rule
|
||||
id[[ I ]] = \"I\"
|
||||
Syntax Pgm : pgm ::= 'int' idlist ';' stmt
|
||||
|
||||
Semantics run[[ _:pgm ]] : =>null-type
|
||||
Rule run[[ 'int' IL ';' Stmt ]] =
|
||||
scope( collateral(declare-int-vars[[ IL ]]),
|
||||
execute[[ Stmt ]] )
|
||||
|
||||
Syntax IL : idlist ::= id (',' idlist)?
|
||||
|
||||
Semantics declare-int-vars[[ _: idlist ]] : (=>environments)+
|
||||
Rule declare-int-vars[[ Id ]] = bind(\"Id\", allocate-initialised-variable(integers, 0))
|
||||
Rule declare-int-vars[[ Id ',' IL ]] = declare-int-vars[[ Id ]], declare-int-vars[[ IL ]]
|
||||
|
||||
|
||||
|
||||
|
||||
Lexis keyword ::= 'else' | 'false' | 'if' | 'true' | 'while' | 'int'
|
||||
Lexis SDF
|
||||
/*
|
||||
lexical syntax
|
||||
``id`` = ``keyword`` {reject}
|
||||
lexical restrictions
|
||||
``id`` -/- [A-Za-z0-9]
|
||||
*/
|
||||
|
||||
Syntax SDF
|
||||
/*
|
||||
context-free syntax
|
||||
``exp ::= exp '+' exp`` {assoc}
|
||||
``exp ::= exp '&&' exp`` {assoc}
|
||||
``stmt ::= stmt stmt`` {right}
|
||||
*/
|
||||
41
IBAF-cbs/IBAF/IBAF-Start/IBAF-Statements.cbs
Normal file
41
IBAF-cbs/IBAF/IBAF-Start/IBAF-Statements.cbs
Normal file
@@ -0,0 +1,41 @@
|
||||
Language "IBAFlang"
|
||||
|
||||
|
||||
Syntax Stmt:stmt ::= type id '=' exp ';'
|
||||
| 'print' '(' exp ')' ';'
|
||||
// | '{' stmt '}'
|
||||
| stmt stmt
|
||||
|
||||
|
||||
Syntax Typ:type ::= 'int'
|
||||
| 'bool'
|
||||
| id
|
||||
|
||||
Semantics execute[[ _:stmt ]] : => null
|
||||
|
||||
Rule execute[[ Typ Id '=' Exp ';' ]] = assign(bound(id[[ Id ]]), eval-exp[[ Exp ]])
|
||||
Rule execute[[ 'print' '(' Exp ')' ';' ]] = print(eval-exp[[ Exp ]])
|
||||
|
||||
//Rule execute[[ '{' Stmt '}' ]] = scope(
|
||||
// collateral(collect-declared-vars[[ Stmt ]]),
|
||||
// execute[[ Stmt ]]
|
||||
//)
|
||||
|
||||
Rule execute[[ Stmt1 Stmt2 ]] = sequential(execute[[ Stmt1 ]], execute[[ Stmt2 ]])
|
||||
|
||||
|
||||
|
||||
//Semantics collect-declared-vars[[ _:stmt ]] : (=>environments)*
|
||||
//
|
||||
//
|
||||
//Rule collect-declared-vars[[ Typ Id '=' Exp ';' ]] =
|
||||
// bind(
|
||||
// \"Id\",
|
||||
// allocate-initialised-variable(
|
||||
// integers, //TODO: use type
|
||||
// eval-exp[[ Exp ]]
|
||||
// )
|
||||
// )
|
||||
//Rule collect-declared-vars[[ Stmt ]] = null
|
||||
//Rule collect-declared-vars[[ Stmt1 Stmt2 ]] = (collect-declared-vars[[ Stmt1 ]], collect-declared-vars[[ Stmt2 ]]))
|
||||
|
||||
Binary file not shown.
7
readme.md
Normal file
7
readme.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# IBAFlang (Imperative But Also Functional language)
|
||||
|
||||
This repo contains the projects for IBAF.
|
||||
- `cbs` is the project that contains the source `.cbs` files that defines the language.
|
||||
- `Editor` is the Spoofax project that can be used to build the IDE for IBAF.
|
||||
- `Tests` is a project containing some example programs.
|
||||
|
||||
Reference in New Issue
Block a user