home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19361 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.3 KB  |  35 lines

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