Happy解析器中出现令人费解的错误消息

时间:2012-02-09 19:42:42

标签: parsing haskell happy

我正在使用Happy在Haskell中构建一个JavaScript解析器,并且我遇到了一条错误消息,无论我怎么努力,我都无法调试。

我不能在这里发布所有代码,因为它长达数千行。我会尝试发布相关内容,如果有人能帮助我,我会非常感激!

此错误消息很长,请耐心等待。我遗漏了HappyAbsSyn部分的大部分内容。如果有帮助,我可以提供完整的错误消息。

Parser.hs:800:28:
    Couldn't match expected type `Expression'
                with actual type `PrimaryExpr'
    Expected type: Int
                   -> Int
                   -> Token
                   -> HappyState
                        Token
                        (HappyStk
                           (HappyAbsSyn
                              FuncDecl
                              ... etc etc ...
                              PostFix)
                         -> P a1)
                   -> [HappyState
                         Token
                         (HappyStk
                            (HappyAbsSyn
                               FuncDecl
                              ... etc etc ...
                               PostFix)
                          -> P a1)]
                   -> HappyStk
                        (HappyAbsSyn
                           FuncDecl
                              ... etc etc ...
      Actual type: Int
                   -> Int
                   -> Token
                   -> HappyState
                        Token
                        (HappyStk
                           (HappyAbsSyn
                              FuncDecl
                              ... etc etc ...
                              t630)
                         -> P a0)
                   -> [HappyState
                         Token
                         (HappyStk
                            (HappyAbsSyn
                               FuncDecl
                              ... etc etc ...
                               t630)
                          -> P a0)]
                   -> HappyStk
                        (HappyAbsSyn
                           FuncDecl
                              ... etc etc ...
                           t630)
                   -> P a0
    In the first argument of `happyGoto', namely `action_90'
    In the expression: happyGoto action_90

知道了吗?好的,所以我做的第一件事就是查看Parser.hs中的第800行(由Happy生成的文件)。

799: action_60 (7) = happyGoto action_71
800: action_60 (28) = happyGoto action_90
801: action_60 (33) = happyGoto action_15

action_90定义为:

action_90 (100) = happyShift action_224
action_90 _ = happyFail

除非我们理解代码对应的内容,否则这显然没有多大意义。我问Happy在编译时生成一个info文件,这是(我认为)适当的部分:

-----------------------------------------------------------------------------
Grammar
-----------------------------------------------------------------------------
    %start_parse -> program                            (0)
    ... etc etc ...
    statement -> ID ':' statement                      (28)
    ... etc etc ...
    primaryExpr -> THIS                                (100)
    ... etc etc ...

所以看起来它与ID语句有关。到目前为止我真的很困惑。有没有人建议我应该从哪里开始?我猜这是为了解决这个问题,你需要看一下抽象语法。这是一点点。再次,如果有帮助,我很乐意展示更多。

data Expression
    = Assignment    Assignment 
    deriving Show

data Assignment
    = CondExpr        CondExpr
    | Assign          LeftExpr AssignOp Assignment 
    | AssignFuncDecl  FuncDecl
    deriving Show

data FuncDecl
    = FuncDecl      (Maybe String) [String] [Source]
    deriving Show

data Statement
    = EmptyStmt
    | IfStmt        IfStmt
    | IterativeStmt IterativeStmt
    | ExprStmt      Expression
    | Block         [Statement]
    | VarStmt       [VarDecl]
    | TryStmt       TryStmt
    | ContinueStmt  (Maybe String)
    | BreakStmt     (Maybe String)
    | ReturnStmt    (Maybe Expression)
    | WithStmt      Expression Statement
    | LabelledStmt  String Statement
    | Switch        Switch
    | ThrowExpr     Expression
    deriving Show

data PrimaryExpr
    = ExpLitInt     Integer
    | ExpLitStr     String
    | ExpId         String
    | ExpBrackExp   PrimaryExpr
    | ExpThis
    | ExpRegex      String
    | ExpArray      ArrayLit
    | ExpObject     [(Property, Assignment)]
    deriving Show

对不起,这太久了。我在这里结束了我的智慧。任何帮助或指示都会很棒。

0 个答案:

没有答案