Reputation: 1598
I am still very new to OCaml and have written a scanner, parser and Abstract Syntax Tree (with a pretty printer) for a small language. My AST used to compile fine but now it's giving me a syntax error and I can't figure out why.
Here is the part of the code where I get the error:
1 type op = Add | Sub | Mult | Div | Equal | Neq | Less | Leq | Greater | Geq
2 | And | Or | Not
3
4
5 type primitive = Int | Bool | String
6 type objtype = Room | Thing | GameMainDef
7
8 type program = odecl list
9
10 type odecl = {
11 object_name : string;
12 obj_type : objtype;
13 attrib : (string * expr) list;
14 funcdecl : f_decl list;
15 }
16
17 type expr =
18 Literal of int
19 | BoolLiteral of bool
20 | StringLiteral of string
21 | Id of string
22 | Unaryop of op * expr
23 | Binop of expr * op * expr
24 | Assign of string * expr
25 | Call of string * expr list
26 | Noexpr
27
28 type stmt =
29 Block of stmt list
30 | Expr of expr
31 | If of expr * stmt * stmt
32 | For of expr * expr * expr * stmt
33 | While of expr * stmt
34
35 type fdecl = {
36 fname : string;
37 locals : (primitive * string) list;
38 body : stmt list;
39 }
40
41 let rec string_of_type t = match t with
42 Bool -> "bool"
43 | Int -> "int"
44 | String -> "string"
45 | Room -> "Room"
46 | Thing -> "Thing"
47 | MainGameDef -> "MainGameDef"
There are about 100 more lines of code (the pretty printer).
I get the following syntax error:
File "Ast.mli", line 41, characters 0-3: Error: Syntax error
If anybody has any advice, it would be very appreciated. Thank you! :)
Upvotes: 2
Views: 940
Reputation: 9030
According to your updated post, you are compiling an mli file. Mli is an interface file where you cannot write function/value definitions. You got the syntax error because let is not valid in an interface.
Upvotes: 4