AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
AtomicExpression.java
Go to the documentation of this file.
1package aud.example.expr;
2
6public abstract class AtomicExpression {
13 protected ExpressionTree node_ = null;
14
16 public boolean isOperator() { return !isTerminal(); }
18 public boolean isTerminal() { return node_.isLeaf(); }
19
21 public enum Type {
22 OpPlus, OpMinus, OpUnaryMinus, OpTimes, OpDivide, OpPower,
23 TNumber, TSymbol
24 }
26 public abstract Type getType();
27
29 @Override public AtomicExpression clone() {
30 // Note that this should be an abstract method!
31 //
32 // The implementation that throws an exception frees us from
33 // defining clone(), e.g., in the new Power class (expect less
34 // suprises.)
35 //
36 // Similarly, AtomicExpression should better implement
37 // Cloneable; but then we always had to take care of possible
38 // exception (CloneNotSupportedException).
39 throw new RuntimeException("You didn't overwrite clone()!");
40 }
41
45 public abstract double getValue();
46}
boolean isLeaf()
Is this a leaf?
Definition: BinaryTree.java:96
Superclass for data associated with a tree node.
ExpressionTree node_
uplink reference to node: node_.getData()==this @endiliteral
abstract double getValue()
get value
abstract Type getType()
Get type identifier.
AtomicExpression clone()
Get a copy: a new AtomicExpression of same type/content.
boolean isTerminal()
node represents number or symbol
boolean isOperator()
node represents operator
Tree representation of arithmetic expression.
type identifiers returned by getType