-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.ml
38 lines (28 loc) · 1.12 KB
/
ast.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(*===----------------------------------------------------------------------====
* Abstract Syntax Tree
*===----------------------------------------------------------------------===*)
(* Base type for all expression nodes *)
type expr =
(* variant for all numeric literals *)
| Number of float
(* variant for referencing a variable *)
| Variable of string
(* variant for var/in *)
| Var of (string * expr option) array * expr
(* variant for a binary operator *)
| Binary of char * expr * expr
(* variant for a unary operator *)
| Unary of char * expr
(* variant for function calls *)
| Call of string * expr array
(* variant for if/then/else *)
| If of expr * expr * expr
(* variant for for/in *)
| For of string * expr * expr * expr option * expr
(* This type represents the prototype for a function, which captures its name
* and its arguments names (thus the number of arguments the function takes) *)
type proto =
| Prototype of string * string array
| BinOpPrototype of string * string array * int
(* This type represents a function definition itself *)
type func = Function of proto * expr