git @ Cat's Eye Technologies ZOWIE / b321499
Beginning of Scanner objects. Chris Pressey 7 years ago
1 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
187187 if key in self.mmap_register:
188188 self.mmap_register[key].write(value)
189189 self.storage_register[key] = value
190
191
192 class Scanner(object):
193 def __init__(self, line):
194 self.line = line
195
196 def scan_integer(self):
197 number = 0
198 if not self.line or not self.line[0].isdigit():
199 raise SyntaxError('Expected integer')
200 while self.line and self.line[0].isdigit():
201 number = number * 10 + (ord(line[0]) - ord('0'))
202 self.line = self.line[1:]
203 return number
204
205 def scan_register(self):
206 if not self.line or self.line[0] != 'R':
207 raise SyntaxError('Expected R')
208 self.line = self.line[1:]
209 if not self.line:
210 raise SyntaxError('Expected register designator')
211 if self.line[0] == '[':
212 pass # ...
213 else:
214 regnum = self.scan_integer()
215 return ('direct', regnum)
190216
191217
192218 class Instruction(object):