1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
{
module Main where
}
%wrapper "basic"
$digit = 0-9 -- digits
$alpha = [a-zA-Z] -- alphabetic characters
tokens :-
$white+ { \s -> White }
"--".* { \s -> Comment }
let { \s -> Let }
in { \s -> In }
$digit+ { \s -> Int (read s) }
[\=\+\-\*\/\(\)] { \s -> Sym (head s) }
$alpha [$alpha $digit \_ \']* { \s -> Var s }
{
-- Each right-hand side has type :: String -> Token
-- The token type:
data Token =
White |
Comment |
Let |
In |
Sym Char |
Var String |
Int Int |
Err
deriving (Eq,Show)
main = do
s <- getContents
print (alexScanTokens s)
}
|