diff --git a/tools/python/jwutils/algo/ShuntingYard.py b/tools/python/jwutils/algo/ShuntingYard.py index 61ebf24..caaef18 100644 --- a/tools/python/jwutils/algo/ShuntingYard.py +++ b/tools/python/jwutils/algo/ShuntingYard.py @@ -27,6 +27,9 @@ class Stack: def __init__(self, itemlist=[]): self.items = itemlist + def __repr__(self): + return str(self.items) + def isEmpty(self): if self.items == []: return True @@ -45,8 +48,7 @@ class Stack: class ShuntingYard(object): # export def __init__(self, operators = None): - self.do_debug = False - #self.do_debug = True + self.do_debug = prio_gets_logged(DEBUG) self.__ops = {} if operators is not None: for k, v in operators.items(): @@ -238,7 +240,7 @@ class ShuntingYard(object): # export op = self.__ops[token] args = [] - self.debug("Adding %d arguments" % (op.nargs)) + self.debug(f'Adding {op.nargs} arguments: {vals}') for i in range(0, op.nargs): self.debug("Adding argument %d" % (i)) args.append(vals.pop()) @@ -253,7 +255,7 @@ class ShuntingYard(object): # export if not isinstance(infix, basestring): return infix postfix = self.infix_to_postfix(infix) - self.debug(infix, "-->", postfix) + self.debug(f'"{infix}" --> {postfix}') for token in postfix: self.debug("Token is %s" % (token)) return self.eval_postfix(postfix)