我正在使用OCamllex和Menhir编写Go to Python编译器,但我的词法分析器无法导入Core包。
这是我的lex.mll文件:
{
(* Header *)
open Core.Std
open Lexing
open Parser
exception SyntaxError of string
let next_line lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{ pos with pos_bol = lexbuf.lex_curr_pos;
pos_lnum = pos.pos_lnum + 1
}
let syntaxError msg = raise (SyntaxError (msg ^ " on line " ^ (string_of_int next_line)))
(* End Header *)
}
[ lexer rules ]
我有一个make文件,make.sh将lexer和解析器放在一起
#! /bin/bash
echo "==Creating compiler=="
echo "- OCamllex : lex.mll -> lex.ml"
ocamllex lex.mll
echo "- OCaml : lex.ml -> lex"
ocamlc lex.ml -o lex
# echo "- OCamlBuild -> main.ml"
# ocamlbuild -use-menhir main.native
但是当我运行./make.sh时,我收到了这个错误:
==Creating compiler==
- OCamllex : lex.mll -> lex.ml
1030 states, 16995 transitions, table size 74160 bytes
- OCaml : lex.ml -> lex
File "lex.mll", line 4, characters 7-15:
Error: Unbound module Core
我可以通过编辑我的.ocamlinit文件在ocaml解释器中打开Core,但是如何在ocamlc编译的脚本中导入Core?
答案 0 :(得分:2)
从脚本中删除所有内容,然后使用
corebuild -use-menhir main.native
corebuild
将推断所有依赖项并编译它们,并完成所有工作。