-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexer.x
More file actions
52 lines (47 loc) · 1.33 KB
/
Lexer.x
File metadata and controls
52 lines (47 loc) · 1.33 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
module Lexer where
}
%wrapper "posn"
$digit = 0-9
-- numbers
$alpha = [a-zA-Z]
-- alphabetic characters
$upper = [A-Z]
-- uppercase alphabetic characters
$lower = [a-z]
-- lowercase alphabetic characters
tokens :-
$white+ ;
"//".* ;
"{" { \p s -> TokenOpenBrace p}
"}" { \p s -> TokenCloseBrace p}
"[" { \p s -> TokenOpenSqr p}
"]" { \p s -> TokenCloseSqr p}
\= { \p s -> TokenEq p}
\( { \p s -> TokenLParen p}
\) { \p s -> TokenRParen p}
";" { \p s -> TokenSemiColon p}
"," { \p s -> TokenComma p}
"_" { \p s -> TokenUnderscore p }
$lower [$alpha $digit \_ \’]* { \p s -> TokenVar p s }
$upper [$alpha $digit \_ \’]* { \p s -> TokenRel p s }
[$digit]+ { \p s -> TokenNum p (read s) }
{
-- Each action has type :: String -> Token
-- The token type:
data Token =
TokenOpenBrace AlexPosn |
TokenCloseBrace AlexPosn |
TokenOpenSqr AlexPosn |
TokenCloseSqr AlexPosn |
TokenVar AlexPosn String |
TokenRel AlexPosn String |
TokenEq AlexPosn |
TokenLParen AlexPosn |
TokenRParen AlexPosn |
TokenSemiColon AlexPosn |
TokenNum AlexPosn Int |
TokenUnderscore AlexPosn |
TokenComma AlexPosn
deriving (Eq,Show)
}