-- vim: set syntax=alex autoindent {module Imp_Lex where } %wrapper "basic" -- character classes $digit = [0-9] $alpha = [A-Za-z] :- $white+ ; -- whitespace \( | \) {\s -> SCOPE s} -- scope \; {\s -> DELIM} -- command delimiter \+ | \- | \* {\s -> OP s} -- arithmetic ops \=\= | \< {\s -> OP s} -- boolean ops \:\= {\s -> ASSIGN} -- assignment if | then | else {\s -> KEYWORD s} -- if command while | do {\s -> KEYWORD s} -- while command skip {\s -> KEYWORD s} -- skip command True | False {\s -> BOOL $ read s} -- boolean literals $digit+ {\s -> NUM $ read s} -- numbers $alpha [$alpha $digit \_]* {\s -> LOC s} -- locations { -- The Token type - the action for each lexical class has type String -> Token data Token = SCOPE String | DELIM | OP String | ASSIGN | KEYWORD String | BOOL Bool | NUM Integer | LOC String | INVALID deriving Show imp_lex = alexScanTokens }