Skip to content

Instantly share code, notes, and snippets.

@4toblerone
Created March 7, 2013 01:04
Show Gist options
  • Save 4toblerone/5104694 to your computer and use it in GitHub Desktop.
Save 4toblerone/5104694 to your computer and use it in GitHub Desktop.
class MathOpThree(object):
def sum(self, node):
if len(node.childrens) == 2:
print node.getTokenValue()
#node.setTokenValue(self.sum(node.childrens[0]).getTokenValue() + self.sum(node.childrens[1]).getTokenValue())
node.setTokenValue(self.doMathOperation(node.getTokenType(), self.sum(node.childrens[0]).getTokenValue(), self.sum(node.childrens[1]).getTokenValue()))
return node
def doMathOperation(self, mathOpString, tokenValue1, tokenValue2):
dicti = {"PLUS" : tokenValue1+tokenValue2,
"MINUS" : tokenValue1-tokenValue2,
"TIMES" : tokenValue1*tokenValue2,
"DIVIDE" : tokenValue1/tokenValue2}
return dicti[mathOpString]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment