public class ParseTreeEvaluator extends AbstractParseTreeVisitor
ASTPtRootNode| Yellow (neuendor) |
| Green (neuendor) |
| Modifier and Type | Field and Description |
|---|---|
protected Token |
_evaluatedChildToken |
protected ParseTreeTypeInference |
_typeInference |
| Constructor and Description |
|---|
ParseTreeEvaluator() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_assert(boolean flag,
ASTPtRootNode node,
java.lang.String message)
Assert that the given boolean value, which describes the given
parse tree node, is true.
|
protected Token[] |
_evaluateAllChildren(ASTPtRootNode node)
Loop through all of the children of this node,
visiting each one of them; this will cause their token
value to be determined.
|
protected Token |
_evaluateArrayIndex(ASTPtRootNode node,
Token value,
Token index)
Evaluate the array index operation represented by the given node.
|
protected Token |
_evaluateChild(ASTPtRootNode node,
int i)
Evaluate the child with the given index of the given node.
|
protected Token |
_evaluateMatrixIndex(ASTPtRootNode node,
Token value,
Token rowIndex,
Token columnIndex)
Evaluate the Matrix index operation represented by the given node.
|
protected Token |
_functionCall(java.lang.String functionName,
Type[] argTypes,
java.lang.Object[] argValues)
Evaluate the specified function.
|
protected Token |
_methodCall(java.lang.String methodName,
Type[] argTypes,
java.lang.Object[] argValues)
Evaluate the specified method.
|
protected void |
_trace(java.lang.String string)
Add a record to the current trace corresponding to the given message.
|
protected void |
_traceEnter(ASTPtRootNode node)
Add a record to the current trace corresponding to the start
of the evaluation of the given node.
|
protected void |
_traceLeave(ASTPtRootNode node)
Add a record to the current trace corresponding to the completion
of the evaluation of the given node.
|
Token |
evaluateParseTree(ASTPtRootNode node)
Evaluate the parse tree with the specified root node.
|
Token |
evaluateParseTree(ASTPtRootNode node,
ParserScope scope)
Evaluate the parse tree with the specified root node using
the specified scope to resolve the values of variables.
|
java.lang.String |
traceParseTreeEvaluation(ASTPtRootNode node,
ParserScope scope)
Trace the evaluation of the parse tree with the specified root
node using the specified scope to resolve the values of
variables.
|
void |
visitArrayConstructNode(ASTPtArrayConstructNode node)
Construct an ArrayToken that contains the tokens from the
children of the specified node.
|
void |
visitBitwiseNode(ASTPtBitwiseNode node)
Evaluate a bitwise operator on the children of the specified
node, where the particular operator is property of the node.
|
void |
visitFunctionalIfNode(ASTPtFunctionalIfNode node)
Evaluate the first child, and depending on its (boolean) result,
evaluate either the second or the third child.
|
void |
visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
Apply a function to the children of the specified node.
|
void |
visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
Define a function, where the children specify the argument types
and the expression.
|
void |
visitLeafNode(ASTPtLeafNode node)
Evaluate a numeric constant or an identifier.
|
void |
visitLogicalNode(ASTPtLogicalNode node)
Evaluate a logical AND or OR on the children of the specified node.
|
void |
visitMatrixConstructNode(ASTPtMatrixConstructNode node)
Construct a matrix containing the children nodes.
|
void |
visitMethodCallNode(ASTPtMethodCallNode node)
Apply a method to the children of the specified node, where the
first child is the object on which the method is defined and the
rest of the children are arguments.
|
void |
visitPowerNode(ASTPtPowerNode node)
Evaluate the power operator on the children of the specified node.
|
void |
visitProductNode(ASTPtProductNode node)
Multiply the children of the specified node.
|
void |
visitRecordConstructNode(ASTPtRecordConstructNode node)
Construct a record by assigning the fields values given by
the children nodes.
|
void |
visitRelationalNode(ASTPtRelationalNode node) |
void |
visitShiftNode(ASTPtShiftNode node)
Apply a shift operator to the children of the specified node.
|
void |
visitSumNode(ASTPtSumNode node)
Apply a sum operator to the children of the specified node.
|
void |
visitUnaryNode(ASTPtUnaryNode node)
Apply a unary operator to the single child of the specified node.
|
void |
visitUnionConstructNode(ASTPtUnionConstructNode node)
Construct a union by assigning the label value given by
the children nodes.
|
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNodeprotected Token _evaluatedChildToken
protected ParseTreeTypeInference _typeInference
public Token evaluateParseTree(ASTPtRootNode node) throws IllegalActionException
node - The root of the parse tree.IllegalActionException - If an evaluation error occurs.public Token evaluateParseTree(ASTPtRootNode node, ParserScope scope) throws IllegalActionException
node - The root of the parse tree.scope - The scope for evaluation.IllegalActionException - If an error occurs during
evaluation.public java.lang.String traceParseTreeEvaluation(ASTPtRootNode node, ParserScope scope) throws IllegalActionException
node - The root of the parse tree.scope - The scope for evaluation.IllegalActionException - If an error occurs during
evaluation.public void visitArrayConstructNode(ASTPtArrayConstructNode node) throws IllegalActionException
visitArrayConstructNode in interface ParseTreeVisitorvisitArrayConstructNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitBitwiseNode(ASTPtBitwiseNode node) throws IllegalActionException
visitBitwiseNode in interface ParseTreeVisitorvisitBitwiseNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException
MatlabUtilities.evaluate(String, Set, ParserScope)
.visitFunctionApplicationNode in interface ParseTreeVisitorvisitFunctionApplicationNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node) throws IllegalActionException
visitFunctionDefinitionNode in interface ParseTreeVisitorvisitFunctionDefinitionNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitFunctionalIfNode(ASTPtFunctionalIfNode node) throws IllegalActionException
visitFunctionalIfNode in interface ParseTreeVisitorvisitFunctionalIfNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
visitLeafNode in interface ParseTreeVisitorvisitLeafNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitLogicalNode(ASTPtLogicalNode node) throws IllegalActionException
visitLogicalNode in interface ParseTreeVisitorvisitLogicalNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitMatrixConstructNode(ASTPtMatrixConstructNode node) throws IllegalActionException
visitMatrixConstructNode in interface ParseTreeVisitorvisitMatrixConstructNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitMethodCallNode(ASTPtMethodCallNode node) throws IllegalActionException
visitMethodCallNode in interface ParseTreeVisitorvisitMethodCallNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitPowerNode(ASTPtPowerNode node) throws IllegalActionException
visitPowerNode in interface ParseTreeVisitorvisitPowerNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitProductNode(ASTPtProductNode node) throws IllegalActionException
visitProductNode in interface ParseTreeVisitorvisitProductNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitRecordConstructNode(ASTPtRecordConstructNode node) throws IllegalActionException
visitRecordConstructNode in interface ParseTreeVisitorvisitRecordConstructNode in class AbstractParseTreeVisitornode - The record constructor node.IllegalActionException - If an evaluation error occurs.public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException
visitRelationalNode in interface ParseTreeVisitorvisitRelationalNode in class AbstractParseTreeVisitorIllegalActionExceptionpublic void visitShiftNode(ASTPtShiftNode node) throws IllegalActionException
visitShiftNode in interface ParseTreeVisitorvisitShiftNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitSumNode(ASTPtSumNode node) throws IllegalActionException
visitSumNode in interface ParseTreeVisitorvisitSumNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionException - If an evaluation error occurs.public void visitUnaryNode(ASTPtUnaryNode node) throws IllegalActionException
visitUnaryNode in interface ParseTreeVisitorvisitUnaryNode in class AbstractParseTreeVisitornode - The specified node.IllegalActionExceptionpublic void visitUnionConstructNode(ASTPtUnionConstructNode node) throws IllegalActionException
visitUnionConstructNode in interface ParseTreeVisitorvisitUnionConstructNode in class AbstractParseTreeVisitornode - The union constructor node.IllegalActionException - If an evaluation error occurs.protected void _assert(boolean flag,
ASTPtRootNode node,
java.lang.String message)
flag - The flag that is asserted to be true.node - The node on which the assertion is asserted.message - The message to include in the exception.InternalErrorException - If the assertion is violated.
Note that this is a runtime exception, so it need not be declared
explicitly.protected Token[] _evaluateAllChildren(ASTPtRootNode node) throws IllegalActionException
node - The node whose children are evaluated.IllegalActionException - If an evaluation error occurs.protected Token _evaluateArrayIndex(ASTPtRootNode node, Token value, Token index) throws IllegalActionException
node - The node that caused this method to be called.value - The token that is being indexed into, which must
be an ArrayToken.index - The index, which must be an integer token.IllegalActionException - If an evaluation error occurs.protected Token _evaluateChild(ASTPtRootNode node, int i) throws IllegalActionException
IllegalActionException - If an evaluation error occurs.protected Token _evaluateMatrixIndex(ASTPtRootNode node, Token value, Token rowIndex, Token columnIndex) throws IllegalActionException
node - The node that caused this method to be called.value - The token that is being indexed into, which must
be a MatrixToken.rowIndex - The row index, which must be an integer token.columnIndex - The column index, which must be an integer token.IllegalActionException - If an evaluation error occurs.protected Token _functionCall(java.lang.String functionName, Type[] argTypes, java.lang.Object[] argValues) throws IllegalActionException
functionName - The function name.argTypes - An array of argument types.argValues - An array of argument values.IllegalActionException - If an evaluation error occurs.protected Token _methodCall(java.lang.String methodName, Type[] argTypes, java.lang.Object[] argValues) throws IllegalActionException
methodName - The method name.argTypes - An array of argument types.argValues - An array of argument values.IllegalActionException - If an evaluation error occurs.protected void _trace(java.lang.String string)
protected void _traceEnter(ASTPtRootNode node)
protected void _traceLeave(ASTPtRootNode node)