create a list of operator
This commit is contained in:
parent
4920bbd27d
commit
693c982cbe
@ -183,13 +183,16 @@ class Operator(str):
|
|||||||
return flatten_list([op])
|
return flatten_list([op])
|
||||||
|
|
||||||
|
|
||||||
add = Operator("+")
|
class op(object):
|
||||||
sub = Operator("-")
|
""" List of admited operations """
|
||||||
mul = Operator("*")
|
# TODO: On pourrait peut être le faire plus proprement avec des décorateurs? |mar. nov. 11 20:24:54 CET 2014
|
||||||
div = Operator("/")
|
add = Operator("+")
|
||||||
pw = Operator("^")
|
sub = Operator("-")
|
||||||
sub1 = Operator("-", 1)
|
mul = Operator("*")
|
||||||
par = Operator("(")
|
div = Operator("/")
|
||||||
|
pw = Operator("^")
|
||||||
|
sub1 = Operator("-", 1)
|
||||||
|
par = Operator("(")
|
||||||
|
|
||||||
def save_mainOp(obj, mainOp):
|
def save_mainOp(obj, mainOp):
|
||||||
"""Create a temporary class build over built-in type to stock the main operation of a calculus
|
"""Create a temporary class build over built-in type to stock the main operation of a calculus
|
||||||
|
@ -65,17 +65,13 @@ def p2i_render(token):
|
|||||||
try:
|
try:
|
||||||
return getattr(token, '__p2i__')(*args)
|
return getattr(token, '__p2i__')(*args)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return list(token)
|
return token
|
||||||
return render
|
return render
|
||||||
p2i = Render(p2i_render)
|
p2i = Render(p2i_render)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from .operator import Operator
|
from .operator import op
|
||||||
mul = Operator("*", 2)
|
exp = [ 2, 3, op.add, 4, op.mul]
|
||||||
add = Operator("+", 2)
|
|
||||||
sub1 = Operator("-", 1)
|
|
||||||
div = Operator("/", 1)
|
|
||||||
exp = [ 2, 3, add, 4, mul]
|
|
||||||
print(exp)
|
print(exp)
|
||||||
print("txt(exp) :" + str(txt(exp)))
|
print("txt(exp) :" + str(txt(exp)))
|
||||||
print("tex(exp) :" + str(tex(exp)))
|
print("tex(exp) :" + str(tex(exp)))
|
||||||
|
@ -161,12 +161,10 @@ if __name__ == '__main__':
|
|||||||
#
|
#
|
||||||
#print(in2post_fix(in_tokens))
|
#print(in2post_fix(in_tokens))
|
||||||
|
|
||||||
#a, s, m, d, p = Operator("+"), Operator("-"), Operator("*"), Operator("/"), Operator("^")
|
from .operator import op
|
||||||
#s1 = Operator("-", 1)
|
print(in2post_fix([op.par, 2, op.add, 5, op.sub, 1, ')', op.div, op.par, 3, op.mul, 4, ')']))
|
||||||
#par = Operator("(")
|
print(in2post_fix([op.sub1, op.par, op.sub1, 2, ')']))
|
||||||
#print(in2post_fix([par, 2, a, 5, s, 1, ')', d, par, 3, m, 4, ')']))
|
print(in2post_fix([op.sub1, op.par, op.sub1, 2, op.add, 3, op.mul, 4, ')']))
|
||||||
#print(in2post_fix([s1, par, s1, 2, ')']))
|
|
||||||
#print(in2post_fix([s1, par, s1, 2, a, 3, m, 4, ')']))
|
|
||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
Reference in New Issue
Block a user