home *** CD-ROM | disk | FTP | other *** search
- /*
- USING CALC
-
- CALC is a simple quite sophisticated calculator program which
- allows you to carry out all sorts of numerical calculations
- using algebraic format. If you type a line like
- 2**4
- then CALC will define a variable ans and set it equal to the
- result of the calculation. If however you type
- X = 2**4*SIN(14)
- then the variable X will become defined and will be set
- equal to the numerical result of the computation.
- All of the special functions in the ieee library can be called
- from inside of calc; e.g., sin(), cos(), tan(), asin(), acos(),
- exp(), sinh(), etc.
- If you call a function (i.e. use sin()) then CALC recognizes
- the () and doesn't set ans equal to the result of the call.
- In this case it will return the value and give an error message.
- To avoid the message always set the result of a function call
- equal to something; e.g.,
- PI = 2*ACOS(0)
-
- By default calc echos all commands typed. If you want to turn
- this feature off say ECHO OFF. To restore it type ECHO ON.
- To define a rexx function which can be called from CALC say
- EDIT (synonym PROGRAM) and you will be thrown into TxEd Plus.
- Type the rexx program and file it under the name you want;
- for example, rexx:foo.rexx .
- When you exit the editor you will be back in CALC.
-
- To leave CALC type QUIT.
- */
- arg x
-
- if x = ? then do
- y = sourceline(2)
- line = ""
- do i = 3 until y = "*/"||'0a'x
- line = line||y
- y = sourceline(i)
- end
- say line
- exit
- end
-
-
- START:
- SIGNAL ON ERROR
- SIGNAL ON SYNTAX
- address command
-
- OPTIONS FAILAT 30
- echo = 1
- do i = 1
- call open('CALCWIN','con:0/0/400/400//')
- call writech(CALCWIN,"? ")
- equation = readln(CALCWIN)
- equalloc = index(equation,"=")
- parloc = index(equation,"(")
- ifloc = index(equation, "IF ")
- select
-
- when equation = "QUIT" | equation = "quit" then exit 0
- when ifloc ~=0 then interpret equation
- when equation = "EDIT" | equation = "edit" then "runwsh e"
- when equation = "" then iterate
- when equalloc = 0 then do
- if equation = "ECHO OFF" then do
- echo = 0
- iterate
- end
- if equation = "ECHO ON" then do
- echo = 1
- iterate
- end
- if parloc ~=0 then do
- interpret equation
- iterate
- end
- interpret "ans = "equation
- ansstring = equation" = "ans
- call writeln(CALCWIN," "ansstring)
- end
- otherwise do
- parse var equation leftside "=" rightside
- INTERPRET "ans = "rightside
- if echo = 1 then call writeln(CALCWIN," "leftside" = "ans)
- INTERPRET leftside" = "rightside
- end
- end
- end
- exit
- ERROR:
- if rc > 0 then call writeln(CALCWIN,"you made a mistake")
- SIGNAL VALUE START
- SYNTAX:
- call writeln(CALCWIN,"you made a syntax error, bubbalah!")
- SIGNAL VALUE START
-