home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
PASCAL
/
EEV100R1.ZIP
/
POSTFIX.DOC
< prev
next >
Wrap
Text File
|
1992-02-02
|
4KB
|
121 lines
-------------------------------------------------------------------
POSTFIX.PAS (TP5.5/6.0) and POSTFIX.INC (TP3.0)
-------------------------------------------------------------------
February 2, 1992: Version 1.00, Revision 1
- TP3.0 include files added
- supports TP3.0, TP5.5, and TP6.0
December 28, 1991: Version 1.00, Revision 0
- original release for TP5.5 and TP6.0
Written by: David J. Firth
5665-A2 Parkville St.
Columbus, OH 43229
This unit provides an API for a postfix expression evaluator.
Postfix is reverse polish notation (RPN), a notation for
expressions that is commonly used by Hewlett Packard calculators
and stack based languages like Forth.
This evaluator supports the following functions:
+ - * / PI ABS ARCTAN COS LN EXP SQR SQRT
Variables are supported also. Any string of characters that
the evaluator finds that is not a number or an operator is
assumed to be a variable ID. When a variable ID is found in
and expression, the variable's value is pushed onto the stack.
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 InitializeEE;
This routine is present in POSTFIX.INC, the evaluator for
TP 3.0, only.
This routine is used to initialize the stack and variables
linked list prior to evaluator use. If you do not call this
routine, the evaluator will probably crash, since the stack
and linked list pointers could point to anywhere.
In the TP5.5/6.0 version, POSTFIX.PAS, the unit initialization
code performs this function.
-------------------------------------------------------------------
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.
Likewise, the evaluator's stack is allocated on the heap. This
routine will also destroy the stack (via the DestroyStack internal
procedure).
-------------------------------------------------------------------
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 Calculate(MyFormula:string;
var MyResult:real;
var MyError:boolean);
This procedure will evaluate an RPN expression, returning the
result is returned to the caller.
MyError=false indentifies a successful evaluation.
-------------------------------------------------------------------
procedure CalcAndStore(MyFormula:string;
StoreID:str20;
var MyError:boolean);
This procedure will evaluate an RPN expression, storing the
result in the variable identified by StoreID.
MyError=false indentifies a successful evaluation.
CalcAndStore calls Calculate for expression evaluation.
-------------------------------------------------------------------
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