Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!ncar!gatech!udel!rochester!cornell!ressler From: ressler@CS.Cornell.EDU (Gene Ressler) Newsgroups: comp.binaries.ibm.pc.d Subject: Re: Program that evaluates equations .. Message-ID: <1991Apr26.011825.21068@cs.cornell.edu> Date: 26 Apr 91 01:18:25 GMT References: <3235@mtecv2.mty.itesm.mx> <1991Apr25.114053.8398@uwasa.fi> Sender: news@cs.cornell.edu (USENET news user) Followup-To: ressler@cs.cornell.edu Organization: Cornell Univ. CS Dept, Ithaca NY 14853 Lines: 29 Nntp-Posting-Host: turing1.cs.cornell.edu 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