xref: /aosp_15_r20/external/llvm/examples/OCaml-Kaleidoscope/Chapter3/ast.ml (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker(*===----------------------------------------------------------------------===
2*9880d681SAndroid Build Coastguard Worker * Abstract Syntax Tree (aka Parse Tree)
3*9880d681SAndroid Build Coastguard Worker *===----------------------------------------------------------------------===*)
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker(* expr - Base type for all expression nodes. *)
6*9880d681SAndroid Build Coastguard Workertype expr =
7*9880d681SAndroid Build Coastguard Worker  (* variant for numeric literals like "1.0". *)
8*9880d681SAndroid Build Coastguard Worker  | Number of float
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker  (* variant for referencing a variable, like "a". *)
11*9880d681SAndroid Build Coastguard Worker  | Variable of string
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker  (* variant for a binary operator. *)
14*9880d681SAndroid Build Coastguard Worker  | Binary of char * expr * expr
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker  (* variant for function calls. *)
17*9880d681SAndroid Build Coastguard Worker  | Call of string * expr array
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker(* proto - This type represents the "prototype" for a function, which captures
20*9880d681SAndroid Build Coastguard Worker * its name, and its argument names (thus implicitly the number of arguments the
21*9880d681SAndroid Build Coastguard Worker * function takes). *)
22*9880d681SAndroid Build Coastguard Workertype proto = Prototype of string * string array
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker(* func - This type represents a function definition itself. *)
25*9880d681SAndroid Build Coastguard Workertype func = Function of proto * expr
26