|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Observable
scphEditor.CloneableObservable
scphEditor.OperandVector
scphEditor.Operand
scphEditor.Expression
public class Expression
This class represents compound expressions. A compound expression has an operator and a list of subexpressions, i.e., children, each child being an Operand object. E.g., -x is modelled as an Expression object, with the unary - operator and the child x.
The arity of an expression is the same as that of its operator; in case the operator is n-ary, though, the expression becomes binary. Use the subclass ExpressionNary instead if you want true n-ary services. For example, 1 + 2 + 3 is better modelled by an ExpressionNary object.
The update() method of an Observer receives an Expression.Replacement object as a parameter.
IOperator
,
ExpressionNary
,
Serialized FormNested Class Summary | |
---|---|
class |
Expression.Replacement
A Replacement object represents a substitutional change made to an Expression object. |
Field Summary | |
---|---|
protected java.util.Vector |
children
List of child operands. |
protected IOperator |
op
[Rooting] Operator in this expression. |
protected boolean |
paren
True iff this operand is parenthesized. |
protected boolean |
splitted
True iff the view should split this expression across lines. |
Constructor Summary | |
---|---|
Expression(IOperator opOf)
Constructs an Expression object with the given operator. |
Method Summary | |
---|---|
void |
acceptVisitor(OperandVisitor v)
Calls v.visitExpression(this). |
void |
addChild(Operand newChild,
int atIndex)
This implementation does not do anything. |
void |
addParen()
Parenthesizes me. |
java.lang.Object |
clone()
Clones this expression. |
int |
countChildren()
Gives the actual, present number of my children. |
Operand |
delChild(int atIndex)
This implementation returns null and does not do anything else. |
protected void |
deParen()
De-parenthesizes me. |
Operand |
getChild(int atIndex)
Gives my child at the given index. |
java.util.Enumeration |
getChildren()
Enumerates all of my children, in ascending order of indexes. |
IOperator |
getOperator()
Gives the operator of this expression. |
boolean |
getParen()
Tells if I am already parenthesized. |
boolean |
getSplit()
Gets my split status. |
void |
setChild(Operand newChild,
int atIndex)
Adopts the given new child as my child at the given index, replacing the previous child at the same index. |
void |
setSplit(boolean split)
Sets my split status. |
Methods inherited from class scphEditor.Operand |
---|
ensureParen, needParen, removeParen |
Methods inherited from class scphEditor.CloneableObservable |
---|
addObserver, cloneObserverList, cloneObserverList, countObservers, deleteObserver, deleteObservers, notifyObservers, notifyObservers |
Methods inherited from class java.util.Observable |
---|
clearChanged, hasChanged, setChanged |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected IOperator op
protected java.util.Vector children
protected boolean paren
protected boolean splitted
Constructor Detail |
---|
public Expression(IOperator opOf)
opOf
- the operator object for this Expression object.Method Detail |
---|
public java.lang.Object clone()
clone
in class Operand
public IOperator getOperator()
getOperator
in class Operand
IOperator
public void setChild(Operand newChild, int atIndex)
OperandVector
This default implementation is for a leaf node in which there must be no child, so it always throws an exception. A compound expression must re-implement this method sensibly.
setChild
in class OperandVector
newChild
- the new childatIndex
- the index to where newChild goespublic Operand getChild(int atIndex)
getChild
in class OperandVector
atIndex
- the index at where a child will be sought.
java.lang.ArrayIndexOutOfBoundsException
- if atIndex
is an invalid index, i.e., atIndex violates my arity.public void addChild(Operand newChild, int atIndex)
addChild
in class OperandVector
public Operand delChild(int atIndex)
delChild
in class OperandVector
public java.util.Enumeration getChildren()
getChildren
in class OperandVector
public int countChildren()
OperandVector
This default implementation returns zero, as a leaf node has no child.
countChildren
in class OperandVector
public void addParen()
Operand
The default implementation is for leaf nodes and does nothing. Compound expressions should override this properly.
addParen
in class Operand
protected void deParen()
Operand
The default implementation is for leaf nodes and does nothing. Compound expressions should override this properly.
deParen
in class Operand
Operand.removeParen(scphEditor.OperandVector)
public boolean getParen()
Operand
This default implementation is for leaf nodes. Compound expressions should override this properly.
getParen
in class Operand
public boolean getSplit()
Operand
b = aOf course, this is just a hint to the view.
This default implementation is for leaf nodes, which never splits. Compound expressions should override this properly.
getSplit
in class Operand
public void setSplit(boolean split)
Operand
This default implementation is for leaf nodes, which never splits. Compound expressions should override this properly.
setSplit
in class Operand
split
- true if you want me to split, false otherwise.public void acceptVisitor(OperandVisitor v)
acceptVisitor
in class Operand
v
- the visitor object that wants to visit this operand.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |