X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=examples%2FOCaml-Kaleidoscope%2FChapter6%2Fast.ml;fp=examples%2FOCaml-Kaleidoscope%2FChapter6%2Fast.ml;h=99088cfd2f516d8b898f0b0a6619f89800a825e8;hp=0000000000000000000000000000000000000000;hb=49457b81589c6a3ef384caa8fdf1463ad2ada7c7;hpb=9ef76b9985a0c408e126affa049698c413ad8664 diff --git a/examples/OCaml-Kaleidoscope/Chapter6/ast.ml b/examples/OCaml-Kaleidoscope/Chapter6/ast.ml new file mode 100644 index 00000000000..99088cfd2f5 --- /dev/null +++ b/examples/OCaml-Kaleidoscope/Chapter6/ast.ml @@ -0,0 +1,36 @@ +(*===----------------------------------------------------------------------=== + * Abstract Syntax Tree (aka Parse Tree) + *===----------------------------------------------------------------------===*) + +(* expr - Base type for all expression nodes. *) +type expr = + (* variant for numeric literals like "1.0". *) + | Number of float + + (* variant for referencing a variable, like "a". *) + | Variable of string + + (* variant for a unary operator. *) + | Unary of char * expr + + (* variant for a binary operator. *) + | Binary of char * expr * 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 + +(* proto - This type represents the "prototype" for a function, which captures + * its name, and its argument names (thus implicitly the number of arguments the + * function takes). *) +type proto = + | Prototype of string * string array + | BinOpPrototype of string * string array * int + +(* func - This type represents a function definition itself. *) +type func = Function of proto * expr