0

我有以下解析器,它应该返回带有globalVarsand的记录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  } }

其中ast.ml将程序定义为:

type program = {
    globalVars  : bind list;
    globalFns   : func_decl list;
}

我收到的错误是: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这里没有绑定。如果有人能指出我正确的方向,那将不胜感激。

4

1 回答 1

1
于 2017-12-01T20:30:11.700 回答