我只有很少的 haskell 技能,我需要帮助如何使用 parsec 实现预测解析 (LL*)。
我有上下文无关语法:
<a> ::= identifier | identifier '(' <args> ')'
基于http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pdf(章节预测解析器)我写了这段代码:
term = do{ x <- m_identifier
; try( char '(' )
; b <- argsparser
; char ')'
; return (FncCall x b)
}
<|> do { x <- m_identifier
; return (VarId x)
}
我希望这段代码尝试匹配'(',如果不是,解析器将继续并仅匹配标识符。此代码仅适用于匹配标识符'('args')'。
仅在标识符“a”上调用它会抛出:
parse error at (line 1, column 2):
unexpected end of input
expecting letter or digit or "("