我有以下解析器,它应该返回带有globalVars
and的记录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
这里没有绑定。如果有人能指出我正确的方向,那将不胜感激。