create a list of operator
This commit is contained in:
parent
4920bbd27d
commit
693c982cbe
@ -183,6 +183,9 @@ class Operator(str):
|
|||||||
return flatten_list([op])
|
return flatten_list([op])
|
||||||
|
|
||||||
|
|
||||||
|
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("+")
|
add = Operator("+")
|
||||||
sub = Operator("-")
|
sub = Operator("-")
|
||||||
mul = Operator("*")
|
mul = Operator("*")
|
||||||
|
@ -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