我想定义一个keyword_table
将一些字符串映射到一些标记的 a,并且我想让这个表对parser.mly
和都可见lexer.mll
。
似乎该表必须在中定义parser.mly
,
%{
open Utility (* where hash_table is defined to make a table from a list *)
let keyword_table = hash_table [
"Call", CALL; "Case", CASE; "Close", CLOSE; "Const", CONST;
"Declare", DECLARE; "DefBool", DEFBOOL; "DefByte", DEFBYTE ]
%}
但是,我不能使用它lexer.mll
,例如
{
open Parser
let x = keyword_table (* doesn't work *)
let x = Parser.keyword_table (* doesn't work *)
let x = Parsing.keyword_table (* doesn't work *)
}
正如这个评论所暗示的,menhir
有一个解决方案,谁能告诉我任何细节?