-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokens.x
53 lines (50 loc) · 1.56 KB
/
Tokens.x
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
53
{
module Tokens where
}
%wrapper "basic"
$digit = 0-9
-- digits
$alpha = [a-zA-Z]
-- alphabetic characters
tokens :-
Loop { \s -> TokenLoop }
$white+ ;
">>".* ;
$digit+ { \s -> TokenInt (read s) }
\L$digit+ { \s -> TokenLiteral (read (tail s)) }
Add { \s -> TokenAdd }
Sub { \s -> TokenSub }
Mul { \s -> TokenMul }
Div { \s -> TokenDiv }
Buffer { \s -> TokenBuffer}
Out { \s -> TokenOut }
SetVar { \s -> TokenSetVar }
Release { \s -> TokenRelease }
\( { \s -> TokenLBrack }
\) { \s -> TokenRBrack }
Var { \s -> TokenVariable }
End { \s -> TokenEnd }
\# ;
\@ ;
\~ ;
{
-- Each action has type :: String -> Token
-- The token type:
data Token =
TokenLoop |
TokenLiteral Int |
TokenInt Int |
TokenVariable |
TokenAdd |
TokenSub |
TokenMul |
TokenDiv |
TokenBuffer |
TokenOut |
TokenLBrack |
TokenRBrack |
TokenRelease |
TokenEnd |
TokenSetVar
deriving (Eq,Show)
}