Opus5
Class ExpressionTree
java.lang.Object
|
+--Opus5.AbstractObject
|
+--Opus5.AbstractContainer
|
+--Opus5.AbstractTree
|
+--Opus5.BinaryTree
|
+--Opus5.ExpressionTree
- All Implemented Interfaces:
- Comparable, Container, Tree
- public class ExpressionTree
- extends BinaryTree
Represents a binary expression as a binary tree.
- Version:
- $Id: ExpressionTree.java,v 3.1 1998/07/28 01:32:17 brpreiss Exp $
- Author:
- Bruno R. Preiss, P.Eng.
|
Constructor Summary |
ExpressionTree(char c)
Constructs a ExpressionTree that consists
of a single (leaf) node with the specified label. |
|
Method Summary |
static ExpressionTree |
parsePostfix(java.io.Reader in)
Parses a postfix expression read from the specified input stream
and constructs the corresponding expression tree. |
java.lang.String |
toString()
Returns a string representation of this expression tree
using infix notation. |
| Methods inherited from class Opus5.BinaryTree |
attachKey, attachLeft, attachRight, compareTo, depthFirstTraversal, detachKey, detachLeft, detachRight, getDegree, getKey, getLeft, getRight, getSubtree, isEmpty, isLeaf, purge |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
ExpressionTree
public ExpressionTree(char c)
- Constructs a
ExpressionTree that consists
of a single (leaf) node with the specified label.
- Parameters:
c - The label on this node.
parsePostfix
public static ExpressionTree parsePostfix(java.io.Reader in)
throws java.io.IOException
- Parses a postfix expression read from the specified input stream
and constructs the corresponding expression tree.
The postfix expression consists of one-letter symbols,
one-digit numbers,
+, -, * and /.
- Parameters:
in - The input stream.- Returns:
- An expression tree.
- Throws:
java.io.IOException - If an error occurs while reading input.
toString
public java.lang.String toString()
- Returns a string representation of this expression tree
using infix notation.
- Overrides:
toString in class AbstractContainer
- Returns:
- A string representation of this expression tree.