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 ptoken
|
||||||
import tokenizer
|
import tokenizer
|
||||||
import queue
|
import queue
|
||||||
import deque
|
|
||||||
import copy
|
import copy
|
||||||
|
import collections.deque
|
||||||
|
|
||||||
debug = True
|
debug = True
|
||||||
|
|
||||||
@@ -13,28 +13,22 @@ def calculate_results(tokens):
|
|||||||
return process_tokens(q, True)
|
return process_tokens(q, True)
|
||||||
|
|
||||||
def process_tokens(tokens, top_level = False):
|
def process_tokens(tokens, top_level = False):
|
||||||
pending_operations = []#queue.Queue()
|
pending_operations = []
|
||||||
power = 0
|
|
||||||
running_total = 0
|
running_total = 0
|
||||||
|
power = 0
|
||||||
p_ops_ran = False
|
p_ops_ran = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if tokens.empty():
|
if tokens.empty():
|
||||||
break
|
break
|
||||||
|
tokenizer.print_token_list(pending_operations)
|
||||||
token = tokens.get()
|
token = tokens.get()
|
||||||
|
|
||||||
if not top_level and token.type == ptoken.TokenType.exp_end:
|
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
|
break
|
||||||
|
|
||||||
if token.type == ptoken.TokenType.exp_start:
|
if token.type == ptoken.TokenType.exp_start:
|
||||||
tmp = process_tokens(tokens)
|
tmp = process_tokens(tokens)
|
||||||
|
|
||||||
pending_operations.append(ptoken.Token(tmp, ptoken.TokenType.constant))
|
pending_operations.append(ptoken.Token(tmp, ptoken.TokenType.constant))
|
||||||
|
|
||||||
elif token.type == ptoken.TokenType.power:
|
elif token.type == ptoken.TokenType.power:
|
||||||
@@ -65,7 +59,7 @@ def process_tokens(tokens, top_level = False):
|
|||||||
pending_operations = []
|
pending_operations = []
|
||||||
pending_operations.append(previous_token)
|
pending_operations.append(previous_token)
|
||||||
pending_operations.append(token)
|
pending_operations.append(token)
|
||||||
tokenizer.print_token_list(pending_operations)
|
#tokenizer.print_token_list(pending_operations)
|
||||||
p_ops_ran = False
|
p_ops_ran = False
|
||||||
|
|
||||||
elif token.type == ptoken.TokenType.constant:
|
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))
|
pending_operations.append(ptoken.Token(running_total, ptoken.TokenType.constant))
|
||||||
p_ops_ran = True
|
p_ops_ran = True
|
||||||
|
|
||||||
tokenizer.print_token_list(pending_operations)
|
#tokenizer.print_token_list(pending_operations)
|
||||||
|
|
||||||
if power > 0:
|
if len(pending_operations) > 0:
|
||||||
running_total = handle_pending(convert_to_queue(pending_operations))
|
|
||||||
|
|
||||||
running_total = operate(running_total, power, ptoken.TokenType.power)
|
|
||||||
elif len(pending_operations) > 0:
|
|
||||||
running_total = handle_pending(convert_to_queue(pending_operations))
|
running_total = handle_pending(convert_to_queue(pending_operations))
|
||||||
|
|
||||||
return running_total
|
return running_total
|
||||||
|
|||||||
Reference in New Issue
Block a user