I my opinion it is much easier to implement a sort of RPN calc for that. Also if you have a PC connected to the circuit you may want to do that on the PC side generating a pcode (with converting the normal form to RPN and do all possible pre-calculations) so then the PIC needs only a much lighter pcode engine rather than a more complex parser. Tamas On Thu, Apr 23, 2009 at 12:54 PM, Isaac Marino Bavaresco < isaacbavaresco@yahoo.com.br> wrote: > Nice code! > > Out of curiosity I downloaded your code and tried to compile with > Hi-Tech PICC. > > The function 'calc_number' calls itself recursively because of the NOT > operator, so I commented it out. I had to do other minor PIC specific > changes. > > Compiled and run OK. > > Occupied 2087 words of FLASH and 140 bytes of RAM in a PIC16F648A. > > It calculates "(123+234)*34" in 11.89ms @ 20MHz. > > Regards, > > Isaac > > > M. Adam Davis escreveu: > > It took me a lot longer to find mine than I expected! I posted one > > simple equation parser here: > > > > http://www.ubasics.com/simple_c_equation_parser > > > > The code and compiled test executable (windows) can also be > > downloaded, http://www.ubasics.com/files/equation.zip > > > > It uses a stack method with no operator precedence. It handles binary > > operators (+, -, *, /, |, &, ^), unary operators(!), parenthesis((,)), > > and numbers. Parenthesis can be used to force precedence, everything > > else is strictly left to right evaluation. > > > > You'll need to add < and > binary operators (and, or, not, xor, > > already exist), and you'll need to either add symbols to represent > > your inputs, or modify the parse routine to accept characters and use > > the correct variable when a word occurs in the equation. > > > > You'll also need to instruct users to use parenthesis rigorously: > > > > T1>T2&T1>72 becomes (T1>T2)&(T1>72) > > T1>T2+5&T2<32 becomes (T1>(T2+5))&(T2<32) > > > > The program I posted compiles under tcc (tiny c compiler) and should > > be standard ansi C, so it ought to port fine. Of course you'll need > > to remove the example main() at the bottom, and perhaps the odd > > debugging printf scattered through the code (I believe they are all > > commented out...). > > > > Good luck, let me know how it works out, and if you do add the ability > > to use variables and <, > operators, feel free to send me the code and > > I'll drop it on the website for others. > > > > -Adam > > > > On Wed, Apr 22, 2009 at 9:26 PM, Forrest W Christian > wrote: > > > >> I've got a temperature control application where I'd like to be able to > >> let the customers enter expressions (via serial) like: > >> > >> T1>T2&T1>72 > >> > >> or > >> > >> T1>T2+5&T2<32 > >> > >> Where T1 and T2 are temperature readings from a thermocouple. The > >> result of these expressions will be used to turn on and off fans and/or > >> heaters in an application I am working on. I could hardcode a lot of > >> options, but I think some simple customer-modfiable rules would be best > >> in this particular application. > >> > >> So, before I write my own parser and the like I figured I'd ask if > >> there's code out there which would be suited for this, and is small (t= he > >> target is a PIC16F886 and CCS C - and it's not easy to change it in th= is > >> application). > >> > >> I've found some example code but it's all overly big and not well suit= ed > >> to what I'm looking for. I know how to write this myself, but I'd > >> rather just use some existing code - or perhaps hear some other ideas. > >> > >> Oh, I really only need a few variables (I'll probably use TA, TB inste= ad > >> of T1, T2 just to simplify parsing), a few boolean functions (and, or, > >> greater than, less than, maybe >=3D or <=3D), and possibly addition, > >> subtraction, and less possibly multiplication and/or division. > >> > >> -forrest > > __________________________________________________ > Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger > http://br.beta.messenger.yahoo.com/ > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.mcuhobby.com -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist