Скачать Parser 1.0 - Recursive Parser with functions

Скачать файл (5,24 Кб)

*                                   parser                                    *
* recursive decent expression parser for turbo-pascal, Loewy Ron, 1991.       *
* parser.doc, Last Update :                  Jun. 14, 1991.                   *


Parser is a recursive decent expression parser unit for Turbo-Pascal, this unit includes the 5 basic math. operators (+ - * / ^), and some basic mathematical functions (sin, exp, cos, ln, log10, log2, abs, arctan, sqr, sqrt, tan, cotan, arcsin, arccos) and 2 constants (pi, e). Parser can be used to receive formula input from the user, and perform the neccessary calculations during program runtime. Parser supports 10 general purpose variables (v0, v1, .., v9) that can be set (using the = operator) and used in formulas by the user.


Simply use parser unit in your program using the USES clause, when ever you want to parse a string formula do :

macro := stringFormula; { stringFormula is where you've got the formula }
        myResult := getExpr(validity);
        if (validity = false) then
                tellError { the formula has an error at the errAt byte }

Please notice - the source code is provided, so you will probably find it easy to understand that example after you will look into the code.