Unit Parser9 |
TParser - component for parsing and evaluating mathematical expressions Renate Schaaf (schaaf@math.usu.edu), 1993 Alin Flaider (aflaidar@datalog.ro), 1996 Version 9.1 - revision by Alin Flaider 1997 stripped off >4K memory leak bug wich affected each expression parsing Version 9: Stefan Hoffmeister 1996-1997 (those who have time are the lucky ones...) Some code cleanup, especially assigning meaningful (English) names to variables, functions and procedures (the original code seems to have been in German...) Fixes bug: 2^500 would not have been evaluated in V8 Fixes bug: x^(real number) would have caused syntax error Fixes bug: crash if access to Value when no Expression has been parsed [I am not sure whether originally I introduced all these bugs myself...] Reduce stack usage by approx 4.2 kb speed up things a wee bit in _parsing_ (streamlining) [according to Alin Flaider the 32bit version evaluataion was sped up by 2%-3%] reduce pointer usage -> less memory in parsing, faster parsing add two new operators: "MOD" and "DIV", performing their respective PASCAL operations WARNING: these operators _implicitly_ perform a trunc() on their operands! Rework the function parsing; now it is possible to simply add new functions by overriding Create and saying something like FunctionOne.AddObject('RND', TObject(@MyProcedure)); FunctionTwo.AddObject('MAX', TObject(@MyProcedure)); Also two new functions have been added: MyProcedure must be a far procedure and declared as procedure MyProcedure(xxx: POperation) (that is the type TMathProcedure); as arguments use xxx^.arg1^ and xxx^.arg2^; store the result of the operation in xxx^.dest^ Of course it also is possible to add functions on the fly making it possible (in theory) to link a couple of parsers: the first parser defines a function used by the second parser... Added error checking for variable names and function names; these must be valid Object Pascal identifiers and they MUST NOT contain the letter combination "MOD" and "DIV" - this would confuse the parser... Added exceptions for better flow control; made memory deallocation in case of an exception / internal error dead safe... General code cleanup (removal of dead code, "dead" variables (reassigned) etc)
Classes |
TParser - far;
Functions |
Register - Make sure we get the right component icon for each version of Delphi } {$IFDEF Win32} {$R PARSER9.
Types |
TFuncPrototype
TParserExceptionEvent
Constants |
Variables |
Functions |
Types |
TFuncPrototype = procedure( AnOp: Poperation)functions that are added to the engine MUST have this declaration } { make sure that the procedure is declared far !!!
TParserExceptionEvent = procedure (Sender: TObject; E: Exception) of objectwe COULD use Forms and the TExceptionEvent therein, but that would give us all the VCL overhead. Consequentially we just redeclare an appropriate event
Constants |
Variables |