User Code: W3Eval

Wednesday Jan 9th 2002 by Nikola Stepan

This user has created a Java applet that evaluates mathematical expressions more 'naturally' than the common calculator. Check it out.

W3Eval is a Java applet that evaluates mathematical expressions step by step. It uses a different approach than that of a conventional calculator, which is more natural to the way people calculate. When you calculate on a conventional calculator, each time you enter a new number you lose sight of the previous one. And if you make a mistake in the middle of a long expression, you have to start all over. In W3Eval, you can see all of what you are calculating, and expressions can easily be edited.

The W3Eval screen consists of three parts:

  • Tree
  • Expressions area
  • Result area

Tree is located on the left part of the screen and contains all operators, variables, and functions. It is used both as help and expression builder. When you double-click or press <Enter> on any of the terminal nodes, a template is pasted into the expressions area.

The expressions area is the upper text area of the screen. It can contain multiple expressions separated with an empty line.

The lower text area displays results and error messages.


  • evaluate mathematical expressions step by step
  • parse expressions
  • reduce parentheses
  • large number of built-in functions and operators
  • hex, oct, bin, and dec numbers
  • deg, rad, grad
  • works with "infinity" and "not-a-number"
  • user-defined variables
  • three kinds of parentheses
  • detail error checking and reporting
  • unlimited size of expressions
  • unlimited depth of nesting
  • expression builder
  • multiplatform
  • HTML help
  • automatic installation of JRE 1.3 Plug-in
  • only 50K in size

This code sample shows the definitions of the classes used for representing functions, operators, and variables:

   public String function;
   public int number_of_arguments;

   public Function( String function, int number_of_arguments )

   public String toString()
      return function;

public class Operator
   public String operator;
   public byte priority;

   public Operator( String operator, byte priority )

   public String toString()
      return operator;

public class Variable
   public String variable;
   public double value;

   public Variable( String variable, double value )

   public String toString()
      return variable;


About the Author

Nikola Stepan is a software engineer at ABIT Ltd., in Croatia, where he works on banking software design and development.

Java users are encouraged to submit samples of useful code for publication in the pages of Gamelan. Send your files and comments to for consideration. Thank you.

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved