Class 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)
    • 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

      • 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 interface ParseTreeVisitor
        Overrides:
        visitLeafNode in class ParseTreeEvaluator
        Parameters:
        node - The leaf node to be evaluated.
        Throws:
        IllegalActionException - If the super class method visitLeafNode 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 interface ParseTreeVisitor
        Overrides:
        visitRelationalNode in class ParseTreeEvaluator
        Parameters:
        node - The relation node to be evaluated.
        Throws:
        IllegalActionException - If the super class method visitRelationNode throws the IllegalActionException.