2026-04-29 15:25:15 +00:00
|
|
|
let sample_program =
|
|
|
|
|
{|
|
|
|
|
|
struct Point {
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int sum_array(int[] arr) {
|
|
|
|
|
int total = 0;
|
|
|
|
|
foreach (int n in arr) {
|
|
|
|
|
total = total + n;
|
|
|
|
|
}
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
struct Point p;
|
|
|
|
|
int[] nums;
|
|
|
|
|
int x = 1 + 2 * 3;
|
|
|
|
|
p.x = x;
|
|
|
|
|
if (x > 0) {
|
|
|
|
|
x = x + p.x;
|
|
|
|
|
} else {
|
|
|
|
|
x = 0;
|
|
|
|
|
}
|
|
|
|
|
x = sum_array(nums);
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|}
|
|
|
|
|
|
|
|
|
|
let () =
|
|
|
|
|
match Spooky.parse_and_type_check sample_program with
|
2026-04-29 15:28:57 +00:00
|
|
|
| Ok ast ->
|
|
|
|
|
Printf.printf "Program parsed and type-checked successfully.\n\n";
|
|
|
|
|
Printf.printf "Parsed AST:\n%s\n" (Spooky.string_of_program ast)
|
2026-04-29 15:25:15 +00:00
|
|
|
| Error msg -> Printf.printf "Error: %s\n" msg
|