home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sources / wanted / 3976 < prev    next >
Encoding:
Text File  |  1992-08-16  |  2.1 KB  |  56 lines

  1. Newsgroups: comp.sources.wanted
  2. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!pacific.mps.ohio-state.edu!davis
  3. From: davis@pacific.mps.ohio-state.edu ("John E. Davis")
  4. Subject: generic interpreter
  5. Message-ID: <DAVIS.92Aug16160709@pacific.mps.ohio-state.edu>
  6. Sender: news@pacific.mps.ohio-state.edu
  7. Nntp-Posting-Host: pacific.mps.ohio-state.edu
  8. Reply-To: davis@pacific.mps.ohio-state.edu  (John E. Davis)
  9. Organization: "Dept. of Physics, The Ohio State University"
  10. Date: Sun, 16 Aug 1992 21:07:09 GMT
  11. Lines: 43
  12.  
  13. Hi,
  14.  
  15.    I am looking for an extensible interpreter (preferably in C). I want an
  16. interpreter which has all the code in it for while loops, if then statements,
  17. etc.  All I need to do is to add the `intrinsic' (in C) functions which the
  18. interpreter will eventually call.  This seems like such a useful generic thing
  19. that someone must have done it already.  If such a thing exists, I would
  20. appreciate about hearing about it.
  21.  
  22.    I wrote something like this for a stack based calculator a year ago. But
  23. since I wrote it from scratch I suspect it is not very elegant and it is
  24. probably slow. The calculator lets the user to define variable and functions.
  25. This calculator also allows looping and conditional branching.  For exaample,
  26. here is the code for the factorial function in the calculator language:
  27.  
  28. ( dup 1 -  ;; entry stack consists of [n-1, n,...]
  29.  
  30.       {
  31.          dup 2 exchn   ;; bury a copy for later pulling product to top
  32.          *
  33.          exch          ;; perform product and exchange for buried copy
  34.          1 -           ;; decrement and loop until this goes 0 or negative
  35.          
  36.       } while          ;; while always removes top element upon exiting
  37. ) !
  38.  
  39.  
  40. The syntax for the function definition is
  41.  
  42.    ( statement_1 statement_2 ... statement_n ) function_name
  43.  
  44.  (By the way, if there is want the source code for this calculator, let me know
  45. and I will post it.  The C soource is only 650 lines long.)
  46.  
  47. Thanks,
  48. --
  49.      _____________
  50. #___/John E. Davis\_________________________________________________________
  51. #
  52. # internet: davis@amy.tch.harvard.edu
  53. #   bitnet: davis@ohstpy
  54. #   office: 617-735-6746
  55. #
  56.