[Pyparsing] Scientific Calculator - how to handle multiparameter functions
Brought to you by:
ptmcg
From: Andrew N. <and...@gm...> - 2015-12-17 04:52:11
|
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 _____________________________________ |