首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ocaml抽象语法树-语法错误

Ocaml抽象语法树-语法错误
EN

Stack Overflow用户
提问于 2013-08-10 07:40:44
回答 1查看 907关注 0票数 2

我仍然对OCaml非常陌生,并为一种小型语言编写了扫描仪、解析器和抽象语法树(带有漂亮的打印机)。我的AST以前编译得很好,但现在它给了我一个语法错误,我不知道为什么。

下面是我得到错误的代码的一部分:

代码语言:javascript
复制
 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:错误:语法错误

如果有人有任何建议的话,我们将不胜感激。谢谢!:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-10 22:25:11

根据您更新的帖子,您正在编译一个mli文件。Mli是一个接口文件,您不能写入函数/值定义。您得到了语法错误,因为let在接口中无效。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18159773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档