26 lines
836 B
Python
26 lines
836 B
Python
import token
|
|
|
|
def calculate_results(tokens):
|
|
|
|
return 0
|
|
|
|
def peek_list(tokens):
|
|
if tokens:
|
|
return tokens[-1]
|
|
else:
|
|
raise IndexError("The token list is empty.", tokens)
|
|
|
|
def operate(n1, n2, tokenType):
|
|
if tokenType == token.TokenType.add:
|
|
print("Adding %d and %d to get %d." %(n1, n2, n1 + n2))
|
|
elif tokenType == token.TokenType.subtract:
|
|
print("Subtracting %d and %d to get %d." %(n1, n2, n1 - n2))
|
|
elif tokenType == token.TokenType.multiply:
|
|
print("Multiplying %d and %d to get %d" %(n1, n2, n1 * n2))
|
|
elif tokenType == token.TokenType.divide:
|
|
print("Dividing %d and %d to get %d" %(n1, n2, n1 / n2))
|
|
elif tokenType == token.TokenType.power:
|
|
print("Raising %d to the power of %d to get %d" %(n1, n2, n1**n2))
|
|
else:
|
|
raise TypeError("Invalid operator value " + str(tokenType) + ".", tokenType)
|