153
|
1 from collections import namedtuple
|
|
2
|
191
|
3 # Token is used in the lexical analyzer:
|
194
|
4 class Token:
|
|
5 def __init__(self, typ, val, loc=None):
|
|
6 self.typ = typ
|
|
7 self.val = val
|
|
8 if loc is None:
|
|
9 loc = SourceLocation(0, 0, 0)
|
|
10 assert type(loc) is SourceLocation
|
|
11 self.loc = loc
|
|
12 def __repr__(self):
|
|
13 return 'Token({0}, {1})'.format(self.typ, self.val)
|
191
|
14
|
163
|
15 class SourceLocation:
|
249
|
16 def __init__(self, row, col, ln):
|
|
17 self.row = row
|
|
18 self.col = col
|
|
19 self.length = ln
|
|
20 self.filename = ''
|
|
21
|
|
22 def __repr__(self):
|
|
23 return '{}, {}'.format(self.row, self.col)
|
163
|
24
|
153
|
25 SourceRange = namedtuple('SourceRange', ['p1', 'p2'])
|
|
26
|