From: Isabelle M. <isa...@pr...> - 2002-08-03 11:52:51
|
Hi everyone, Here's an idea for a subproject: The expression evaluator is a component that can evaluate expressions at run time. Expressions can contain numbers, booleans, all arithmetic, logical and relational operators, as well as exponentiation. The evaluator language also understands if-statements and functions. Functions can be written either in the evaluator-language, or in Java and the evaluator will call the Java code. Some functions could be built into the language, such as logarithms, absolute values, ... <question : do we need both facilities or is one sufficient?> The evaluator language also has variables. Utility of this component: similar components have been used in (1) an application for trimming (load-and-balancing) cargo aircraft (2) an application for production planning of furnaces In both cases, formulas are stored in the database (e.g. how to compute the center of gravity of the fuel in the fuel tanks of the airplane, or how to compute the composition of the mix to be fed to the furnace) and must be evaluated at run-time by the application. Experience has shown that formulas are used in 2 different contexts : sometimes a given formula needs to be evaluated only once, other times a formula will be evaluated thousands of times. So, in order to serve everyone best, we probably need the option to build a syntax tree so that multiple evaluations will be very fast (parse once, evaluate many times). I think we should use ANTLR (www.antlr.org) to build the parser. I can produce the EBNF grammar fairly quickly. It will then have to be ported to the antlr syntax. Similar projects : have a look at JEP (http://sourceforge.net/projects/jep/). This is actually pretty similar to what I have in mind, except for user functions in the evaluator language and if-statements. It also lacks on-demand variables : typically, the application using the evaluator does not know what variables are used in the formula, and so cannot set them before evaluation. Instead, the evaluator has to callback to the application to obtain the variable's value at runtime. Example : var x, y; x = y + 10; Since no value was provided for y, the evaluator will call back on a callback interface in order to obtain it. An alternative to the callback interface would be for the application to pass a bean-like object to the evaluator, and the evaluator will call the appropriate getXXX method. I need to think some more about this, because sometimes the application's object model is too complex for simple getXXX(). For example, in the furnace-planning application, the object model consists of furnaces, production models, components (a mixture of chemical elements and other components), and chemical elements. If there's enough interest in this project, I can produce detailed specs. Isabelle -- __________________________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup Get 4 DVDs for $.49 cents! plus shipping & processing. Click to join. http://adfarm.mediaplex.com/ad/ck/990-1736-3566-59 |