-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokens.hs
122 lines (117 loc) · 2.99 KB
/
Tokens.hs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module Tokens where
-- Token type
data Token =
TkInt
| TkBool
| TkArray
| TkDeclare
| TkRead
| TkPrint
| TkPrintln
| TkIf
| TkFi
| TkFor
| TkIn
| TkTo
| TkRof
| TkDo
| TkOd
| TkAtoi
| TkSize
| TkMax
| TkMin
| TkComma
| TkColon
| TkSemicolon
| TkSoForth
| TkArrow
| TkPlus
| TkMinus
| TkMult
| TkDiv
| TkMod
| TkOr
| TkAnd
| TkNot
| TkEqual
| TkNEqual
| TkLess
| TkLeq
| TkGreater
| TkGeq
| TkGuard
| TkAssign
| TkConcat
| TkOpenPar
| TkClosePar
| TkOpenBracket
| TkCloseBracket
| TkOpenBlock
| TkCloseBlock
| TkId String
| TkNum Int
| TkString String
| TkTrue
| TkFalse
| TkEOF
deriving(Eq)
instance Show Token where
show TkInt = "TkInt"
show TkBool = "TkBool"
show TkArray = "TkArray"
show TkDeclare = "TkDeclare"
show TkRead = "TkRead"
show TkPrint = "TkPrint"
show TkPrintln = "TkPrintln"
show TkIf = "TkIf"
show TkFi = "TkFi"
show TkFor = "TkFor"
show TkIn = "TkIn"
show TkTo = "TkTo"
show TkRof = "TkRof"
show TkDo = "TkDo"
show TkOd = "TkOd"
show TkAtoi = "TkAtoi"
show TkSize = "TkSize"
show TkMax = "TkMax"
show TkMin = "TkMin"
show TkComma = "TkComma"
show TkColon = "TkTwoPoints"
show TkSemicolon = "TkSemicolon"
show TkSoForth = "TkSoForth"
show TkArrow = "TkArrow"
show TkPlus = "TkPlus"
show TkMinus = "TkMinus"
show TkMult = "TkMult"
show TkDiv = "TkDiv"
show TkMod = "TkMod"
show TkOr = "TkOr"
show TkAnd = "TkAnd"
show TkNot = "TkNot"
show TkEqual = "TkEqual"
show TkNEqual = "TkNEqual"
show TkLess = "TkLess"
show TkLeq = "TkLeq"
show TkGreater = "TkGreater"
show TkGeq = "TkGeq"
show TkGuard = "TkGuard"
show TkAssign = "TkAsig"
show TkConcat = "TkConcat"
show TkOpenPar = "TkOpenPar"
show TkClosePar = "TkClosePar"
show TkOpenBracket = "TkOBracket"
show TkCloseBracket = "TkCBracket"
show TkOpenBlock = "TkOBlock"
show TkCloseBlock = "TkCBlock"
show (TkId s) = "TkId(" ++ show s ++ ")"
show (TkNum n) = "TkNum(" ++ show n ++ ")"
show (TkString s) = "TkString(" ++ show s ++ ")"
show TkTrue = "TkTrue"
show TkFalse = "TkFalse"
show TkEOF = "TkEOF"
type TokenPos = (Token, Int, Int)
getPos :: TokenPos -> (Int, Int)
getPos (_,l,c) = (l,c)
getString :: TokenPos -> String
getString (TkId s, _, _) = s
getString _ = undefined