home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!netnews!bandy
- From: bandy@netnews.jhuapl.edu (Mike Bandy)
- Subject: Re: How can you evaluate an arbitrary function?
- Message-ID: <C0Ht1z.DG9@netnews.jhuapl.edu>
- Organization: JHU/Applied Physics Laboratory
- References: <1993Jan6.202453.8630@news.tufts.edu>
- Date: Thu, 7 Jan 1993 16:41:59 GMT
- Lines: 24
-
- slahiri@jade.tufts.edu (Sandip Lahiri) writes:
-
- >Suppose you have to write a program which would accept any arbitrary
- >function f(x) and calculate its values for x = ... . The program has
- >to be written in C. How would you go about it ? Note, common lisp
- >does have the eval primitive and this task is considerably easier
- >if the program is written in lisp. Should you write a parser first to
- >check the input ? Remember we can have a function nested to any
- >arbitrary depth e.g. f(x) = tan(tanx + sin(cos(sinx + x^2)) + 5).
- >Any help/pointers most welcome.
- >Thanx in advance.
-
- I'd start by writing a Lisp interpreter! ;)
-
- Really, I suggest you find a compiler book and look at a recursive
- descent solution. You probably want to look at the functions involved
- with scanning and tokenizing the input, too. Or you could convert to
- postfix notation and use a stack to evaluate it.
-
- --
-
- Mike Bandy
- bandy@aplcomm.jhuapl.edu
- Johns Hopkins University / Applied Physics Lab
-