Collect all declared variables at start of program execution

This commit is contained in:
Peter
2024-04-16 08:12:52 +02:00
parent cb7f6f8e5d
commit f5f5626521
21 changed files with 299 additions and 284 deletions

View File

@@ -1,90 +0,0 @@
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
("5")),
sequential
(scope
(collateral
(map
( )),
print handle-return apply
(bound "fib",
list
(assigned
(bound
("n"))))),
assign
(bound "n",
int-add
(1,
assigned bound
"n")))))))

View File

@@ -1,10 +0,0 @@
fun fib(n) {
if (n <= 1) {
return n;
}
return fib(n-1) + fib(n-2);
}
for (int n = 0; n < 5) {
print(fib(n));
}

View File

@@ -20,36 +20,32 @@ initialise-binding scope
sequential
(if-else
(is-less-or-equal
(assigned
(bound
("n")),
(assigned bound
"n",
decimal-natural
("1")),
scope
(collateral
(map
( )),
return assigned
(bound
("n"))),
return assigned bound
"n"),
null),
return int-add
(handle-return apply
(bound "fib",
list
(integer-subtract
(assigned
(bound
("n")),
(assigned bound
"n",
decimal-natural
("1")))),
handle-return apply
(bound "fib",
list
(integer-subtract
(assigned
(bound
("n")),
(assigned bound
"n",
decimal-natural
("2"))))))))),
bind
@@ -60,16 +56,15 @@ initialise-binding scope
( )),
sequential
(null,
assign
initialise-variable
(bound "n",
0),
while
(is-less
(assigned
(bound
("n")),
(assigned bound
"n",
decimal-natural
("5")),
("8")),
scope
(collateral
(map
@@ -79,17 +74,18 @@ initialise-binding scope
map
( )),
sequential
(print handle-return apply
(bound "fib",
list
(assigned
(bound
("n")))),
(print
(to-string handle-return apply
(bound "fib",
list
(assigned bound
"n")),
"
"),
assign
(bound "n",
int-add
(assigned
(bound
("n")),
(assigned bound
"n",
decimal-natural
("1"))))))))

View File

@@ -8,7 +8,7 @@ fun fib(n) {
int n = 0;
while (n < 5) {
while (n < 8) {
print(fib(n));
n = n + 1;
}

View File

@@ -6,59 +6,64 @@ initialise-binding scope
(integers)),
map
( ),
map
( ),
bind
("y",
allocate-variable
(integers)),
map
( ),
map
( )),
sequential
(assign
(initialise-variable
(bound "x",
int-mul
(decimal-natural
("10"),
decimal-natural
("10"))),
print assigned
(bound
("x")),
scope
(collateral
(bind
("x",
allocate-variable
(integers)),
bind
("y",
allocate-variable
(integers)),
map
( ),
map
( ),
map
( )),
sequential
(assign
(bound "x",
decimal-natural
("10")),
assign
(bound "y",
int-mul
(assigned
(bound
("x")),
assigned
(bound
("x")))),
print assigned
(bound
("x")),
print assigned
(bound
("y")))),
print assigned
(bound
("y"))))
print
(to-string assigned bound
"x",
"
"),
initialise-variable
(bound "y",
decimal-natural
("5")),
if-else
(true,
scope
(collateral
(bind
("y",
allocate-variable
(integers)),
map
( ),
map
( )),
sequential
(initialise-variable
(bound "y",
int-mul
(assigned bound
"x",
assigned bound
"x")),
print
(to-string assigned bound
"x",
"
"),
print
(to-string assigned bound
"y",
"
"))),
null),
print
(to-string assigned bound
"y",
"
")))

View File

@@ -1,13 +1,15 @@
int x =10*10;
print(x);
//y = 100;
//print y;
{
int x = 10;
int x =10*10;
print x;
int y = 5;
if(true){
// int x = 10;
int y = x*x;
print(x);
print(y);
print x;
print y;
}
print(y);
//int x = 1;
print y;

View File

@@ -4,61 +4,56 @@ initialise-binding scope
("x",
allocate-variable
(integers)),
bind
("y",
allocate-variable
(integers)),
map
( ),
map
( ),
bind
("y",
allocate-variable
(integers)),
map
( ),
map
( )),
sequential
(assign
(initialise-variable
(bound "x",
int-mul
(decimal-natural
("10"),
decimal-natural
("10"))),
print assigned
(bound
("x")),
scope
(collateral
(bind
("x",
allocate-variable
(integers)),
bind
("y",
allocate-variable
(integers)),
map
( ),
map
( ),
map
( )),
sequential
(assign
(bound "x",
decimal-natural
("10")),
assign
(bound "y",
int-mul
(assigned
(bound
("x")),
assigned
(bound
("x")))),
print assigned
(bound
("x")),
print assigned
(bound
("y")))),
print assigned
(bound
("x"))))
sequential
(initialise-variable
(bound "y",
int-mul
(assigned bound
"x",
assigned bound
"x")),
print
(to-string assigned bound
"x",
"
"),
print
(to-string assigned bound
"y",
"
")),
if-else
(false,
initialise-variable
(bound "y",
0),
null),
print
(to-string assigned bound
"y",
"
")))

View File

@@ -1,11 +1,13 @@
int x =10*10;
print(x);
{
int x = 10;
int y = x*x;
print(x);
print(y);
}
print(x);
if(false){
int y =0;
}
print(y);