Class ParseTreeEvaluatorForGuardExpression
- java.lang.Object
-
- ptolemy.data.expr.AbstractParseTreeVisitor
-
- ptolemy.data.expr.ParseTreeEvaluator
-
- ptolemy.domains.modal.kernel.ParseTreeEvaluatorForGuardExpression
-
- All Implemented Interfaces:
ParseTreeVisitor
public class ParseTreeEvaluatorForGuardExpression extends ParseTreeEvaluator
This class extends the ParseTreeEvaluator class. It is specially designed for guard expressions associated with transitions of FSM. An object of this class is a visitor that visits a parse tree of a guard expression and evaluates it into a token. Meanwhile, this visitor stores the type and difference of all relations of the guard expression into a relation list. Here a relation means an expression that does not contain a logical operator.This visitor has two modes of operation: construction mode and update mode. During the construction mode, this visitor constructs a relation list where each element of the list corresponds to a relation of the guard expression. The order of the elements is fixed and it is the same as the order that the relations appear in the guard expression. If the guard expression changes, the relation list will be reconstructed. During the update mode, the relation list gets updated only. The order of the elements get updated is the same order the relations of the guard expression get evaluated.
When this visitor evaluates the parse tree, 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 visiting node is treated as a relation. The visitor evaluates the 'difference' and 'relationType' of this relation, and stores the evaluation results into the corresponding element in the relation list.
The 'difference' of a relation is calculated in the following way. For a leaf node evaluated as a boolean token, the difference is 0. This situation corresponds to the "true", or "false", or "x_isPresent" elements in a guard expression. For a relational node with the format (scalarLeft relationOperator scalarRight), the difference is the absolute double value of (scalarLeft - scalarRight). For details of relation type, see
RelationType
.If the evaluator is in the construction mode, the relation information is added into the relation list, if it is in the update mode, the corresponding element of the relation List gets updated.
Note, this evaluator does not use short-circuit evaluation on logical nodes, meaning all nodes will be evaluated.
- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Haiyang Zheng
- See Also:
RelationList
,ParseTreeEvaluator
- Pt.AcceptedRating:
- Red (hyzheng)
- Pt.ProposedRating:
- Red (hyzheng)
-
-
Field Summary
-
Fields inherited from class ptolemy.data.expr.ParseTreeEvaluator
_evaluatedChildToken, _typeInference
-
-
Constructor Summary
Constructors Constructor Description ParseTreeEvaluatorForGuardExpression(RelationList relationList, double errorTolerance)
Construct a parse tree evaluator for a guard expression of the given relation list and the error tolerance for evaluation the relations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.RelationList
getRelationList()
Return the list of relations (boolean-valued expressions that do not contain a logical operator, such as comparison expressions) in the guard expression of this transition.void
setConstructionMode()
Set parse tree evaluator to be in construction mode.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.ParseTreeEvaluator
_assert, _evaluateAllChildren, _evaluateArrayIndex, _evaluateChild, _evaluateMatrixIndex, _functionCall, _methodCall, _trace, _traceEnter, _traceLeave, evaluateParseTree, traceParseTreeEvaluation, visitArrayConstructNode, visitBitwiseNode, visitFunctionalIfNode, visitFunctionApplicationNode, visitFunctionDefinitionNode, visitMatrixConstructNode, visitMethodCallNode, visitPowerNode, visitProductNode, visitRecordConstructNode, visitShiftNode, visitSumNode, visitUnaryNode, visitUnionConstructNode
-
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode
-
-
-
-
Constructor Detail
-
ParseTreeEvaluatorForGuardExpression
public ParseTreeEvaluatorForGuardExpression(RelationList relationList, double errorTolerance)
Construct a parse tree evaluator for a guard expression of the given relation list and the error tolerance for evaluation the relations. The relation stores the information of the relation. After the parse tree evaluator is created, it is always in construction mode.- Parameters:
relationList
- The relation list.errorTolerance
- The errorTolerance.
-
-
Method Detail
-
evaluateParseTree
public Token evaluateParseTree(ASTPtRootNode node, ParserScope scope) throws IllegalActionException
Evaluate the parse tree with the specified root node using the specified scope to resolve the values of variables.- Overrides:
evaluateParseTree
in classParseTreeEvaluator
- Parameters:
node
- The root of the parse tree.scope
- The scope for evaluation.- Returns:
- The result of evaluation.
- Throws:
IllegalActionException
- If an error occurs during evaluation.
-
getRelationList
public RelationList getRelationList()
Return the list of relations (boolean-valued expressions that do not contain a logical operator, such as comparison expressions) in the guard expression of this transition.- Returns:
- The list of relations.
-
setConstructionMode
public void setConstructionMode()
Set parse tree evaluator to be in construction mode. Clear the relation list and the relation list will be populated, based on the nodes in the parse tree.
-
visitLeafNode
public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
Visit the leaf node. It is evaluated the same way as normal parse tree evaluator, except that if the the result is a boolean token, the information about the node (the difference and relationType) is either added into the relation list or used to update the corresponding element in the relation list, depending on the evaluator mode.- Specified by:
visitLeafNode
in interfaceParseTreeVisitor
- Overrides:
visitLeafNode
in classParseTreeEvaluator
- Parameters:
node
- The leaf node to be evaluated.- Throws:
IllegalActionException
- If the super class method visitLeafNode throws the IllegalActionException.
-
visitLogicalNode
public void visitLogicalNode(ASTPtLogicalNode node) throws IllegalActionException
Visit the logical node. This visitor does not use short-circuit evaluation. It evaluates both the nodes beside the logical operator.- Specified by:
visitLogicalNode
in interfaceParseTreeVisitor
- Overrides:
visitLogicalNode
in classParseTreeEvaluator
- Parameters:
node
- The logical node to be evaluated.- Throws:
IllegalActionException
- If the super class method visitLogicalNode throws the IllegalActionException.
-
visitRelationalNode
public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException
Visit the relation node. The evaluation part is the same as normal parseTreeEvaluator, except that information about each relation (the difference and relationType) is either added into the relation list or used to update the corresponding element in the relation list, depending on the evaluator mode.- Specified by:
visitRelationalNode
in interfaceParseTreeVisitor
- Overrides:
visitRelationalNode
in classParseTreeEvaluator
- Parameters:
node
- The relation node to be evaluated.- Throws:
IllegalActionException
- If the super class method visitRelationNode throws the IllegalActionException.
-
-