From: Mart Lubbers Date: Wed, 24 Feb 2016 21:35:31 +0000 (+0100) Subject: Changed numbertoken to Int X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=75ac4a13efdc20b444a5eb6cb2d16425c82d333e;p=cc1516.git Changed numbertoken to Int --- diff --git a/lex.dcl b/lex.dcl index e141b94..438e547 100644 --- a/lex.dcl +++ b/lex.dcl @@ -6,7 +6,7 @@ import Data.Either :: TokenValue //Value tokens = IdentToken [Char] // Identifier - | NumberToken [Char]// Integer + | NumberToken Int // Integer | CharToken Char // Character literal //Keyword tokens | VarToken // var keyword diff --git a/lex.icl b/lex.icl index 82e6139..de200df 100644 --- a/lex.icl +++ b/lex.icl @@ -65,14 +65,16 @@ lex ['\'':'\\':x:'\'':xs] = case get x EscapeMap of Just t = ret (CharToken t) xs _ = err ("Unknown escape: \\" +++ toString x) lex ['-':t=:[x:xs]] -| isDigit x = let (n, r) = span isDigit t in ret (NumberToken ['-':n]) r +| isDigit x = let (n, r) = span isDigit t in + ret (NumberToken (toInt $ toString ['-':n])) r | otherwise = ret DashToken xs lex t=:[x:xs] = case get x SingleCharTokens of (Just tok) = ret tok xs Nothing | x == '\n' = \i.lex xs (i+1) | isSpace x = lex xs - | isDigit x = let (v, r) = span isDigit t in ret (NumberToken v) r + | isDigit x = let (v, r) = span isDigit t in + ret (NumberToken (toInt $ toString v)) r | isAlpha x = let (v, r) = span isIdent t in ret (IdentToken v) r with isIdent c = isAlphanum c || c == '_' | otherwise = err ("Unexpected character: " +++ toString x)