Ocamlyacc似乎没有返回完整记录

Ocamlyacc似乎没有返回完整记录,ocaml,ocamlyacc,Ocaml,Ocamlyacc,我有下面的解析器,它应该返回一个带有globalVars和globalFns的记录,但它似乎没有 %start program %type <Ast.program> program %% program: decls EOF { $1 } decls: /* nothing */ { { globalVars = []; globalFns = []; } } | decls varDecl { {

我有下面的解析器,它应该返回一个带有globalVars和globalFns的记录,但它似乎没有

%start program
%type <Ast.program> program

%%

program:
    decls EOF { $1 }

decls:
      /* nothing */             { { globalVars = []; globalFns = []; } }
    | decls varDecl             { { $1 with globalVars  = $1::$2.globalVars  } }
    | decls fnDecl              { { $1 with globalFns   = $1::$2.globalFns  } }
当我尝试执行以下操作时,收到的错误是:error:Unbound record field globalVars:

let translate program =
    let global_vars =
        let global_var m (t, n) =
            let init = L.const_int (ltype_of_typ t) 0
            in StringMap.add n (L.define_global n init the_module) m in
            List.fold_left global_var StringMap.empty program.globalVars in

我根本不明白为什么program.globalVars在这里没有绑定。如果有人能给我指出正确的方向,我将不胜感激。

是记录字段globalVars在当前范围内未绑定,而不是真正编程。globalVars本身:字段标签位于定义它们的模块中。为了访问在当前模块外部定义的类型的记录字段;您需要使用完全限定的字段路径program.Ast.globalVars,其中Ast.globalVars是模块Ast中定义的字段globalVars的路径,或者通过打开模块或注释程序类型将字段引入范围:let translate program:Ast.program=..

Omg,I love you@octachron
let translate program =
    let global_vars =
        let global_var m (t, n) =
            let init = L.const_int (ltype_of_typ t) 0
            in StringMap.add n (L.define_global n init the_module) m in
            List.fold_left global_var StringMap.empty program.globalVars in