render accept ":"
This commit is contained in:
parent
bb12e67557
commit
a0dbef2946
12
render.py
12
render.py
@ -15,7 +15,7 @@ class Render(object):
|
|||||||
Those three dictionnaries while define how a postfix expression will be transform into a string.
|
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}):
|
def __init__(self, op_infix = {}, op_postfix = {}, other = {}, join = " ", type_render = {int: str, Fraction: str, FormalExp: str}):
|
||||||
"""Initiate the render
|
"""Initiate the render
|
||||||
@ -204,7 +204,7 @@ class flist(list):
|
|||||||
# ------------------------
|
# ------------------------
|
||||||
# A console render
|
# A console render
|
||||||
|
|
||||||
txt_infix = {"+": "+", "-": "-", "*": "*", "/" : "/"}
|
txt_infix = {"+": "+", "-": "-", "*": "*", "/" : "/", ":": ":"}
|
||||||
txt_postfix = {}
|
txt_postfix = {}
|
||||||
txt_other = {"(": "(", ")": ")"}
|
txt_other = {"(": "(", ")": ")"}
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ txt_render = Render(txt_infix, txt_postfix, txt_other)
|
|||||||
# ------------------------
|
# ------------------------
|
||||||
# A infix to postfix list convertor
|
# A infix to postfix list convertor
|
||||||
|
|
||||||
p2i_infix = {"+": "+", "-": "-", "*": "*", "/" : "/"}
|
p2i_infix = {"+": "+", "-": "-", "*": "*", "/" : "/", ":":":"}
|
||||||
p2i_postfix = {}
|
p2i_postfix = {}
|
||||||
p2i_other = {"(": "(", ")": ")"}
|
p2i_other = {"(": "(", ")": ")"}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ def texSlash(op1, op2):
|
|||||||
def texFrac(frac):
|
def texFrac(frac):
|
||||||
return ["\\frac{" , str(frac._num) , "}{" , str(frac._denom) , "}"]
|
return ["\\frac{" , str(frac._num) , "}{" , str(frac._denom) , "}"]
|
||||||
|
|
||||||
tex_infix = {"+": " + ", "-": " - ", "*": " \\times "}
|
tex_infix = {"+": " + ", "-": " - ", "*": " \\times ", ":": ":"}
|
||||||
tex_postfix = {"/": texSlash}
|
tex_postfix = {"/": texSlash}
|
||||||
tex_other = {"(": "(", ")": ")"}
|
tex_other = {"(": "(", ")": ")"}
|
||||||
tex_type_render = {int: str, Fraction: texFrac, FormalExp: str}
|
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__':
|
if __name__ == '__main__':
|
||||||
exp = [2, 5, '+', 1, '-', 3, 4, '*', '/']
|
exp = [2, 5, '+', 1, '-', 3, 4, '*', ':']
|
||||||
print(txt_render(exp))
|
print(txt_render(exp))
|
||||||
exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, '+']
|
exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, 5, '/', ':']
|
||||||
print(tex_render(exp))
|
print(tex_render(exp))
|
||||||
exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, '+']
|
exp = [2, 5, '+', 1, '-', 3, 4, '*', '/', 3, '+']
|
||||||
print(post2in_fix(exp))
|
print(post2in_fix(exp))
|
||||||
|
Loading…
Reference in New Issue
Block a user