home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / REC.ZIP / CALC.CNV < prev    next >
Encoding:
Text File  |  1986-12-01  |  1.5 KB  |  57 lines

  1. [CALC.CNV]
  2. [G. Cisneros, 9.7.85]
  3. [Include #.#^#%]
  4. [[Calculator: accepts <arith. expr.> or <var.>=<arith. expr.>]]
  5.  
  6. [main routine: parses the line given to it]
  7. ((
  8.     ((IVL,0,9,)) d                [digit]
  9.     (<:d:>(ITR,<:d:>)) i            [integer]
  10.     ((or,<:i:>.<:i:>,<:i:>.,.<:i:>)) r    [real]
  11.     ((or,+,-,)) s                [optional sign]
  12.     ((or,E,D,e,d)<:s:><:i:>) D        [exponent of 10]
  13.     ((or,<:r:>,<:i:>)(or,<:D:>,)) n        [number]
  14.     ((or,(IVL,A,Z,),(IVL,a,z,))) l        [letter]
  15.     ((or,<:d:>,<:l:>)) a            [alphanumeric]
  16.     (<:l:>(ITR,<:a:>)) v            [variable]
  17.     ((or,<:n:>,<:v:>,<(><:e:><)>)) p    [operand]
  18.     ((or,+,-,**,*,/,^,%)) o            [operator]
  19.     (<:s:><:p:>(ITR,<:o:><:p:>)) e        [expression]
  20. )()(0 1)(
  21.     (<>,(%Q)(%R)):
  22.     ((^Z),);
  23.     ((and,<:v:>,<0>)=(and,<:e:>,<1>)<>,(A,(V,<1>))(%R)):
  24.     (<:e:><>,(%t,(V,<=>))(%R)):
  25.     ((or,<:v:>=,)(or,<:e:>,)<1>,(%t,<1> not recognized)(%R)):
  26. )) P
  27.  
  28. [evaluate an expression]
  29. ((
  30.     ((or,<:n:>,<(><:e:><)>)) p        [operand, no variables]
  31. )()(0 1 2)(
  32.     (<:e:><>,(#f,(&u,<=>)));
  33.     ((and,<:v:>,<0>)<1>,(F)<1>):
  34.     ((and,<-->(or,<(>,<:o:>)<:v:>,<1><:v:>,<1><0>)<2>,<1>(F)<2>):
  35. )) V
  36.  
  37. [fetch a variable's value]
  38. (()()()(
  39.     (,(,(%Or,MEM:v))(LAM,(1),(%R,MEM:v,(itr,<-->;)<0>:<1>;,<1>,0)));
  40. )) F
  41.  
  42. [assign a value to a variable]
  43. (()()(2)(
  44.     (<2>,(,(%Or,MEM:v))<<
  45.         >>(%W,MEM:v,<<
  46.             >>(LAM,(1 3),(%R,MEM:v,<<
  47.                 >>(and,(itr,<-->;)<0>:,<1>)<-->;<3>,<<
  48.                 >><1><2>;<3>,<=><0>:<2>;))<<
  49.             >>(,(%Ow,MEM:v))));
  50. )) A
  51.  
  52. [main program - open the symbol table]
  53. (()()()(
  54.     (,(P,<=>(,(%Ow,MEM:v,2048))));
  55. ))
  56.  
  57. [end]