{Defined in UNIT SParser.}

A parser is an object that can convert a string of characters representing a formula into a number. Beginning programmers usually code formulas into the Pascal program and the Delphi compiler converts these formulas into machine code.

Function Cot(x:Double):Double;




But what if you don’t know what the function will be when your are writing the code? What if you want to write a program where the user inputs a function and you then want to integrate and plot the function? Getting the characters that represent the function into the computer is easy—just define a string variable and you are done. But to evaluate this expression and convert it into a number is hard. For this you need a parser.

In order to use a STools parser you must do the following.

1) Include the Sparser unit in the uses declaration.

2) Declare an variable of type Sparser.

3) Create and initialize the Parser in the code. This is usually done in the FormCreate method.

4) Send the character string representing the function to the Parser.

5) Have the parser evaluate the character string and return a value.

The following Interface declarations tell the whole story. Parsers are not hard to use once someone has written one!

TSParser = class(TParser)

Constructor Create(aString:String;aVar:Char);

Destructor Done;

Function Value(x:Double):Double;

Function GetParseString:String;

Procedure SetParseString(aString:String);


The parser can recognize the following regular functions