From c6d063ea35b03dcd00c5244579ad3c9b7c17ebe9 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 24 Apr 2020 00:20:26 -0500 Subject: [PATCH] Commit before attempting to change the backing queue to a deque. --- calc_engine.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/calc_engine.py b/calc_engine.py index c2162b5..2a29ab9 100644 --- a/calc_engine.py +++ b/calc_engine.py @@ -1,8 +1,8 @@ import ptoken import tokenizer import queue -import deque import copy +import collections.deque debug = True @@ -13,28 +13,22 @@ def calculate_results(tokens): return process_tokens(q, True) def process_tokens(tokens, top_level = False): - pending_operations = []#queue.Queue() - power = 0 + pending_operations = [] running_total = 0 + power = 0 p_ops_ran = False while True: if tokens.empty(): break - + tokenizer.print_token_list(pending_operations) token = tokens.get() if not top_level and token.type == ptoken.TokenType.exp_end: - - - #if look_ahead.popleft().type == ptoken.TokenType.power: - # power = float(look_ahead.value) - break if token.type == ptoken.TokenType.exp_start: tmp = process_tokens(tokens) - pending_operations.append(ptoken.Token(tmp, ptoken.TokenType.constant)) elif token.type == ptoken.TokenType.power: @@ -65,7 +59,7 @@ def process_tokens(tokens, top_level = False): pending_operations = [] pending_operations.append(previous_token) pending_operations.append(token) - tokenizer.print_token_list(pending_operations) + #tokenizer.print_token_list(pending_operations) p_ops_ran = False elif token.type == ptoken.TokenType.constant: @@ -85,13 +79,9 @@ def process_tokens(tokens, top_level = False): pending_operations.append(ptoken.Token(running_total, ptoken.TokenType.constant)) p_ops_ran = True - tokenizer.print_token_list(pending_operations) + #tokenizer.print_token_list(pending_operations) - if power > 0: - running_total = handle_pending(convert_to_queue(pending_operations)) - - running_total = operate(running_total, power, ptoken.TokenType.power) - elif len(pending_operations) > 0: + if len(pending_operations) > 0: running_total = handle_pending(convert_to_queue(pending_operations)) return running_total