annotate python/ppci/common.py @ 194:b01429a5d695

Fixed test
author Windel Bouwman
date Wed, 29 May 2013 22:36:37 +0200
parents 6b2bec5653f1
children e41e4109addd
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
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
3 # Token is used in the lexical analyzer:
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
4 class Token:
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
5 def __init__(self, typ, val, loc=None):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
6 self.typ = typ
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
7 self.val = val
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
8 if loc is None:
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
9 loc = SourceLocation(0, 0, 0)
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
10 assert type(loc) is SourceLocation
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
11 self.loc = loc
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
12 def __repr__(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
13 return 'Token({0}, {1})'.format(self.typ, self.val)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
14
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
15 class SourceLocation:
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
16 def __init__(self, row, col, ln):
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
17 self.row = row
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
18 self.col = col
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
19 self.length = ln
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
20
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
21 SourceRange = namedtuple('SourceRange', ['p1', 'p2'])
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
22