diff --git a/render.py b/render.py index 995f430..a93112f 100644 --- a/render.py +++ b/render.py @@ -15,7 +15,7 @@ class Render(object): Those three dictionnaries while define how a postfix expression will be transform into a string. """ - PRIORITY = {"*" : 3, "/": 3, "+": 2, "-":2, "(": 1} + PRIORITY = {"*" : 3, "/": 3, ":": 3, "+": 2, "-":2, "(": 1} def __init__(self, op_infix = {}, op_postfix = {}, other = {}, join = " ", type_render = {int: str, Fraction: str, FormalExp: str}): """Initiate the render @@ -204,7 +204,7 @@ class flist(list): # ------------------------ # A console render -txt_infix = {"+": "+", "-": "-", "*": "*", "/" : "/"} +txt_infix = {"+": "+", "-": "-", "*": "*", "/" : "/", ":": ":"} txt_postfix = {} txt_other = {"(": "(", ")": ")"} @@ -213,7 +213,7 @@ txt_render = Render(txt_infix, txt_postfix, txt_other) # ------------------------ # A infix to postfix list convertor -p2i_infix = {"+": "+", "-": "-", "*": "*", "/" : "/"} +p2i_infix = {"+": "+", "-": "-", "*": "*", "/" : "/", ":":":"} p2i_postfix = {} p2i_other = {"(": "(", ")": ")"} @@ -232,7 +232,7 @@ def texSlash(op1, op2): def texFrac(frac): return ["\\frac{" , str(frac._num) , "}{" , str(frac._denom) , "}"] -tex_infix = {"+": " + ", "-": " - ", "*": " \\times "} +tex_infix = {"+": " + ", "-": " - ", "*": " \\times ", ":": ":"} tex_postfix = {"/": texSlash} tex_other = {"(": "(", ")": ")"} tex_type_render = {int: str, Fraction: texFrac, FormalExp: str} @@ -242,9 +242,9 @@ tex_render = Render(tex_infix, tex_postfix, tex_other, type_render = tex_type_re if __name__ == '__main__': - exp = [2, 5, '+', 1, '-', 3, 4, '*', '/'] + exp = [2, 5, '+', 1, '-', 3, 4, '*', ':'] print(txt_render(exp)) - exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, '+'] + exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, 5, '/', ':'] print(tex_render(exp)) exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, '+'] print(post2in_fix(exp))