[comp.lang.c] Wanted: Expression Evaluator

ssdken@jarthur.Claremont.EDU (Ken Nelson) (02/14/90)

Hi:

   I need the C source for an expression evaluator. Something that can
   understand things like this:

      A/B*LOG(D)


   The evaluator would get A B and D from a symbol table, evaluate the 
   expression and return the result.

   Anybody have such a beast????


			Thanks,


				Ken Nelson
				Principal Engineer
				Software Systems Design
				3627 Padua Av.
				Claremont, CA 91711
				(714) 624-3402

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (02/19/90)

In article <4365@jarthur.Claremont.EDU> ssdken@jarthur.Claremont.EDU (Ken Nelson) writes:
>Hi:
>
>   I need the C source for an expression evaluator. Something that can
>   understand things like this:
>
>      A/B*LOG(D)
>
>
>   The evaluator would get A B and D from a symbol table, evaluate the 
>   expression and return the result.
>
>   Anybody have such a beast????
>
>
>			Thanks,
>
>
>				Ken Nelson
>				Principal Engineer
>				Software Systems Design
>				3627 Padua Av.
>				Claremont, CA 91711
>				(714) 624-3402
I have the guts of two, one an interpreter, one a compiler. The
compiler requires that your machine be able to execute data - 
many Unixes are seriously deficient in this regard. And, of
course, you have to put in the opcodes for your computer if you
want the compiler. The presently finished ones assume doubles. 
They have a very limited hard-coded set of symbols, but adding a 
symbol table lookup is trivial -  except, of course, you have to 
code in the symbol table at compile time. These will evaluate an 
expression of arbitrary complexity by recursive descent. They have
a fairly good syntax checker.

Interestingly, the code is amazingly small.

Send me e-mail if interested.

Doug McDonald (mcdonald@aries.scs.uiuc.edu)

root@cca.ucsf.edu (Systems Staff) (02/21/90)

In article <4365@jarthur.Claremont.EDU>, ssdken@jarthur.Claremont.EDU (Ken Nelson) writes:
> 
>    I need the C source for an expression evaluator. Something that can
>    understand things like this:
> 
>       A/B*LOG(D)
> ...
>    Anybody have such a beast????

You might look at the Basic interpreter in volume 7 of comp.sources.unix
with a view toward extracting the expression evaluator.

 Thos Sumner       Internet: thos@cca.ucsf.edu
 (The I.G.)        UUCP: ...ucbvax!ucsfcgl!cca.ucsf!thos
                   BITNET:  thos@ucsfcca

 U.S. Mail:  Thos Sumner, Computer Center, Rm U-76, UCSF
             San Francisco, CA 94143-0704 USA

I hear nothing in life is certain but death and taxes -- and they're
working on death.

#include <disclaimer.std>

CMH117@psuvm.psu.edu (Charles Hannum) (02/22/90)

>In article <4365@jarthur.Claremont.EDU> ssdken@jarthur.Claremont.EDU (Ken
>Nelson) writes:
>>Hi:
>>
>>   I need the C source for an expression evaluator. Something that can
>>   understand things like this:
>>
>>      A/B*LOG(D)
>>
>>
>>   The evaluator would get A B and D from a symbol table, evaluate the
>>   expression and return the result.
>>
>>   Anybody have such a beast????

I have an O(n) parser that I think will do what you want.  It uses a stack-
based algorithm which I invented and later discovered that I was not the first
to do so ...  <sigh>


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117@psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h@psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."