implement scoping 🎉

This commit is contained in:
Peter
2023-11-18 11:18:25 +01:00
parent c3ee83292f
commit ae30900155
19 changed files with 338 additions and 181 deletions

View File

@@ -0,0 +1,99 @@
initialise-binding scope
(collateral
(bind
("z",
allocate-initialised-variable
(integers,
0)),
bind
("x",
allocate-initialised-variable
(integers,
0)),
map
( ),
map
( ),
map
( ),
map
( ),
map
( ),
map
( ),
map
( )),
sequential
(assign
(bound
("z"),
decimal-natural
("5")),
assign
(bound
("x"),
int-mul
(decimal-natural
("5"),
decimal-natural
("3"))),
print
(assigned
(bound
("x"))),
assign
(bound
("x"),
decimal-natural
("2")),
print
(int-mul
(assigned
(bound
("x")),
decimal-natural
("3"))),
scope
(collateral
(bind
("y",
allocate-initialised-variable
(integers,
0)),
map
( ),
map
( )),
sequential
(assign
(bound
("y"),
decimal-natural
("4")),
print
(assigned
(bound
("y"))))),
assign
(bound
("z"),
int-mul
(assigned
(bound
("z")),
assigned
(bound
("x")))),
print
(assigned
(bound
("z"))),
print
(int-add
(assigned
(bound
("z")),
assigned
(bound
("x"))))))

View File

@@ -0,0 +1,16 @@
int z =5;
int x =5*3;
print(x);
x = 2;
print(x*3);
{
int y =4;
print (y);
}
z = z * x;
print(z);
print(z+x);

View File

@@ -1,64 +0,0 @@
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")))))

View File

@@ -1,4 +1,4 @@
int x, y;
int x,y;
int x = 10;
int y = x % 3;

View File

@@ -1 +0,0 @@
int x , y ; x = 10 % 3 ; y = x + 10 ; print ( x ) ; print ( y ) ;