|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.netlib.math.complex.Complex
org.fraid.interpreter.SimpleNode
public class SimpleNode
A SimpleNode
is generated for each token found in the FrAid input stream.
After the javacc/jjtree generated code hands over the parse tree,
is called on the root after which the
parse tree is linked and evaluated. If the operation is assignment the tree is trimmed and optimized and a new process()
is registered in the DefinedFunction
SymbolTable
. SimpleNode
inherits from Complex
so complex numbers
can be used interchangeably everywhere in the parser code. (Which could have been achieved by some sort of composition?)
Nested Class Summary | |
---|---|
static class |
SimpleNode.FunctionEvaluationType
|
Field Summary | |
---|---|
protected Node[] |
children
Automatically generated by javacc. |
protected int |
id
Automatically generated by javacc. |
protected ComplexFunction |
mFunction
If the type of token is Function (JJTFUNCTIONCALL = 27) mFunction holds it. |
protected SimpleNode.FunctionEvaluationType |
mFunctionEvalType
How many arguments need to be provided for this tree to be evaluated. |
protected DefinedFunction |
mLastDefinedFunction
A reference to the last defined function. |
protected SymbolTable |
mSymbTable
A local reference to the symbol table. |
protected java.lang.String |
mText
If the type of token is String (JJTSTRING = 23) mText holds it. |
protected java.lang.Integer |
mVarIndex
If the type of token is function variable (JJTVARIABLE = 28) mVarIndex holds the index of this variable in the variable list passed to the function. |
protected Node |
parent
Automatically generated by javacc. |
protected Fraid |
parser
Automatically generated by javacc. |
protected static java.lang.String |
sHiddenFunctionNamePrefix
|
protected static int |
sHiddenFunctionNextIndex
Internal counter for forming hidden function names. |
Fields inherited from class org.netlib.math.complex.Complex |
---|
AUTHOR, DATE, iii, im, re, REMARK, TWO_PI, VERSION |
Fields inherited from interface org.fraid.interpreter.FraidTreeConstants |
---|
JJTADD, JJTAND, JJTASSIGNMENT, JJTDIVIDE, JJTEQUAL, JJTEXPRESSIONTOCALCULATE, JJTFUNCTIONCALL, JJTFUNCTIONDEF, JJTGREATER, JJTGREATEROREQUAL, JJTIFTHENEXPRESSION, JJTIMAGINARYNUMBER, JJTMETA, JJTMULTIPLY, JJTNEGATE, jjtNodeName, JJTNOT, JJTNOTEQUAL, JJTOR, JJTPOWER, JJTPROCESSSINGLELINE, JJTPROCESSSTREAM, JJTREALNUMBER, JJTSMALLER, JJTSMALLEROREQUAL, JJTSTRING, JJTSUBTRACT, JJTVARIABLE, JJTVOID, JJTXOR |
Constructor Summary | |
---|---|
SimpleNode(Complex aC)
Create a node of type JJTIMAGINARYNUMBER. |
|
SimpleNode(ComplexFunction aFunction)
Create a node of type JJTFUNCTIONCALL. |
|
SimpleNode(double aReal,
double aImaginary)
|
|
SimpleNode(Fraid p,
int i)
Create a node from the given type and with the given parser. |
|
SimpleNode(int i)
Create a node of the given type |
|
SimpleNode(SimpleNode aNode)
Copy constructor. |
|
SimpleNode(java.lang.String aString)
Create a node of type JJTSTRING. |
Method Summary | |
---|---|
protected void |
_copy(SimpleNode aNode)
|
protected static void |
addArgumentNodesToMeta(SimpleNode aNode)
|
void |
addChangeListener(javax.swing.event.ChangeListener aListener)
Adds a change listener to this node. |
protected static int |
childrenCountMissingArgs(SimpleNode aNode)
|
protected void |
clean()
The code executed before an eval takes place. |
java.lang.Object |
clone()
Local implementation of the clone() method. |
protected static void |
connectGeneratedF(DefinedFunction aGf,
DefinedFunction aDf)
|
protected static boolean |
containsMeta(SimpleNode aNode)
|
static SimpleNode |
copyFrAidRelevantData(Complex aComplex)
|
static int |
countMissingArgs(SimpleNode aNode)
|
protected static java.util.HashMap<java.lang.String,java.lang.Integer> |
createArgumentList(SimpleNode aSignatureNode)
|
static void |
createSymbTableEntry(SimpleNode aNode)
This is the main processor of the assignment operator (function/variable definition) in FrAid. |
java.lang.String |
dumpString(java.util.HashMap aArgs)
Helper to and
|
java.lang.String |
dumpTree(java.lang.String aPrefix)
Dumps the parser generated expression tree of which this node is a root. |
void |
ensureUsable()
Makes shure the node is usable outside of the interpreter. |
static Complex |
eval(SimpleNode aNode,
Complex[] aArgs)
Each node in the expression tree evaluates to something for which this method is responsible. |
static Complex |
evalFunction(SimpleNode aNode,
Complex[] aArgs)
|
static SimpleNode |
evalGeneratedF(SimpleNode aNode)
If the right hand side of an assignment operator is a org.fraid.complex.GeneratorFunction this method evaluates it so createSymbTableEntry(org.fraid.interpreter.SimpleNode)
can create a function with the given signature. |
DefinedFunction |
findSampled()
If this node is of type JJTFUNCTIONCALL go recursively through the children and find if any of them is a sampled function. |
protected static java.lang.String |
generateHiddenFunctionName()
|
void |
getDependancies(java.util.Vector<ComplexFunction> aVector,
java.util.HashSet<ComplexFunction> aAllreadyPassed)
Get all the functions this node depends on (is defined using). |
ComplexFunction |
getFunction()
Getter for the mFunction member. |
int |
getId()
|
protected static SimpleNode |
getNextGeneratedF(SimpleNode aNode)
|
protected static SimpleNode |
getNextGraphicsF(SimpleNode aNode)
|
static int |
getParentIndexOfSelf(SimpleNode aNode)
|
java.lang.String |
getText()
Getter for the mText member |
void |
jjtAddChild(Node n,
int i)
Automatically generated by javacc. |
void |
jjtClose()
Automatically generated by javacc. |
Node |
jjtGetChild(int i)
Automatically generated by javacc. |
int |
jjtGetNumChildren()
Automatically generated by javacc. |
Node |
jjtGetParent()
Automatically generated by javacc. |
void |
jjtOpen()
Automatically generated by javacc. |
void |
jjtSetParent(Node n)
Automatically generated by javacc. |
static void |
linkNode(SimpleNode aNode,
java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment)
The main routine to link the nodes in a tree to their respective values/functions/variables. |
protected static void |
node2Function(SimpleNode aNode,
java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment)
|
protected void |
prelinkFunctionOrVariableNode(java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment)
This function will prepare a node if it is a variable or a function. |
protected static void |
preventMetaFromNesting(SimpleNode aNode)
|
protected static void |
printTreeProcessingInfo(SimpleNode aNode,
java.lang.String aDescription)
|
protected static void |
printTreeProcessingInfo(java.lang.String aContent,
java.lang.String aDescription)
|
Complex |
process()
After the parser builds the parse tree it calls process on the root (so process is called only once per expression). |
protected static void |
pruneComputable(SimpleNode aNode)
|
int |
removeChangeListener(javax.swing.event.ChangeListener aListener)
Removes a listener. |
protected static void |
setFunctionsEvalMode(SimpleNode aNode)
|
void |
setText(java.lang.String text)
Setter for the mText member. |
java.lang.String |
toString()
Selfexplanatory. |
static int |
treeDepthFromNode(SimpleNode aNode)
|
Methods inherited from class org.netlib.math.complex.Complex |
---|
abs, acos, acosh, add, arg, asin, asinh, atan, atanh, cart, conj, cos, cosec, cosh, cot, div, equals, exp, im, isInfinite, isNaN, log, main, mul, neg, norm, polar, pow, pow, pow, pow, re, real, scale, sec, sin, sinh, sqrt, sub, tan, tanh |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Node parent
protected Node[] children
protected int id
protected Fraid parser
protected SymbolTable mSymbTable
protected DefinedFunction mLastDefinedFunction
protected java.lang.String mText
mText
holds it.
protected ComplexFunction mFunction
mFunction
holds it.
protected java.lang.Integer mVarIndex
mVarIndex
holds the index of this variable in the variable list passed to the function.
protected SimpleNode.FunctionEvaluationType mFunctionEvalType
protected static volatile int sHiddenFunctionNextIndex
protected static final java.lang.String sHiddenFunctionNamePrefix
Constructor Detail |
---|
public SimpleNode(int i)
i
- node type#FraidTreeConstants
public SimpleNode(Fraid p, int i)
p
- parseri
- node type#FraidTreeConstants
public SimpleNode(Complex aC)
aC
- value for the nodepublic SimpleNode(double aReal, double aImaginary)
public SimpleNode(java.lang.String aString)
aString
- value for the node.public SimpleNode(ComplexFunction aFunction) throws ComplexFunctionException
aFunction
- value for the node.
ComplexFunctionException
public SimpleNode(SimpleNode aNode)
aNode
- value for the node.Method Detail |
---|
public void setText(java.lang.String text)
mText
member.
text
- textpublic java.lang.String getText()
mText
member
public ComplexFunction getFunction()
mFunction
member.
protected void _copy(SimpleNode aNode)
public static SimpleNode copyFrAidRelevantData(Complex aComplex)
public java.lang.Object clone()
clone()
method.
clone
in class Complex
Cloneable
,
Object.clone()
public void jjtOpen()
jjtOpen
in interface Node
public void jjtClose()
jjtClose
in interface Node
public void jjtSetParent(Node n)
jjtSetParent
in interface Node
n
- a parent nodepublic Node jjtGetParent()
jjtGetParent
in interface Node
public void jjtAddChild(Node n, int i)
n
at position i
.
jjtAddChild
in interface Node
n
- child to addi
- position in the listpublic Node jjtGetChild(int i)
jjtGetChild
in interface Node
i
- index
public int jjtGetNumChildren()
jjtGetNumChildren
in interface Node
public java.lang.String toString()
toString
in class Complex
Complex.cart(double, double)
public int getId()
protected void clean()
eval
takes place.
public void ensureUsable() throws SemanticException
SemanticException
- if the node is not usable outside of the interpreterpublic java.lang.String dumpTree(java.lang.String aPrefix)
dumpTree()
FrAid function.
aPrefix
- step before each level
org.fraid.utils.functions.dumpTree
public DefinedFunction findSampled()
sampled
DefineFunction
found in the tree else null
.public java.lang.String dumpString(java.util.HashMap aArgs)
dumpTree(java.lang.String)
and toString()
aArgs
- null or argInfo#DefinedFunction
public void getDependancies(java.util.Vector<ComplexFunction> aVector, java.util.HashSet<ComplexFunction> aAllreadyPassed)
aVector
- a vector containing all the functions this node depends on (output value)aAllreadyPassed
- helper - a hash set of the already processed functions (to prevent duplicates in the output list)public void addChangeListener(javax.swing.event.ChangeListener aListener)
aListener
- the listener to addpublic int removeChangeListener(javax.swing.event.ChangeListener aListener)
aListener
- the listener to remove
public Complex process() throws java.lang.Exception
process
on the root (so process
is called only once per expression).
process
traverses the expression tree recursively linking
and evaluating
the expression.
java.lang.Exception
- needs to be able to throw any posible exception comming from the underlying processingprotected static void printTreeProcessingInfo(SimpleNode aNode, java.lang.String aDescription)
protected static void printTreeProcessingInfo(java.lang.String aContent, java.lang.String aDescription)
public static Complex eval(SimpleNode aNode, Complex[] aArgs) throws java.lang.Exception
aArgs
- parameters for the evaluation
java.lang.Exception
- channels what may go wrong during the evaluationpublic static Complex evalFunction(SimpleNode aNode, Complex[] aArgs) throws java.lang.Exception
java.lang.Exception
public static void linkNode(SimpleNode aNode, java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment) throws java.lang.Exception
aEnvironment
- the defined so far variables
java.lang.Exception
- if something goes wrongprotected void prelinkFunctionOrVariableNode(java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment) throws SemanticException
aEnvironment
- the environment to check if this is a proper variable
SemanticException
- Throws when the node is marked as a function or a variable but something is wrong. If this function returns and the node is a function or a variable they will be set properly.public static void createSymbTableEntry(SimpleNode aNode) throws java.lang.Exception
java.lang.Exception
- channels any exception from bellow if something goes wrongprotected static void setFunctionsEvalMode(SimpleNode aNode)
public static int treeDepthFromNode(SimpleNode aNode)
public static int getParentIndexOfSelf(SimpleNode aNode) throws SemanticException
SemanticException
protected static void node2Function(SimpleNode aNode, java.util.HashMap<java.lang.String,java.lang.Integer> aEnvironment) throws SemanticException, ComplexFunctionException, java.lang.Exception
SemanticException
ComplexFunctionException
java.lang.Exception
protected static void addArgumentNodesToMeta(SimpleNode aNode)
protected static void pruneComputable(SimpleNode aNode) throws java.lang.Exception
java.lang.Exception
protected static SimpleNode getNextGeneratedF(SimpleNode aNode)
protected static SimpleNode getNextGraphicsF(SimpleNode aNode)
protected static boolean containsMeta(SimpleNode aNode) throws SemanticException
SemanticException
protected static void preventMetaFromNesting(SimpleNode aNode) throws SemanticException
SemanticException
public static int countMissingArgs(SimpleNode aNode) throws SemanticException
SemanticException
protected static int childrenCountMissingArgs(SimpleNode aNode) throws SemanticException
SemanticException
protected static java.util.HashMap<java.lang.String,java.lang.Integer> createArgumentList(SimpleNode aSignatureNode) throws SemanticException
SemanticException
protected static void connectGeneratedF(DefinedFunction aGf, DefinedFunction aDf) throws ComplexFunctionException, SemanticException, java.lang.Exception
ComplexFunctionException
SemanticException
java.lang.Exception
public static SimpleNode evalGeneratedF(SimpleNode aNode) throws java.lang.Exception
org.fraid.complex.GeneratorFunction
this method evaluates it so createSymbTableEntry(org.fraid.interpreter.SimpleNode)
can create a function with the given signature. eval could be used here but with the price of one more if(aNode.mFunction instanceof GeneratorFunction) in there
java.lang.Exception
- if something goes wrongprotected static java.lang.String generateHiddenFunctionName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |