|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectptolemy.data.expr.AbstractParseTreeVisitor
ptolemy.data.expr.ParseTreeEvaluator
ptolemy.domains.fsm.kernel.ParseTreeEvaluatorForGuardExpression
A ParseTreeEvaluatorForGuardExpression contains a relation list which is used to indicate the value change of the relations embedded in a guard expression. It extends ParseTreeEvaluator. It is specially designed for guard expressions associated with transitions of FSM. It visits a parse tree and evaluates it into a token.
The ParseTreeEvaluatorForGuardExpression has two operation modes: construction and updat. During construction mode, the relation list expands. During update mode, the relation list doesn't expand but has its element updated.
During the parse tree evaluation, if the visiting node is a leaf node and the evaluated token is a boolean token, or the visiting node is a relational node, the evaluator decides the 'difference' and 'relationType' of the node, and stores these information into the relation list.
The 'difference' of a node is calculated this way:
For a leaf node evaluated as a boolean token, the difference is 0. For a relation node, (scalarLeft relationOperator scalarRight), the difference is the absolute double value of (scalarLeft - scalarRight).
The 'relationType' of a node has 5 different values with meaning: 1: true; 2: false; 3: equal/inequal; 4: less_than: 5: bigger_than. It is calculated this way:
For a leaf node evaluated as a boolean token, the relationType is assigned according to the boolean value of the result token, 1 for true and 2 for false. For a relation node, (scalarLeft relationOperator scalarRight), the relationType depends on the relationOperator. If the relationOperator is '==' or '!=', rhe relationType can be 3 indicating the two scalars equal or not equal, 4 indicating the left scalar is less than the right one, and 5 to indicate left scalar is bigger than the right one. For other kind of relationOperators, the relationType is assigned according to the boolean value of the relation, i.e., 1 for true and 2 for false.
If the evaluator is in construction mode, the node information is added into a relationList, if it is in update mode, the according element of a relationList gets updated.
Note, this evaluator does not use short-circuit evaluation on logical nodes.
RelationList,
ParseTreeEvaluator
| Red (hyzheng) |
| Red (hyzheng) |
| Field Summary |
| Fields inherited from class ptolemy.data.expr.ParseTreeEvaluator |
_evaluatedChildToken |
| Constructor Summary | |
ParseTreeEvaluatorForGuardExpression(RelationList relationList,
double errorTolerance)
Construct a parse tree evaluator for guard expression. |
|
| Method Summary | |
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. |
void |
setConstructionMode(boolean mode)
Set the mode of parse tree evaluator. |
void |
visitLeafNode(ASTPtLeafNode node)
Visit the leaf node. |
void |
visitLogicalNode(ASTPtLogicalNode node)
Visit the logical node. |
void |
visitRelationalNode(ASTPtRelationalNode node)
Visit the relation node. |
| Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor |
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ParseTreeEvaluatorForGuardExpression(RelationList relationList,
double errorTolerance)
relationList - The relation list.errorTolerance - The errorTolerance.| Method Detail |
public Token evaluateParseTree(ASTPtRootNode node,
ParserScope scope)
throws IllegalActionException
evaluateParseTree in class ParseTreeEvaluatornode - The root of the parse tree.scope - The scope for evaluation.
IllegalActionException - If an error occurs during
evaluation.public void setConstructionMode(boolean mode)
mode - The mode of the parse tree evaluator.
public void visitLeafNode(ASTPtLeafNode node)
throws IllegalActionException
visitLeafNode in interface ParseTreeVisitorvisitLeafNode in class ParseTreeEvaluatornode - The leaf node to be evaluated.
IllegalActionException - If the super class method
visitLeafNode throws the IllegalActionException.
public void visitLogicalNode(ASTPtLogicalNode node)
throws IllegalActionException
visitLogicalNode in interface ParseTreeVisitorvisitLogicalNode in class ParseTreeEvaluatornode - The logical node to be evaluated.
IllegalActionException - If the super class method
visitLogicalNode throws the IllegalActionException.
public void visitRelationalNode(ASTPtRelationalNode node)
throws IllegalActionException
visitRelationalNode in interface ParseTreeVisitorvisitRelationalNode in class ParseTreeEvaluatornode - The relation node to be evaluated.
IllegalActionException - If the super class method
visitRelationNode throws the IllegalActionException.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||