我对 OCaml 还是很陌生,并且已经为一种小型语言编写了扫描仪、解析器和抽象语法树(带有漂亮的打印机)。我的 AST 过去编译得很好,但现在它给了我一个语法错误,我不知道为什么。
这是我收到错误的代码部分:
 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"
还有大约 100 行代码(漂亮的打印机)。
我收到以下语法错误:
文件“Ast.mli”,第 41 行,字符 0-3:错误:语法错误
如果有人有任何建议,将不胜感激。谢谢!:)