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])
|
||||
|
||||
|
||||
add = Operator("+")
|
||||
sub = Operator("-")
|
||||
mul = Operator("*")
|
||||
div = Operator("/")
|
||||
pw = Operator("^")
|
||||
sub1 = Operator("-", 1)
|
||||
par = Operator("(")
|
||||
class op(object):
|
||||
""" List of admited operations """
|
||||
# TODO: On pourrait peut être le faire plus proprement avec des décorateurs? |mar. nov. 11 20:24:54 CET 2014
|
||||
add = Operator("+")
|
||||
sub = Operator("-")
|
||||
mul = Operator("*")
|
||||
div = Operator("/")
|
||||
pw = Operator("^")
|
||||
sub1 = Operator("-", 1)
|
||||
par = Operator("(")
|
||||
|
||||
def save_mainOp(obj, mainOp):
|
||||
"""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:
|
||||
return getattr(token, '__p2i__')(*args)
|
||||
except AttributeError:
|
||||
return list(token)
|
||||
return token
|
||||
return render
|
||||
p2i = Render(p2i_render)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from .operator import Operator
|
||||
mul = Operator("*", 2)
|
||||
add = Operator("+", 2)
|
||||
sub1 = Operator("-", 1)
|
||||
div = Operator("/", 1)
|
||||
exp = [ 2, 3, add, 4, mul]
|
||||
from .operator import op
|
||||
exp = [ 2, 3, op.add, 4, op.mul]
|
||||
print(exp)
|
||||
print("txt(exp) :" + str(txt(exp)))
|
||||
print("tex(exp) :" + str(tex(exp)))
|
||||
|
@ -161,12 +161,10 @@ if __name__ == '__main__':
|
||||
#
|
||||
#print(in2post_fix(in_tokens))
|
||||
|
||||
#a, s, m, d, p = Operator("+"), Operator("-"), Operator("*"), Operator("/"), Operator("^")
|
||||
#s1 = Operator("-", 1)
|
||||
#par = Operator("(")
|
||||
#print(in2post_fix([par, 2, a, 5, s, 1, ')', d, par, 3, m, 4, ')']))
|
||||
#print(in2post_fix([s1, par, s1, 2, ')']))
|
||||
#print(in2post_fix([s1, par, s1, 2, a, 3, m, 4, ')']))
|
||||
from .operator import op
|
||||
print(in2post_fix([op.par, 2, op.add, 5, op.sub, 1, ')', op.div, op.par, 3, op.mul, 4, ')']))
|
||||
print(in2post_fix([op.sub1, op.par, op.sub1, 2, ')']))
|
||||
print(in2post_fix([op.sub1, op.par, op.sub1, 2, op.add, 3, op.mul, 4, ')']))
|
||||
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
Loading…
Reference in New Issue
Block a user