Commit before attempting to change the backing queue to a deque.
This commit is contained in:
+7
-17
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user