Created
March 7, 2013 01:04
-
-
Save 4toblerone/5104694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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