Lexer is ready just added some test files t#09

This commit is contained in:
Meyer Simon
2025-02-13 21:11:03 -05:00
parent 4483afc081
commit 910760661e
4 changed files with 65 additions and 6 deletions

View File

@ -0,0 +1,26 @@
(* Type definitions *)
type string: 1 -> character
type int2int: integer -> integer
type string2int: string -> integer
(* Function prototypes
They use the above type definitions
*)
function square : int2int
function entry : string2int
(* Function definition
Functions must be declared before they are defined
*)
square(x) := {
return x * x;
}
(* Function definition
entry is the first function called
*)
entry(arg) := {
input = 7;
expected = 49;
actual := square(input);
rseult := expected = actual;
return 0;
[ integer: input; integer: expected; integer: actual; boolean: result; string: input ]
}

View File

@ -0,0 +1,28 @@
type rec: [integer: x; integer: y]
type T1: integer -> integer
type T2: rec -> integer
function foo : T1
function bar1 : T2
function bar2 : T2
foo(x) := {
return x * x;
}
bar1(a) := {
return a.x * a.y;
}
bar2 as (r,s) := {
return r * s;
}
entry(arg) := {
[ integer: result ; rec: w]
result := foo(5);
w := reserve(w); (* see types.alpha reserve returns a value of type address,
which can be assigned to array and record variables
*)
w.x := 5;
w.y := 7;
result := bar1(w); (* pass w (a rec type value) to bar1 *)
result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *)
return 0;
}