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