home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / grs / g / calc < prev    next >
Encoding:
Text File  |  1991-08-17  |  535 b   |  23 lines

  1. (* calc - the world's smallest string / integer expression evaluator
  2.    n.b. independent of type read in *)
  3. (* supports integers, strings, lists of
  4.   + - / * :: or and not head tail mid len
  5. *)
  6. (* Guy Verbist 1991 *)
  7.  
  8.  
  9. null function calc()
  10. {
  11.    let string s := "";
  12.    string s_to_eval;
  13.    loop
  14.       write("?-> ");
  15.       read(s);
  16.       exiton( (s="quit") or (s="end") or (s="exit") or (s = "q") or (s="x"));
  17.       s_to_eval := "write(\"Answer is : \",eval({" + s + "}),\"\n\");";
  18.       exec(compile(s_to_eval));
  19.    endloop;
  20. };
  21.  
  22. calc();
  23.