annotate python/ppci/common.py @ 287:1c7c1e619be8

File movage
author Windel Bouwman
date Thu, 21 Nov 2013 11:57:27 +0100
parents e41e4109addd
children 534b94b40aa8
rev   line source
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
1 from collections import namedtuple
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
2
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
3
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
4 # Token is used in the lexical analyzer:
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
5 class Token:
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
6 def __init__(self, typ, val, loc=None):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
7 self.typ = typ
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
8 self.val = val
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
9 if loc is None:
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
10 loc = SourceLocation('', 0, 0, 0)
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
11 assert type(loc) is SourceLocation
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
12 self.loc = loc
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
13 def __repr__(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
14 return 'Token({0}, {1})'.format(self.typ, self.val)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
15
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
16
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
17 class SourceLocation:
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
18 def __init__(self, filename, row, col, ln):
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
19 self.filename = filename
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
20 self.row = row
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
21 self.col = col
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
22 self.length = ln
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
23
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
24 def __repr__(self):
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
25 return '{}, {}'.format(self.row, self.col)
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
26
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
27
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
28 SourceRange = namedtuple('SourceRange', ['p1', 'p2'])
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
29