Re: [Pyparsing] Scientific Calculator - how to handle multiparameter functions
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2015-12-17 10:17:40
|
Hm, interesting approach, to make the function an operator. For your list of args, the operator is not a delimited list, it is just the ',' symbol itself. Try adding this to your infixNotation call, before fnop: (',', 2, opAssoc.LEFT, lambda t: tuple(t[::2]) if len(t)>1 else t[0]), Totally untested. Good luck! -- Paul -----Original Message----- From: Andrew Nelson [mailto:and...@gm...] Sent: Wednesday, December 16, 2015 10:52 PM To: pyp...@li... Subject: [Pyparsing] Scientific Calculator - how to handle multiparameter functions Dear pyparsing users, I'm attempting to make a fully functional scientific calculator by expanding on some example code I found on the pyparsing wiki. The code I have so far is at: http://pastebin.com/aAPri29k I have managed to get the calculator to do things along the lines of: >>> vars_={'A': 0, 'B': 1.1, 'C': 2.2, 'D': 3.3, 'E': 4.4, 'F': 5.5, 'G': 6.6, 'H':7.7, 'I':8.8, 'J':9.9, "abc": 20} >>> arith = Arith( vars_ ) >>> arith.eval("1+2*sin(B)*2") 4.564829440245742 So far so good. However, I would now like to use functions which have more that one parameter, e.g. math.pow or math.atan2. I've been trying all day to add this kind of functionality, but failing miserably. I've mainly been experimenting with delimitedList: listop = delimitedList(operand) and adding this listop to the infixNotation call. Can anyone inform me if there is a simple solution? I'm a total novice at parsing. regards, Andrew. _____________________________________ Dr. Andrew Nelson _____________________________________ ---------------------------------------------------------------------------- -- _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus |