home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / exoten / rec / calc.cnv < prev    next >
Encoding:
Text File  |  1990-07-09  |  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.     (<>,(%t,Accepts (<)arith.expr.(>) or (<)var.(>)=(<)arith.expr.(>))(%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)(%R,(1),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.             >>(%R,(1 3),MEM:v,<<
  47.                 >>(and,(itr,<-->;)<0>:,<1>)<-->;<3>,<<
  48.                 >>(%Ow,MEM:v)<1><2>;<3>,<0>:<2>;)<<
  49.             >>));
  50. )) A
  51.  
  52. [main program - open the symbol table]
  53. (()()()(
  54.     (,(P,<=>(%Ow,MEM:v,4096)));
  55. ))
  56.  
  57. [end]