home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
math
/
eev
/
infix.doc
< prev
next >
Wrap
Text File
|
1992-01-02
|
5KB
|
134 lines
------------------------------------------------------------------------
INFIX.PAS
------------------------------------------------------------------------
This unit uses recursive descent to evaluate expressions
written in infix notation. The operations addition (+),
subtraction (-), multiplication (*), and division (/) are supported,
as are the functions ABS, ARCTAN, COS, EXP, LN, SQR, and SQRT.
PI returns the value for pi. Results exceeding 1.0E37 are reported
as overflows. Results less than 1.0E-37 are set to zero.
Written by:
James L. Dean
406 40th Street
New Orleans, LA 70124
February 25, 1985
Modified by:
David J. Firth
5665-A2 Parkville St.
Columbus, OH 43229
December 26, 1991
This code was originally written as a stand-alone program using
standard Pascal. In that form the program wasn't very useful.
I have taken the code and reorganized it for use with Turbo Pascal
versions 5.x or 6.0. I have added six procedures to this code
for use as an API (application program interface). Those six
routines are described in this file.
In addition, I have reworked it to support variables by adding a
preprocessor. The variables are preceded and followed by a @ symbol,
are case sensitive, and must be less than 20 characters long
(including the 2 @s). For example, the following would all be valid
variables:
@VARIABLE1@ @Pressure3@ @AngleOfAttack@
Variable identifiers are passed around as strings of type Str20.
The variable-related procedures are:
-------------------------------------------------------------------
procedure StoreVariable(VariableID:str20;MyValue:real);
This procedure will store MyValue in the variable identified by
VariableID. If the variable doesn't exist, it will be created.
If the variable does exist, the value will be updated.
-------------------------------------------------------------------
procedure ReadVariable(VariableID:str20;var MyValue:real;
var MyError:boolean);
This procedure will read the value of the variable identified by
VariableID. If the variable doesn't exist, MyError will be true.
-------------------------------------------------------------------
procedure DestroyList;
The variables are stored in a singly linked list. If your program
uses variables, you need to call this routine before you exit to
DOS. Otherwise, the memory taken by the linked list will not be
given back.
-------------------------------------------------------------------
Calculation results may either be stored in variables or returned
to the caller. The following procedures should be used to call
the expression evaluator.
-------------------------------------------------------------------
procedure RawCalculate(MyFormula:string;var MyResult:real;
var MyError:byte);
This procedure will evaluate an expression that does not contain
variables. This procedure calls the original code. It has been
superceded by Calculate and CalcAndStore.
MyError=0 indentifies a successful evaluation. A non-zero
value holds the offset of the error in the formula.
-------------------------------------------------------------------
procedure Calculate(MyFormula:string;var MyResult:real;var MyError:byte);
This procedure will evaluate an expression containing zero or
more variables. The result is returned to the caller.
MyError=0 indentifies a successful evaluation. A non-zero
value holds the offset of the error in the formula. However,
the error is the offset of the error in the formula AFTER the
variable's ID strings have been replaced with the numeric
values.
Calculate calls RawCalculate for final expression evaluation.
-------------------------------------------------------------------
procedure CalcAndStore(MyFormula:string;StoreID:str20;var MyError:byte);
This procedure will evaluate an expression containing zero or
more variables. The result is stored in the variable indentified
by StoreID.
MyError=0 indentifies a successful evaluation. A non-zero
value holds the offset of the error in the formula. However,
the error is the offset of the error in the formula AFTER the
variable's ID strings have been replaced with the numeric
values.
CalcAndStore calls Calculate for expression evaluation.
-------------------------------------------------------------------
Unfortunately, the original code is virtually unreadable due
to the original author's lack of any comments. I have attempted
to provide a front end to this code that is useful and understandable.
I have tested this code using Turbo Debugger 2.0 and it seems
to work fine. However, if you find a bug, please let me know.
Your comments are welcome (and desired!). My E-Mail addresses
are:
GEnie: D.FIRTH
CIS: 76467,1734