【发布时间】:2018-05-16 00:01:10
【问题描述】:
我有以下解析器,它应该返回带有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 } }
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 在这里不受约束。如果有人能指出我正确的方向,那将不胜感激。
【问题讨论】: