मैं सामान्य रूप में एलेक्स और lexers समझने की कोशिश कर रहा हूँ, लेकिन मैं अपने lexer चलाने के लिए परेशानी आ रही है में त्रुटि।हास्केल एलेक्स - आवरण टेम्पलेट
मैं "बुनियादी" और "posn" रैपर में lexers लिखा था, लेकिन मैं "इकाई" आवरण में नहीं कर सके। मुझे लगता है कि मुझे 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)'
मैं भी विभिन्न त्रुटियों हो रही है जब मैं एलेक्स के GitHub रेपो में उदाहरण संकलित करने के लिए प्रयास करते हैं, यह एक संस्करण बेमेल साथ संबंधित हो सकता है: जब मैं यह संकलन करने की कोशिश, मैं इस त्रुटि मिल रही है? मैंने ghc 7.0.4 के साथ कैबल से एलेक्स स्थापित किया है। कोई विचार?
धन्यवाद! क्या मुझे इसके गिटहब रेपो में कोई समस्या खुलनी चाहिए? – sinan
@sinan: हाँ, यह शायद एक अच्छा विचार होगा। – hammar