-- Expression-Scanner: { module ExpAlex where } %wrapper "posn" $digit = 0-9 -- ziffer $nonzero = 1-9 -- ziffer nicht null $char = [a-zA-Z] -- Alphabet $plm = [\+\-] -- Vorzeichen exp_tokens :- $white+ ; \( { \p s -> OpenB p } \) { \p s -> CloseB p } \+ { \p s -> Plus p } \* { \p s -> Times p } 0 | $nonzero $digit* { \p s -> NumVal (read s) p } $char [ $char $digit ]* { \p s -> Id s p } $printable { \p s -> LexErr p } { type P = AlexPosn data Token = OpenB P | CloseB P -- runde Klammern | Plus P | Times P | NumVal Int P -- Integer | Id String P -- Bezeichner | LexErr P -- Lex. Error deriving Show -- Positionsanzeige: tokenLine :: Token -> Int tokenLine (OpenB p) = line p tokenLine (CloseB p) = line p tokenLine (Plus p) = line p tokenLine (Times p) = line p tokenLine (NumVal _ p)= line p tokenLine (Id _ p) = line p line :: AlexPosn -> Int line (AlexPn _ l _) = l }