annotate python/ppci/common.py @ 252:c4370696ccc7

added optimize function
author Windel Bouwman
date Tue, 30 Jul 2013 17:57:46 +0200
parents e41e4109addd
children 1c7c1e619be8
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:
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
16 def __init__(self, row, col, ln):
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
17 self.row = row
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
18 self.col = col
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
19 self.length = ln
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
20 self.filename = ''
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
21
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
22 def __repr__(self):
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
23 return '{}, {}'.format(self.row, self.col)
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
24
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
25 SourceRange = namedtuple('SourceRange', ['p1', 'p2'])
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
26