home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / mouse-ex.lbr / INFIX.MZE / INFIX.MSE
Encoding:
Text File  |  1993-02-22  |  1.1 KB  |  49 lines

  1.  
  2. ~ Expression evaluation. Peter Grogono  7/9/84
  3.  
  4. ~ 7/15/84  Removed cursor logic
  5.  
  6. "!Enter expressions like 15 * (234 - 34). Press RETURN at the!"
  7. "end of your expression.
  8.  
  9. To leave this program, enter a single period.!"
  10.  
  11. ("!:"  #G,c;  1 c. '. = - ^
  12.   #E,c;"!"!
  13. )
  14.  
  15. $E #T,1%;                         ~ Evaluate an expression
  16.    1%. '+ =
  17.      [ #G,1%;#E,1%;+@]
  18.    1%. '- =
  19.      [ #G,1%;#E,1%;-@] @
  20.  
  21. $T #F,1%;                         ~ Evaluate a term
  22.    1%. '* =
  23.      [ #G,1%;#T,1%;*@]
  24.    1%. '/ =
  25.      [ #G,1%;#T,1%;/@]
  26.    1%. '\ =
  27.      [ #G,1%;#T,1%;\@] @
  28.  
  29. $F #D,1%;                         ~ Evaluate a factor
  30.      [ #N,1%;@]
  31.    1%. '( =
  32.      [ #G,1%;#E,1%;
  33.        1%. ') =
  34.          [ #G,1%;@]
  35.        "!) expected" @]
  36.     " Illegal character!:" 0 @
  37.  
  38. $N 1%. '0 -                       ~ Convert digit string to number
  39.    ( #G,1%; #D,1%; ^
  40.      10 * 1%. '0 - + ) @
  41.  
  42. $D 1%. x:                         ~ Digit test
  43.    x. '0 1 - >
  44.    x. '9 1 + < * @
  45.  
  46. $G (?' x: x. ' = ^ )              ~ Get a non-blank character
  47.    x. 1%: @
  48.  
  49.