Compilation ocamlyacc上的表达式类型错误

Compilation ocamlyacc上的表达式类型错误,compilation,ocaml,parse-tree,ocamllex,ocamlyacc,Compilation,Ocaml,Parse Tree,Ocamllex,Ocamlyacc,作为学校项目的一部分,我必须识别.dot文件并生成相应的解析树。为了实现这一点,我必须使用ocamlex和ocamlyacc,我遇到了一些困难 这是我的ocaml.mli类型文件: type id = string and node = id and attr = id * id and attr_list = attr list list and attr_stmt = Graphs of (attr_list) | Nodes of (attr_list) | Ed

作为学校项目的一部分,我必须识别.dot文件并生成相应的解析树。为了实现这一点,我必须使用ocamlex和ocamlyacc,我遇到了一些困难

这是我的ocaml.mli类型文件:

type id = string 
and node = id
and attr = id * id
and attr_list = attr list list
and attr_stmt =
    Graphs of (attr_list)
    | Nodes of (attr_list)
    | Edge of (attr_list)
and node_stmt = node * attr_list
and node_subgraph = 
    Node of (node)
    | Subgraphs of (graph)  
and edge_stmt = node_subgraph * (node_subgraph list) * attr_list
and stmt = 
    Node_stmt of (node_stmt)
    | Edge_stmt of (edge_stmt)
    | Attr_stmt of (attr_stmt)
    | Attr of (attr)
    | Subgraph of  graph
and graph = 
    Graph_node of (node * stmt list)
    | Graph of (stmt list);;
这是我的lexer文件:

{
    open Parser
}
rule token = parse 
    (* Espacements *)
    | [ ' ' '\t' '\n']+  {token lexbuf}
    (* *)
    | "graph" {GRAPH}
    | "subgraph" {SUBGRAPH}
    | "--" {EDGE}
    (* Délimiteurs *)
    | "{" {LEFT_ACC}
    | "}" {RIGHT_ACC}
    | "(" {LEFT_PAR}
    | ")" {RIGHT_PAR}
    | "[" {LEFT_BRA}
    | "]" {RIGHT_BRA} 
    | "," {COMMA}
    | ";" {SEMICOLON}
    | "=" {EQUAL}
    | ":" {TWOPOINT}
    | ['a'-'z''A'-'Z''0'-'9']*  as id {ID (id)} 
    | eof { raise End_of_file }
这是我尚未完成的yacc文件:

%{
    open Types
%}

%token <string> ID 
%token <string> STR
%token GRAPH SUBGRAPH EDGE
%token LEFT_ACC RIGHT_ACC LEFT_PAR RIGHT_PAR LEFT_BRA RIGHT_BRA
%token COMME SEMICOLON EQUAL TWOPOINT EOF 

%start main
%type <graph> main 

%%

main:
 graph EOF { $1 }


graph:
    GRAPH ID LEFT_ACC content RIGHT_ACC {$4}
    | GRAPH LEFT_ACC content RIGHT_ACC {$3}

subgraph:
    SUBGRAPH ID LEFT_ACC content RIGHT_ACC {$4}
    | SUBGRAPH LEFT_ACC content RIGHT_ACC {$3}

content:
    | ID EDGE ID SEMICOLON {[($1,$3)]}
但是,当我尝试编译解析器接口时,会出现以下错误: 此表达式具有“a列表”类型 但表达式应为Types.graph类型(引用
ID边ID分号{[$1,$3)]}
line)

我不明白,因为{[$1,$3]}有一个(string*string)列表类型。如果我们在寻找types.mli,它可以是一个图形


否则,我是否正确理解了ocamlex和ocamlyacc的运行

类型为
graph
的值必须以
graph
graph\u节点开始。这与
(string*string)列表完全不同

谢谢!至少现在它可以编译了,但是当我尝试运行程序时,我得到了一个致命的错误:异常End_of_File。我怎样才能解决这个问题?如何查看是否已创建解析树?
graph D {
    A -- B ;
}