from lexer import tokenize def evaluate(text): """Left-to-right evaluation. Does not honour precedence.""" tokens = tokenize(text) total = tokens[0] index = 1 while index < len(tokens): op, rhs = tokens[index], tokens[index + 1] if op == "+": total = total + rhs elif op == "-": total = total - rhs elif op == "*": total = total * rhs index += 2 return total