home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sources / wanted / 3986 < prev    next >
Encoding:
Text File  |  1992-08-17  |  2.2 KB  |  60 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.92Aug17105309@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@amy.tch.harvard.edu  (John E. Davis)
  9. Organization: "Dept. of Physics, The Ohio State University"
  10. Date: Mon, 17 Aug 1992 15:53:09 GMT
  11. Lines: 47
  12.  
  13.  
  14. [ I posted this to comp.sources.wanted but it is not clear to me who reads
  15.   such a group; I suspect that I will do much better here. ]
  16.         
  17. Hi,
  18.  
  19.    I am looking for an extensible interpreter (preferably in C). I want an
  20. interpreter which has all the code in it for while loops, if then statements,
  21. etc.  All I need to do is to add the `intrinsic' (in C) functions which the
  22. interpreter will eventually call.  This seems like such a useful generic thing
  23. that someone must have done it already.  If such a thing exists, I would
  24. appreciate about hearing about it.
  25.  
  26.    I wrote something like this for a stack based calculator a year ago. But
  27. since I wrote it from scratch I suspect it is not very elegant and it is
  28. probably slow. The calculator lets the user to define variable and functions.
  29. This calculator also allows looping and conditional branching.  For exaample,
  30. here is the code for the factorial function in the calculator language:
  31.  
  32. ( dup 1 -  ;; entry stack consists of [n-1, n,...]
  33.  
  34.       {
  35.          dup 2 exchn   ;; bury a copy for later pulling product to top
  36.          *
  37.          exch          ;; perform product and exchange for buried copy
  38.          1 -           ;; decrement and loop until this goes 0 or negative
  39.          
  40.       } while          ;; while always removes top element upon exiting
  41. ) !
  42.  
  43.  
  44. The syntax for the function definition is
  45.  
  46.    ( statement_1 statement_2 ... statement_n ) function_name
  47.  
  48.  (By the way, if there is want the source code for this calculator, let me know
  49. and I will post it.  The C soource is only 650 lines long.)
  50.  
  51. Thanks,
  52. --
  53.      _____________
  54. #___/John E. Davis\_________________________________________________________
  55. #
  56. # internet: davis@amy.tch.harvard.edu
  57. #   bitnet: davis@ohstpy
  58. #   office: 617-735-6746
  59. #
  60.