elna/example.elna

155 lines
1.8 KiB
Plaintext

type
T = array 5 of Int,
R = record
x: Int;
y: Int
end,
U = union
a: Int;
b: Int
end;
proc test_string();
var s: String;
begin
s := "Test string.";
writei("");
writei(s)
end;
proc test_array();
var a: T, x: Int;
begin
a[0] := 2;
a[1] := 5;
writei("");
writei("Test array:");
x := 0;
while x < 2 do
writei(a[x]);
x := x + 1
end
end;
proc test_pointer();
var x: Int, p: pointer to Int;
begin
x := 5;
p := @x;
writei("");
writei("Test pointer:");
writei(p);
writei(p^)
end;
proc test_record();
var r: R;
begin
writei("");
writei("Test record:");
r.x := 4;
r.y := 8;
writei(r.y)
end;
proc test_union();
var u: U;
begin
writei("");
writei("Test union:");
u.a := 9;
writei(u.b)
end;
proc test_primitive();
var c: Char, z: Float;
begin
c := 'x';
z := 8.2;
writei("");
writei("Test primitives:");
writei(c);
writei(z)
end;
proc test_const();
const t = 5;
var x: Int;
begin
x := t;
writei("");
writei("Test const:");
writei(x)
end;
proc test_if();
var x: Bool, y: Bool;
begin
x := true;
y := false;
writei("");
if x and y then
writei("Test if: True")
else
writei("Test if: False")
end
end;
proc test_not();
var x: Bool;
begin
x := false;
writei("");
if not x then
writei("Test not true.")
else
writei("Test not false")
end
end;
proc test_param(d: Int, e: Int);
begin
writei("");
writei("Test param");
writei(d);
writei(e)
end;
proc test_const_char();
const x = 'u';
begin
writei("");
writei("Test constant character");
writei(x)
end;
proc exit(code: Int); extern;
begin
test_primitive();
test_string();
test_array();
test_pointer();
test_record();
test_const();
test_if();
test_not();
test_param(8, 7);
test_const_char();
test_union();
exit(0)
end.