我想了解Alex和詞法分析器一般,但我無法運行我的詞法分析器。哈斯克爾亞歷克斯 - 錯誤的包裝模板
我寫了「基本」和「posn處」包裝詞法分析器,但我不能在「單子」的包裝。我想我必須使用monad
包裝,因爲我需要在輸入中收集字符串和標記位置。我也需要多個國家。現在我試圖運行這個簡單〔實施例:
{
module Main (main) where
}
%wrapper "monad"
$whitespace = [\ \b\t\n\f\v\r]
$digit = 0-9
$alpha = [a-zA-Z_]
$upper = [A-Z]
$lower = [a-z]
@tidentifier = $upper($alpha|_|$digit)*
@identifier = $lower($alpha|_|$digit)*
tokens :-
$whitespace+ ;
$upper $alpha+ { typeId }
$lower $alpha+ { id_ }
$digit+ { int }
{
data Lexeme = L AlexPosn LexemeClass String
data LexemeClass
= TypeId String
| Id String
| Int Int
| EOF
deriving (Show, Eq)
typeId :: AlexInput -> Int -> Alex Lexeme
typeId = undefined
id_ :: AlexInput -> Int -> Alex Lexeme
id_ = undefined
int :: AlexInput -> Int -> Alex Lexeme
int = undefined
alexEOF = return (L undefined EOF "")
main :: IO()
main = do
s <- getContents
let r = runAlex s $ do
return alexMonadScan
print r
}
我的行爲是undefined
現在。當我嘗試編譯它,我得到這個錯誤:
➜ haskell ghc --make Tokens.hs
[1 of 1] Compiling Main (Tokens.hs, Tokens.o)
templates/wrappers.hs:208:17:
Couldn't match expected type `(AlexPosn, Char, [Byte], String)'
with actual type `(t0, t1, t2)'
Expected type: AlexInput
Actual type: (t0, t1, t2)
In the return type of a call of `ignorePendingBytes'
In the first argument of `action', namely
`(ignorePendingBytes inp)'
我也越來越各種錯誤,當我嘗試編譯在Alex的GitHub庫的例子,可以把它用的版本不匹配有關?我已經用ghc 7.0.4安裝了cab的alex。有任何想法嗎?
謝謝!我應該在GitHub倉庫中打開一個問題嗎? – sinan
@sinan:是的,這可能是一個好主意。 – hammar