git @ Cat's Eye Technologies SixtyPical / c73590f
Begin refactoring how the ParsingContext is used by the Parser. Chris Pressey 4 years ago
1 changed file(s) with 11 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
3232 def __str__(self):
3333 return "Symbols: {}\nStatics: {}\nTypedefs: {}\nConsts: {}".format(self.symbols, self.statics, self.typedefs, self.consts)
3434
35 def lookup(self, name):
35 def fetch(self, name):
3636 if name in self.statics:
3737 return self.statics[name].model
3838 if name in self.symbols:
5050 self.scanner.syntax_error(msg)
5151
5252 def lookup(self, name):
53 model = self.context.lookup(name)
53 model = self.context.fetch(name)
5454 if model is None:
5555 self.syntax_error('Undefined symbol "{}"'.format(name))
5656 return model
57
58 def declare(self, name, symentry):
59 if self.context.fetch(name):
60 self.syntax_error('Symbol "%s" already declared' % name)
61 self.context.symbols[name] = symentry
5762
5863 # --- grammar productions
5964
6974 typenames.extend(self.context.typedefs.keys())
7075 while self.scanner.on(*typenames):
7176 defn = self.defn()
72 name = defn.name
73 if self.context.lookup(name):
74 self.syntax_error('Symbol "%s" already declared' % name)
75 self.context.symbols[name] = SymEntry(defn, defn.location)
77 self.declare(defn.name, SymEntry(defn, defn.location))
7678 defns.append(defn)
7779 while self.scanner.on('define', 'routine'):
7880 if self.scanner.consume('define'):
8284 else:
8385 routine = self.legacy_routine()
8486 name = routine.name
85 if self.context.lookup(name):
86 self.syntax_error('Symbol "%s" already declared' % name)
87 self.context.symbols[name] = SymEntry(routine, routine.location)
87 self.declare(name, SymEntry(routine, routine.location))
8888 routines.append(routine)
8989 self.scanner.check_type('EOF')
9090
301301 c = {}
302302 for defn in statics:
303303 name = defn.name
304 if self.context.lookup(name):
304 if self.context.fetch(name):
305305 self.syntax_error('Symbol "%s" already declared' % name)
306306 c[name] = SymEntry(defn, defn.location)
307307 return c
333333 elif forward:
334334 name = self.scanner.token
335335 self.scanner.scan()
336 loc = self.context.lookup(name)
336 loc = self.context.fetch(name)
337337 if loc is not None:
338338 return loc
339339 else: