001/* ASTPtRelationalNodes represent relational operator(>, >=, <, <=, ==, !=)
002 nodes in the parse tree.
003
004 Copyright (c) 1998-2014 The Regents of the University of California.
005 All rights reserved.
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the above
009 copyright notice and the following two paragraphs appear in all copies
010 of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025 PT_COPYRIGHT_VERSION_2
026 COPYRIGHTENDKEY
027
028
029 Created : May 1998
030
031 */
032package ptolemy.data.expr;
033
034import java.util.Map;
035
036import ptolemy.kernel.util.IllegalActionException;
037
038//////////////////////////////////////////////////////////////////////////
039//// ASTPtRelationalNode
040
041/**
042 The parse tree created from the expression string consists of a
043 hierarchy of node objects. This class represents relational
044 operator(&gt;, &ge;, &lt;, &le;, ==, !=) nodes in the parse tree.
045 <p>
046 Each node of this type has exactly two children. The resolved type
047 is a BooleanToken.</p>
048
049 @author Neil Smyth
050 @version $Id$
051 @since Ptolemy II 0.2
052 @Pt.ProposedRating Yellow (nsmyth)
053 @Pt.AcceptedRating Red (cxh)
054 @see ptolemy.data.expr.ASTPtRootNode
055 @see ptolemy.data.expr.PtParser
056 @see ptolemy.data.Token
057 */
058public class ASTPtRelationalNode extends ASTPtRootNode {
059    public ASTPtRelationalNode(int id) {
060        super(id);
061    }
062
063    public ASTPtRelationalNode(PtParser p, int id) {
064        super(p, id);
065    }
066
067    /** Return the lexical token representing the operation of this node.
068     *  @return the token that represents the operation of this node.
069     */
070    public Token getOperator() {
071        return _lexicalToken;
072    }
073
074    /** Return true if this node is (hierarchically) congruent to the
075     *  given node, under the given renaming of bound identifiers.
076     *  Derived classes should extend this method to add additional
077     *  necessary congruency checks.
078     *  @param node The node to compare to.
079     *  @param renaming A map from String to String that gives a
080     *  renaming from identifiers in this node to identifiers in the
081     *  given node.
082     */
083    @Override
084    public boolean isCongruent(ASTPtRootNode node, Map renaming) {
085        if (!super.isCongruent(node, renaming)) {
086            return false;
087        }
088
089        if (_lexicalToken.kind != ((ASTPtRelationalNode) node)._lexicalToken.kind) {
090            return false;
091        }
092
093        return true;
094    }
095
096    /** Traverse this node with the given visitor.
097     */
098    @Override
099    public void visit(ParseTreeVisitor visitor) throws IllegalActionException {
100        visitor.visitRelationalNode(this);
101    }
102
103    protected Token _lexicalToken = null;
104}