******************* ** Calc4 ** ******************* Author: Michael Lam Company: FreeArrow Software Email: feedback@freearrow.com EXE Version: 1.0.0 License: Freeware Created with: JDK 1.4.1 w/ Xinox JCreator LE Paradox Copyright (C) 2003 Michael Lam Calc4 Copyright (C) 2003 Michael Lam -- Description -- Evaluating a mathematical expression such as “2 + 1.05e-18[53(sin 4)(? – 7 log2 3)]” is a unique challenge, even for a computer. Much of the challenge is associated with the act of cutting or “parsing” the actual text of the expression into a form that computers can understand. One method of doing this is with a recursive descent parsing algorithm, which builds an expression tree by recursively parsing an expression according to a special grammar. Paradox is a set of Java classes I programmed with JDK v1.4.1 that will parse and evaluate a mathematical expression such as the one written above. It supports variables, functions, boolean operators, subexpressions, and developer-defined functions. I also created Calc4, a helper application. It provides a graphical user interface (GUI) for the Paradox engine, allowing the user to type in complex expressions and obtain the numerical answer. Calc4 also demonstrates the benefits of using a simple scripting language to automate routine calculations. Altogether, Paradox is a reliable, expandable engine that has many potential uses at the home, on the job and in the classroom. Unless they're using Unix or one of its variants, it is fairly uncommon for regular computer users to utilize the command line much anymore. In this era of "user-friendly" interfaces, it is rare to find someone who would not prefer a "pretty" GUI (Graphical User Interface) to a "boring" CLI (Command Line Interface). Although there are those who would argue for the superiority of a CLI and there are others who would never dream of using anything other than a GUI, I believe that both have their place. Therefore, although Paradox has a simple CLI program built-in (found in the Util class), I have also created Calc4, a small sample GUI for demonstration purposes. It is by no means a comprehensive program, but it provides a reasonably nice interface for entering expressions and getting their results. It also demonstrates the possibility of using a simple scripting language in conjunction with Paradox to automate routine calculations. The main purpose of Calc4 is to provide a decent multiline display with which you can enter expressions and obtain results. When the program is started, this display is the dominating feature. To evaluate an expression, simply type the expression in the window and press the ENTER key (note that if for some reason you wish to simply insert a carriage return/line feed, you can do this by pressing Ctrl-Enter or Alt-Enter). This window does support copy and paste, so you don't have to enter complex expressions over and over again; simply copy and paste the expression and then edit it if necessary. Also shown in the initial screen is a smaller window below the main display. This window serves as an error log, keeping track of all errors that occur in the session. If you enter an invalid expression, such as "3+*4", the error message "Error while parsing expression: Number expected but not found." is shown in this window. The error messages are fairly self-explanatory, but sometimes in a long expression it can be hard to tell exactly where the problem is. Therefore, it is recommended that you make extra effort to work slowly and enter your expressions correct the first time. However, typos are inevitable, and this error log helps alleviate some of the aggravation that they cause. There is also a large set of buttons that can be shown by selecting "Show Buttons" from the View menu or by pressing F4. These buttons simply replace the current selection with the text on them. When a button with text ending in parentheses (such as a function) is clicked, the cursor is moved inside the parentheses. Also in the View menu is an option to show expression trees. If this option is selected, the expression tree is printed after the result when you enter an expression. The string representation used is obtained by calling the toString() function of the root Expression (see above section on the implementation for details). The Engine menu contains options for displaying lists of supported constants and variables as well as for executing scripts (see Scripting.txt for more info on scripts). There are several other purely cosmetic options as well. You can change the font size and the "look & feel" of the application using the appropriate submenus in the View menu. In addition, selecting "Clear" in the menu or pressing Ctrl-Del will clear the display. Paradox is freeware. In other words, it is free to anyone who desires to use it in their application, whether it be for personal or commercial usage. Any individual, organization or company who can afford to donate a small amount to compensate me for the time I spent on the project is certainly welcome to send any amount they deem appropriate, but payment is by no means required for the use of this program. In addition, Paradox may be freely distributed. If you wish to put it on a disk or in a code library, though, I would appreciate a complimentary copy of your disk or library. The Java source code is also freely and easily obtainable for further study or enhancement. If you do wish to modify the program and release the modified version, feel free to do so. You do not have to ask my permission, but it would be nice to notify me of your intentions beforehand. Note also that if you are planning to charge for your product, I would very much appreciate a complimentary copy of your product. The only restriction on the use and distribution of this product is that you may not charge for an unmodified (or only marginally modified) version of this program or claim that you wrote it. The code for both Paradox and Calc4 are copyright by me and may only be distributed and used if I am cited. Most of the above also applies to the user interface program (Calc4). However, the source code for the UI program is NOT publicly available and I reserve the right to charge for the use of future versions. Enjoy!