Mercurial > lcfOS
view python/c3/scope.py @ 150:4ae0e02599de
Added type check start and analyze phase
author | Windel Bouwman |
---|---|
date | Fri, 01 Mar 2013 16:53:22 +0100 |
parents | |
children | b28a11c01dbe |
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']: scope.addSymbol(astnodes.BaseType(tn)) topScope = Scope() createBuiltins(topScope)