GLR_Lib.hs:找不到模块'系统' [英] GLR_Lib.hs: Could not find module 'System'

查看:136
本文介绍了GLR_Lib.hs:找不到模块'系统'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面是一个例子,ABC.y,so这很清楚我在尝试什么:

  {
模块Main其中
}
%名称ps1 s1
tokentype {ABC}
%error {parseError}
%令牌
a {A}
b {B}
c {C}
%%

s1:aaab {} | b s2 a {}
s2:b a b s2 {} | c {}
{
data ABC = A | B | C
parseError _ =错误bad
main = getContents>> = print。 ps1。 lexer('a':xs)= A:lexer xs
ETC
}

这个例子在 $ b

  happy ABC.y 

但是,用--glr开心,我无法建立结果。我想知道我是否做错了。准确地说,happy --glr产生了两个输出ABC.hs.然而,ABCData.hs

  ghc --make ABC.hs ABCData.hs 

现在失败。我得到的错误是找不到模块'系统',它是haskell-98的一个隐藏成员...我尝试添加包haskell98,并得到模糊的前奏问题。我也尝试将语法编码为BNFC并使用它们的-glr选项,但是我仍然遇到其他错误,例如依赖Data.FiniteMap,这显然已被弃用。有没有办法让这个编译?

解决方案

  happy --glr 

工作正常 - 只有一件事情必须在输出中手动更改。但是请注意,它与在典型的 _ .y文件中使用Happy不同。



基本上,您需要一些区别考虑到。预期词法分析器结果的类型不同。解析器的返回类型不易控制且不同。而你使用解析器的方式稍有不同。必要的信息可以在以下网址找到:
http:/ /www.haskell.org/happy/doc/html/sec-glr-using.html
,了解该网页正确使用glr选项非常重要。



以下是如何使用Happy与glr选项生成独立分析器的方法;我们所关心的只是解析是否成功 - 您可以在上面的页面中阅读更多关于解析结果以及如何解释它们的内容。我们将为上面的解析器ABC做这件事。首先,创建一个名为ABCMain.hs的文件:

 模块Main其中

导入ABC
import ABCData

main = do
inp< - getContents
case $ b $ happyParse(lexer inp)= ParseOK _ _ - > putStrLn成功
_ - > putStrLnsuccess
lexer('a':xs)= [A]:词法分析器xs
等等 - 注意它是[[Token]]而不是[Token]

ABC.y文件很简单:

 %tokentype {ABC} 
%错误{parseError}
%令牌
a {A}
b {B}
c {C}
%%
s1:aaab {} | b s2 a {}
s2:b a b s2 {} | c {}
{
data ABC = A | B | C导出(Eq,Ord,Show) - 必须有Eq和Ord
parseError _ =错误bad
}

运行

  happy --glr ABC.y 
code>

生成这两个文件。现在,有一点我会喜欢某人评论 - 基本上你必须在生成的文件ABC.hs中手动更改行

 导入系统

  import System.IO 

然后,下面的工程对我来说:

  ghc --make ABCMain.hs 

所有东西都编译完毕,解析器按预期工作。随时让我知道我是否正确地做。


I am trying to generate a GLR parser from happy, but I am getting errors once the files are generated.

Here is an example, ABC.y , so it's clear what I am trying:

{
module Main where
}
%name ps1 s1
%tokentype { ABC }
%error { parseError }
%token
  a { A }
  b { B }
  c { C }
%%

s1: a a a b {} | b s2 a {}
s2: b a b s2 {} | c {}
{
data ABC = A | B | C
parseError _ = error "bad"
main = getContents >>= print . ps1 . lexer
lexer ('a':xs) = A : lexer xs
ETC
}

This example works just fine with

happy ABC.y

However, happy'd with --glr, I cannot build the result. I am wondering if I am doing it wrong. To be precise, happy --glr, produces the two outputs, ABC.hs. ABCData.hs, however,

ghc --make ABC.hs ABCData.hs

fails now. The error I get is Could not find module 'System', It is a hidden member of haskell-98... I tried adding package haskell98, and got ambiguous prelude problems. I also tried coding the grammar into BNFC and using their -glr option, but I still get other errors, like dependency on Data.FiniteMap which is apparently deprecated. Is there a way to get this compiling?

解决方案

happy --glr

Works fine -- there is just one thing that must be manually changed in the output. Note however, it is different from using Happy on a typical _.y file.

Basically, there are a bunch of differences you have to take into consideration. The type of the expected lexer result is different. The type of return from the parser is less controllable and different. And the way you use the parser is slightly different. The necessary information can be found on : http://www.haskell.org/happy/doc/html/sec-glr-using.html and it's really important to understand that web-page to correctly use the glr option.

Here is how you can use Happy with the glr option to produce a standalone parser; all we will care about is if the parse was successful -- you can read more about the results of parsing and how to interpret them on the above page. We will do this for the parser above, ABC. First, create a file called ABCMain.hs:

module Main where

import ABC
import ABCData

main = do
    inp <- getContents
    case happyParse (lexer inp) of
        ParseOK _ _ -> putStrLn "success"
        _ -> putStrLn " success"
lexer ('a':xs) = [A] : lexer xs
ETC -- note that it is [[Token]] instead of [Token]

And the ABC.y file is simply:

%tokentype { ABC }
%error { parseError }
%token 
    a { A }
    b { B }
    c { C }
%%
s1 : a a a b {} | b s2 a {}
s2: b a b s2 {} | c {}
{
data ABC = A | B | C deriving (Eq,Ord,Show) -- you must have Eq and Ord
parseError _ = error "bad"
}

Run

happy --glr ABC.y

Producing the two files. Now, there is one point I would love someone to comment about -- essentially you have to manually change, in the generated file ABC.hs, the line

import System

to

import System.IO

Then, the following works for me:

ghc --make ABCMain.hs

Everything compiles and the parser works as expected. Feel free to let me know if I am doing correctly.

这篇关于GLR_Lib.hs:找不到模块'系统'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆