josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) (04/25/91)
I folks !... I'm looking for a program in Pascal or C, that read a equation from the Keyboard and evaluate it ..... If anybody knows some please tell me .... Thanks.. Jose A. Vela A. josevela@mtecv2.mty.itesm.mx
ts@uwasa.fi (Timo Salmi) (04/25/91)
In article <3235@mtecv2.mty.itesm.mx> josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) writes: > I'm looking for a program in Pascal or C, that read a equation from the > Keyboard and evaluate it ..... > If anybody knows some please tell me .... : I'll do even better (worse :-) that that. I'll tell the whole net. Such code for Turbo Pascal has been published at least in two books, but I can remember only one ouright, that this O'Brien, Turbo Pascal, The Complete Reference, Borland-Osborne. This seems a good case of adding one more question to my FAQ collection, since this one pops up from time to time, and the reply is not trivial, and difficult to give on the fly. I've adapted such a code also myself in /pc/ts/tsfunc13.arc, but that only shows the end result. Even I try to give information otherwise, I have an ironclad rule of not releasing my source codes. ................................................................... Prof. Timo Salmi Moderating at garbo.uwasa.fi anonymous ftp archives 128.214.12.37 School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun
suhonen@kunto.jyu.fi (Timo Suhonen) (04/25/91)
josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) writes: > I'm looking for a program in Pascal or C, that read a equation from the > Keyboard and evaluate it ..... > If anybody knows some please tell me .... : About two years ago I wrote such a program. It reads a string and compiles it to dynamic list and evalutes that list (quite fast). You can set variables and use TP's build-in functions like sin, cos, ln etc. The idea is to first compile the string into dynamic list and then you can (fastly) calculate the list and give new values to variables and then again calculate... If my memory is not (badly) broken, the calculation time of the dynamic list is about 2 times longer than TP-compiled code... (it can easily be speeded up, if you need). Document?? Comments?? What are they?? Something to eat?? B-) If needed, I can put the code into garbo archive (and nic.funet.fi) for you. I won't post it because 1) I don't know how to post to bin-groups and 2) code is not too readable... If someone likes to post it later, then go on, I don't mind... I'll try to put the thing into garbo next monday, so Timo (nice name B-) can put it into a place it shoud be. I'm gonna re-write the whole thing with C++ next summer and add complex support (maybe also matrix support). If I get it working I'll surely post it! -- Timo "I am logged in, therefore I am" Suhonen suhonen@jyu.fi suhonen@euler.jyu.fi suhonen@kunto.jyu.fi suhonen@nic.funet.fi Opinions(?) are mine (if not stolen), NOT those of Univ. of Jyvaskyla.
ressler@CS.Cornell.EDU (Gene Ressler) (04/26/91)
I have recently submitted a 3d function plotter utility with TP5/TASM source that reads an expression of form F(x,y) from the command line and compiles it to a syntax tree. Then a function Eval(tree, x, y) returns the expression value. The plotter uses this to compute a `fishnet'of 31x31 values over a domain also given on the command line. On my ancient 4.77Mhz 8088 (no NCP) clone it does 961 evals of 0.25*cos(28*x^2 + 20*y^2) / (9*x^2 + 6*y^2 + 1) in 35 seconds. On a `slow' 80486 it's less than a second. Here's what it knows about (from the Usage screen): Operators by precedence: a^b - a to b power, b >= 0 or int < 0 right associative -a - negate a a*b - a times b a/b - a divided by b left associative a+b - a plus b a-b - a minus b left associative Functions: Sin(a), Cos(a), Ln(a), Exp(a), Sqrt(a), Atan(a), Abs(a), Min(a,b), Max(a,b). Case is ignored. It's easily extensible. Another place to look is at the MicroCalc spreadsheet that comes with Borland languages. As I recall it parses the expression each time it evaluates, so it will be slower. Another simple approach to compiling is in _Compilers_, Aho et.al., e.g. compile to postfix; then evaluation's a cinch. Talk about options! ;-> Gene
josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) (04/26/91)
suhonen@kunto.jyu.fi (Timo Suhonen) writes: > josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) writes: > > I'm looking for a program in Pascal or C, that read a equation from the > > Keyboard and evaluate it ..... > > If anybody knows some please tell me .... > : >About two years ago I wrote such a program. It reads a string and compiles >it to dynamic list and evalutes that list (quite fast). You can set variables >and use TP's build-in functions like sin, cos, ln etc. >If needed, I can put the code into garbo archive (and nic.funet.fi) for >you. I won't post it because 1) I don't know how to post to bin-groups and >2) code is not too readable... If someone likes to post it later, then >go on, I don't mind... Please put it in garbo !! and thank you !! Just say where is it .... Jose A. Vela A
svec5@menudo.uh.edu (T.C. Zhao) (04/26/91)
In article <3249@mtecv2.mty.itesm.mx> josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) writes: >suhonen@kunto.jyu.fi (Timo Suhonen) writes: > >> > I'm looking for a program in Pascal or C, that read a equation from the > >>About two years ago I wrote such a program. It reads a string and compiles >>it to dynamic list and evalutes that list (quite fast). You can set variables >>and use TP's build-in functions like sin, cos, ln etc. > >>If needed, I can put the code into garbo archive (and nic.funet.fi) for > Please put it in garbo !! and thank you !! The scanner and parser in GNUPLOT is pretty powerful and ready to use, it also evaluates functions with complex variables.