1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-29 18:49:22 +00:00

Another conversion away from self.context.fetch to self.declare.

This commit is contained in:
Chris Pressey 2018-09-07 12:43:55 +01:00
parent c73590f88c
commit 5bad7ff576

View File

@ -56,11 +56,17 @@ class Parser(object):
self.syntax_error('Undefined symbol "{}"'.format(name)) self.syntax_error('Undefined symbol "{}"'.format(name))
return model return model
def declare(self, name, symentry): def declare(self, name, symentry, static=False):
if self.context.fetch(name): if self.context.fetch(name):
self.syntax_error('Symbol "%s" already declared' % name) self.syntax_error('Symbol "%s" already declared' % name)
if static:
self.context.statics[name] = symentry
else:
self.context.symbols[name] = symentry self.context.symbols[name] = symentry
def clear_statics(self):
self.context.statics = {}
# --- grammar productions # --- grammar productions
def program(self): def program(self):
@ -286,9 +292,11 @@ class Parser(object):
else: else:
statics = self.statics() statics = self.statics()
self.context.statics = self.compose_statics_dict(statics) self.clear_statics()
for defn in statics:
self.declare(defn.name, SymEntry(defn, defn.location), static=True)
block = self.block() block = self.block()
self.context.statics = {} self.clear_statics()
addr = None addr = None
location = LocationRef(type_, name) location = LocationRef(type_, name)
@ -298,15 +306,6 @@ class Parser(object):
location=location, statics=statics location=location, statics=statics
) )
def compose_statics_dict(self, statics):
c = {}
for defn in statics:
name = defn.name
if self.context.fetch(name):
self.syntax_error('Symbol "%s" already declared' % name)
c[name] = SymEntry(defn, defn.location)
return c
def labels(self): def labels(self):
accum = [] accum = []
accum.append(self.label()) accum.append(self.label())