comparison python/ppci/assembler.py @ 384:94f5b719ad0b

Small refactor
author Windel Bouwman
date Sun, 27 Apr 2014 17:50:25 +0200
parents 0c44e494ef58
children 2a970e7270e2
comparison
equal deleted inserted replaced
383:173e20a47fda 384:94f5b719ad0b
1 1
2 import re 2 import re
3 import pyyacc 3 import pyyacc
4 from baselex import BaseLexer 4 from baselex import BaseLexer
5 from . import Token, CompilerError, SourceLocation 5 from . import Token, CompilerError, SourceLocation, make_num
6 from .target import Target, Label 6 from .target import Target, Label
7 7
8 8
9 def bit_type(value): 9 def bit_type(value):
10 assert value < (2**32) 10 assert value < (2**32)
35 if val.lower() in self.kws: 35 if val.lower() in self.kws:
36 typ = val.lower() 36 typ = val.lower()
37 return (typ, val) 37 return (typ, val)
38 38
39 def handle_number(self, typ, val): 39 def handle_number(self, typ, val):
40 if val.startswith('0x'): 40 val = make_num(val)
41 val = int(val[2:], 16)
42 else:
43 val = int(val)
44 typ = bit_type(val) 41 typ = bit_type(val)
45 return typ, val 42 return typ, val
46 43
47 44
48 class Parser: 45 class Parser: