/** A tree-based representation of expressions */
public class ExpressionTree {
// ---------- Constants ----------
/** Indicate that a node contains an operation. */
public static final int OPERATION = 32;
/** Indicate that a node contains a variable. */
public static final int VARIABLE = 42;
/** Indicate that a node contains an integer. */
public static final int INTEGER = 52;
// ---------- Fields ----------
/** The contents of the current node. */
private Object contents;
/** The arity of the operation (for operation nodes). */
private int arity;
/** The arguments (if there are any). */
private ExpressionTree[] arguments;
/** The "type" of information stored in the current node. */
int type;
...
// ---------- Constructors ----------
/** Create a leaf node with one integer value. */
public ExpressionTree(int val) {
contents = new Integer(val);
arity = 0;
arguments = null;
type = INTEGER;
} // ExpressionTree
/** Create a binary expression. */
public ExpressionTree(
Operation op,
ExpressionTree arg0,
ExpressionTree arg1)
{
contents = op;
type = OPERATION;
arity = 2;
arguments = new ExpressionTree[2];
arguments[0] = arg0;
arguments[1] = arg1;
} // ExpressionTree
/** Create a trinary expression. */
public ExpressionTree(
Operation op,
ExpressionTree arg0,
ExpressionTree arg1,
ExpressionTree arg2)
{
...
} // ExpressionTree(op,ETree,Etree,Etree)
...
} // ExpressionTree
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Fri Nov 14 12:36:49 1997.
This page generated on Fri Nov 14 12:40:19 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu