/*======================================================================== Copyright (C) 2006 by Geir-Tore Lindsve, Torbjørn Meistad and Yngve Raudberget, hereby refered to as "the authors". All rights reserved Permission is hereby granted, without written agreement and without license or royalty fees, to use, reproduce, prepare derivative works, distribute, and display this software and its documentation for NONCOMMERCIAL RESEARCH AND EDUCATIONAL PURPOSES, provided that (1) the above copyright notice and the following two paragraphs appear in all copies of the source code and (2) redistributions, including without limitation binaries, reproduce these notices in the supporting documentation. IN NO EVENT SHALL THE AUTHORS, OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ========================================================================*/ using System; using System.Collections.Generic; using System.Text; using CLab.Exceptions; using CLab.CSP; using Casper.Data; namespace CLab.Data { /// /// Abstract class for the different types of Expressions /// abstract public class Expression { private Common.ExprType type; /// /// Constructor /// /// The type of the expression: This can be either an operator /// working on a left and right side, or an id or integer expression public Expression(Common.ExprType type) { this.type = type; } /// /// Returns the type of this expression /// /// The type of the expression. public Common.ExprType Type { get { return this.type; } } /// /// Abstract method which runs CSPBuildExpr in CLab.CSP.CSPExpressionBuilder /// Double dispatch pattern /// /// The CSPExpressionBuilder. /// internal abstract CSPExpr RunCSPBuildExpr(CSPExpressionBuilder builder); /// /// Converts the type to an operator sign for printout /// /// The operator to print out /// public String Type2oper(Common.ExprType type) { String setOper; switch (type) { case Common.ExprType.et_impl: setOper = ">>"; break; case Common.ExprType.et_or: setOper = "|"; break; case Common.ExprType.et_and: setOper = "&"; break; case Common.ExprType.et_lte: setOper = "<="; break; case Common.ExprType.et_gte: setOper = ">="; break; case Common.ExprType.et_lt: setOper = "<"; break; case Common.ExprType.et_gt: setOper = ">"; break; case Common.ExprType.et_ne: setOper = "!="; break; case Common.ExprType.et_eq: setOper = "=="; break; case Common.ExprType.et_minus: setOper = "-"; break; case Common.ExprType.et_plus: setOper = "+"; break; case Common.ExprType.et_mod: setOper = "%"; break; case Common.ExprType.et_div: setOper = "/"; break; case Common.ExprType.et_times: setOper = "*"; break; default: throw new ClabInternalErrorException("Invalid ExpressionGammel type"); } return setOper; } } }