Mercurial > lcfOS
view python/c3/scope.py @ 161:956f8e5ee48a
Improvements to code edit
author | Windel Bouwman |
---|---|
date | Sat, 09 Mar 2013 15:52:55 +0100 |
parents | b28a11c01dbe |
children | 8104fc8b5e90 |
line wrap: on
line source
from . import astnodes class Scope: """ A scope contains all symbols in a scope """ def __init__(self, parent=None): self.symbols = {} self.parent = parent def __iter__(self): return iter(self.symbols.values()) def getSymbol(self, name): if name in self.symbols: return self.symbols[name] # Look for symbol: if self.parent: return self.parent.getSymbol(name) raise CompilerException("Symbol {0} not found".format(name), name.loc) def hasSymbol(self, name): if name in self.symbols: return True if self.parent: return self.parent.hasSymbol(name) return False def addSymbol(self, sym): self.symbols[sym.name] = sym def createBuiltins(scope): for tn in ['int', 'u32', 'u16', 'double', 'void']: scope.addSymbol(astnodes.BaseType(tn)) topScope = Scope() createBuiltins(topScope)