control flow
This commit is contained in:
@@ -4,20 +4,28 @@ initialise-binding scope
|
||||
( ),
|
||||
bind
|
||||
("i",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
0)),
|
||||
allocate-variable
|
||||
(integers)),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(if-else
|
||||
(true,
|
||||
print true,
|
||||
print false),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( )),
|
||||
print true),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( )),
|
||||
print false)),
|
||||
assign
|
||||
(bound "i",
|
||||
decimal-natural
|
||||
("0")),
|
||||
integer-negate
|
||||
(decimal-natural
|
||||
("30"))),
|
||||
while
|
||||
(is-less
|
||||
(assigned
|
||||
@@ -25,15 +33,23 @@ initialise-binding scope
|
||||
("i")),
|
||||
decimal-natural
|
||||
("10")),
|
||||
sequential
|
||||
(assign
|
||||
(bound "i",
|
||||
int-add
|
||||
(assigned
|
||||
(bound
|
||||
("i")),
|
||||
decimal-natural
|
||||
("1"))),
|
||||
print assigned
|
||||
(bound
|
||||
("i"))))))
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(assign
|
||||
(bound "i",
|
||||
int-add
|
||||
(assigned
|
||||
(bound
|
||||
("i")),
|
||||
decimal-natural
|
||||
("1"))),
|
||||
print assigned
|
||||
(bound
|
||||
("i")))))))
|
||||
@@ -5,7 +5,7 @@ if (true) {
|
||||
|
||||
|
||||
|
||||
int i = 0;
|
||||
int i = -30;
|
||||
|
||||
while (i < 10) {
|
||||
i = i+1;
|
||||
|
||||
84
IBAF-Tests/IBAF-1/fib.fct
Normal file
84
IBAF-Tests/IBAF-1/fib.fct
Normal file
@@ -0,0 +1,84 @@
|
||||
initialise-binding scope
|
||||
(collateral
|
||||
(bind
|
||||
("curr",
|
||||
allocate-variable
|
||||
(integers)),
|
||||
bind
|
||||
("prev1",
|
||||
allocate-variable
|
||||
(integers)),
|
||||
bind
|
||||
("prev2",
|
||||
allocate-variable
|
||||
(integers)),
|
||||
bind
|
||||
("n",
|
||||
allocate-variable
|
||||
(integers)),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(assign
|
||||
(bound "curr",
|
||||
0),
|
||||
assign
|
||||
(bound "prev1",
|
||||
decimal-natural
|
||||
("1")),
|
||||
assign
|
||||
(bound "prev2",
|
||||
0),
|
||||
assign
|
||||
(bound "n",
|
||||
decimal-natural
|
||||
("7")),
|
||||
while
|
||||
(is-greater-or-equal
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
0),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(assign
|
||||
(bound "curr",
|
||||
int-add
|
||||
(assigned
|
||||
(bound
|
||||
("prev2")),
|
||||
assigned
|
||||
(bound
|
||||
("prev1")))),
|
||||
assign
|
||||
(bound "prev1",
|
||||
assigned
|
||||
(bound
|
||||
("prev2"))),
|
||||
assign
|
||||
(bound "prev2",
|
||||
assigned
|
||||
(bound
|
||||
("curr"))),
|
||||
print assigned
|
||||
(bound
|
||||
("curr")),
|
||||
assign
|
||||
(bound "n",
|
||||
integer-subtract
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1"))))))))
|
||||
14
IBAF-Tests/IBAF-1/fib.ibaf
Normal file
14
IBAF-Tests/IBAF-1/fib.ibaf
Normal file
@@ -0,0 +1,14 @@
|
||||
int curr;
|
||||
int prev1 = 1;
|
||||
int prev2 = 0;
|
||||
|
||||
int n = 7;
|
||||
|
||||
while (n >= 0) {
|
||||
curr = prev2 + prev1;
|
||||
prev1 = prev2;
|
||||
prev2 = curr;
|
||||
print(curr);
|
||||
|
||||
n = n - 1;
|
||||
}
|
||||
90
IBAF-Tests/IBAF-1/fibforfun.fct
Normal file
90
IBAF-Tests/IBAF-1/fibforfun.fct
Normal file
@@ -0,0 +1,90 @@
|
||||
initialise-binding scope
|
||||
(collateral
|
||||
(bind
|
||||
("fib",
|
||||
function abstraction
|
||||
(scope
|
||||
(collateral
|
||||
(map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
bind
|
||||
("n",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
checked head
|
||||
given))),
|
||||
sequential
|
||||
(if-else
|
||||
(is-less-or-equal
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1")),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( )),
|
||||
return assigned
|
||||
(bound
|
||||
("n"))),
|
||||
null),
|
||||
return int-add
|
||||
(handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(integer-subtract
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1")))),
|
||||
handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(integer-subtract
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("2"))))))))),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(null,
|
||||
scope
|
||||
(bind
|
||||
("n",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
0)),
|
||||
while
|
||||
(is-less
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("8")),
|
||||
sequential
|
||||
(scope
|
||||
(collateral
|
||||
(map
|
||||
( )),
|
||||
print handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(assigned
|
||||
(bound
|
||||
("n"))))),
|
||||
assign
|
||||
(bound "n",
|
||||
int-add
|
||||
(1,
|
||||
assigned bound
|
||||
"n")))))))
|
||||
10
IBAF-Tests/IBAF-1/fibforfun.ibaf
Normal file
10
IBAF-Tests/IBAF-1/fibforfun.ibaf
Normal file
@@ -0,0 +1,10 @@
|
||||
fun fib(n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
for (int n = 0; n < 8) {
|
||||
print(fib(n));
|
||||
}
|
||||
95
IBAF-Tests/IBAF-1/fibfun.fct
Normal file
95
IBAF-Tests/IBAF-1/fibfun.fct
Normal file
@@ -0,0 +1,95 @@
|
||||
initialise-binding scope
|
||||
(collateral
|
||||
(bind
|
||||
("fib",
|
||||
function abstraction
|
||||
(scope
|
||||
(collateral
|
||||
(map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
bind
|
||||
("n",
|
||||
allocate-initialised-variable
|
||||
(integers,
|
||||
checked head
|
||||
given))),
|
||||
sequential
|
||||
(if-else
|
||||
(is-less-or-equal
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1")),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( )),
|
||||
return assigned
|
||||
(bound
|
||||
("n"))),
|
||||
null),
|
||||
return int-add
|
||||
(handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(integer-subtract
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1")))),
|
||||
handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(integer-subtract
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("2"))))))))),
|
||||
bind
|
||||
("n",
|
||||
allocate-variable
|
||||
(integers)),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(null,
|
||||
assign
|
||||
(bound "n",
|
||||
0),
|
||||
while
|
||||
(is-less
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("8")),
|
||||
scope
|
||||
(collateral
|
||||
(map
|
||||
( ),
|
||||
map
|
||||
( ),
|
||||
map
|
||||
( )),
|
||||
sequential
|
||||
(print handle-return apply
|
||||
(bound "fib",
|
||||
list
|
||||
(assigned
|
||||
(bound
|
||||
("n")))),
|
||||
assign
|
||||
(bound "n",
|
||||
int-add
|
||||
(assigned
|
||||
(bound
|
||||
("n")),
|
||||
decimal-natural
|
||||
("1"))))))))
|
||||
13
IBAF-Tests/IBAF-1/fibfun.ibaf
Normal file
13
IBAF-Tests/IBAF-1/fibfun.ibaf
Normal file
@@ -0,0 +1,13 @@
|
||||
fun fib(n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
}
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
|
||||
while (n < 8) {
|
||||
print(fib(n));
|
||||
n = n + 1;
|
||||
}
|
||||
@@ -6,6 +6,5 @@ fun test(a, b) {
|
||||
|
||||
int b =test(6, 3);
|
||||
|
||||
|
||||
print(a);
|
||||
print(b);
|
||||
Reference in New Issue
Block a user