Sim*_*ine 8 haskell parser-generator alex happy
在使用Alex lexer生成器或Happy解析器生成器创建一个Lexer.x或一个Parser.y解析器时,将它们编译成Haskell文件,并将它们编译成目标文件,默认情况下会产生以下"警告":
$ ghc Lexer
line-map.c: file "<command-line>" left but not entered
line-map.c: file "<command-line>" left but not entered
[1 of 1] Compiling Lexer ( Lexer.hs, Lexer.o )
$ happy Parser.y
$ ghc Parser
line-map.c: file "<command-line>" left but not entered
line-map.c: file "<command-line>" left but not entered
[2 of 2] Compiling Parser ( Parser.hs, Parser.o )
Run Code Online (Sandbox Code Playgroud)
这些行是由于生成的.hs文件中嵌入了以下行而产生的:
{-# LINE 1 "<command-line>" #-}
Run Code Online (Sandbox Code Playgroud)
为什么包含这些行,并且有一种方法可以抑制这些消息,以防命令行显然没有用于生成的词法分析器和解析器中的任何内容?
谷歌搜索“左但未输入”表明类似这样的消息表明配置错误gcc。以下是 Apple 版本中生成该消息的代码:
void
linemap_check_files_exited (struct line_maps *set)
{
struct line_map *map;
/* Depending upon whether we are handling preprocessed input or
not, this can be a user error or an ICE. */
for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
map = INCLUDED_FROM (set, map))
fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
map->to_file);
}
Run Code Online (Sandbox Code Playgroud)
(来自http://www.opensource.apple.com/source/gcc/gcc-5484/libcpp/line-map.c)
这里的“ICE”指的是“内部编译器错误”。
插入 #LINE 指令以便 ghc 可以根据 .x 或 .y 文件中的位置报告错误。它表示以下行实际上是另一个文件中的某一行。用于伪文件名的 #LINE 指令<command-line>可以<built-in>被忽略,因为它们总是紧跟一个用于真实文件名的 #LINE 指令,例如:
...
{-# LINE 1 "<built-in>" #-}
{-# LINE 1 "<command-line>" #-}
{-# LINE 1 "templates/wrappers.hs" #-}
...
{-# LINE 1 "<built-in>" #-}
{-# LINE 1 "<command-line>" #-}
{-# LINE 1 "templates/GenericTemplate.hs" #-}
...
Run Code Online (Sandbox Code Playgroud)
作为测试,您可以简单地删除 #LINE 指令<command-line>并查看警告是否消失。我还会尝试重新安装/升级您的 gcc 和/或 Haskell 平台。