Lexer.x 1.77 KB
Newer Older
mnay1u19's avatar
mnay1u19 committed
1
2
3
{
module Lexer where
}
4

mnay1u19's avatar
mnay1u19 committed
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%wrapper "basic"
$digit = 0-9
$alpha = [a-zA-Z]


tokens :-
    $white+         ;
    "--".*          ;
    Filter          {\s -> TokenFilter }
    SetName         {\s -> TokenSetName s }
    Func            {\s -> TokenFunc }
    Nat             {\s -> TokenNat (read s) }
    VarName         {\s -> TokenVarName s }
    Record          {\s -> TokenRecord }
    true            {\s -> TokenTrue }
    false           {\s -> TokenFalse }
    String          {\s -> TokenString s }
    '['             {\s -> TokenLeftSqBracket }
    ']'             {\s -> TokenRightSqBracket }
    "->"            {\s -> TokenArrow }
    "=="            {\s -> TokenisEqual }
    "/="            {\s -> TokenisNotEqual }
    '('             {\s -> TokenLeftBracket }
    ')'             {\s -> TokenRightBracket }
    ';'             {\s -> TokenApp }
    '\\'            {\s -> TokenLambda }
    ','             {\s -> TokenComma  }
    '.'             {\s -> TokenFullstop }
    in              {\s -> TokenInSet    }
    out             {\s -> TokenOutSet   }
    $digit $digit+   {(\p s -> TokenInt p (read s))}
    $alpha [$alpha $digit \_ \’]*   { \p s -> TokenVar p s }
{
--token type:
data Token =
    TokenFilter         |
    TokenSetName String |
    TokenFunc           |
    TokenNat Int        |
    TokenVarName String |
    TokenRecord         |
    TokenTrue           |
    TokenFalse          |
    TokenString String  |
    TokenLeftSqBracket  |
    TokenRightSqBracket |
    TokenArrow          |
    TokenisEqual        |
    TokenisNotEqual     |
    TokenLeftBracket    |
    TokenRightBracket   |
    TokenApp            |
    TokenLambda         |
    TokenComma          |
    TokenFullStop       |
    TokenInSet          |
    TokenOutSet
    deriving  (Eq, Show)


}