def __init__(self): """Expression type is somewhat of an C++/Java abstract type, __init__ must only be called by a subclass. Sets _needs_parens to False. User may set it to true in a subclass to add a parenthesis expression""" self._needs_parens = False Traversable.__init__(self)
def setChild(self, which, t): """Overrides Traversable's setChild to enforce the rule that a child of an Expression must be type Expression""" if isinstance(t, Expression): Traversable.setChild(self, which, t) else: raise ChildNotAnExpressionError(str(type(t))) return self
def __init__(self): """Initializes SymbolTable with a new dict type""" self.currSyms = {} Traversable.__init__(self)
def setParent(self, t): """Overrides the setParent in Traversable to catch unsupported parent node""" self._catchParentNotCorrectType(t) Traversable.setParent(self, t)
def removeChild(self, t): """Overrides the Traversable removeChild to catch unsupported referenced nodes""" self._catchChildNotCorrectType(t) Traversable.removeChild(self, t)
def setChild(self, which, t): """Overrides the Traversable setChild to catch unsupported child nodes""" self._catchChildNotCorrectType(t) Traversable.setChild(self, which, t)
def __init__(self, size=1): Traversable.__init__(self) self.setNumChildren(size)
"""Returns a dict representing the contents of this Expression object and its base classes instances' contents. Uses the items() function. Contents added here is _needs_parens, by calling 'items' function""" return dict(self.items()) def __setstate__(self, statedict): """Blindly calls setattr with entried from hir. __getstate__ like string->attr dict""" for k, v in list(statedict.items()): setattr(self, k, v) if __name__ == '__main__': exp = Expression() # exp.testIfNoChild() # exp.testIfNoParent() tra = Traversable() exp.setParens(True) exp.setParent(tra) exp.setNumChildren(2) chi1 = Expression() chi2 = Expression() exp.setChild(0, chi1) exp.setChild(1, chi2) # exp.getChild(100) # exp.setChild(1,1) # exp.setChild(100,chi1) print((repr(exp))) # exp.setParent(1)
def __init__(self): Traversable.__init__(self)
def __init__(self): Traversable.__init__(self) self.setNumChildren(0)