casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FuncExprData.h
Go to the documentation of this file.
00001 //# FuncExprData.h: Data and enumerations for functional expressions
00002 //# Copyright (C) 2001,2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: FuncExprData.h 21024 2011-03-01 11:46:18Z gervandiepen $
00028 
00029 #ifndef SCIMATH_FUNCEXPRDATA_H
00030 #define SCIMATH_FUNCEXPRDATA_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/stdmap.h>
00036 
00037 //# Forward Declarations
00038 #include <casa/iosfwd.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 // <summary> Data and enumerations for functional expressions
00043 // </summary>
00044 
00045 // <use visibility=local> 
00046 
00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //   <li> <linkto class=Function>Function</linkto> class
00052 // </prerequisite>
00053 //
00054 // <synopsis>
00055 // This class provides enumerations for expression analysis; and data element
00056 // descriptions
00057 // </synopsis>
00058 //
00059 // <example>
00060 // </example>
00061 //
00062 // <motivation>
00063 // To tie the Glish language to non-linear fitting procedures
00064 // </motivation>
00065 //
00066 // <thrown>
00067 //    <li>
00068 // </thrown>
00069 //
00070 // <todo asof="2001/11/21">
00071 //   <li> nothing directly
00072 // </todo>
00073 
00074 class FuncExprData {
00075 public:
00076   //# Enumerations
00077   // Operations
00078   enum opTypes {
00079     NOP=0,
00080     UNAMIN,
00081     UNAPLUS,
00082     NON,
00083     POW,
00084     GTE,
00085     LTE,
00086     EQ,
00087     NEQ,
00088     OR,
00089     AND,
00090     CONDEX,
00091     CONDEX2,
00092     CONDEX3,
00093     ADD,
00094     SUB,
00095     MUL,
00096     DIV,
00097     LT,
00098     GT,
00099     CONST,
00100     PARAM,
00101     ARG,
00102     TOIMAG,
00103     LBRACE,
00104     RBRACE,
00105     LPAREN,
00106     RPAREN,
00107     LBR,
00108     RBR,
00109     COMMA,
00110     FINISH,
00111     GOTO,
00112     GOTOF,
00113     GOTOT,
00114     SIN,
00115     COS,
00116     ATAN,
00117     ATAN2,
00118     ASIN,
00119     ACOS,
00120     EXP,
00121     EXP10,
00122     EXP2,
00123     LOG,
00124     LOG10,
00125     LOG2,
00126     ERF,
00127     ERFC,
00128     PI,
00129     EE,
00130     ABS,
00131     FLOOR,
00132     CEIL,
00133     ROUND,
00134     INT,
00135     FRACT,
00136     SQRT,
00137     COMPLEX,
00138     REAL,
00139     IMAG,
00140     AMPL,
00141     PHASE,
00142     // Number
00143     NopTypes };
00144 
00145   // Operation category
00146   enum opCategories {
00147     // Unary, binary  1 or 2 character
00148     UNA2, UNA1, BIN2, BIN1, 
00149     // Special and functions
00150     SPEC, FUNC,
00151     // Number
00152     NopCategories };
00153   // Special categories
00154   enum specAction {
00155     NONE,
00156     // Save environment while compiling
00157     SAVENV,
00158     // Indicate a GOTO
00159     GOTOPC,
00160     // Final expression codes
00161     FINAL };
00162   // Special priority levels
00163   enum specPriority {
00164     // Lowest priority at which right-to-left rather than left-to-right
00165     // execution
00166     RTLPRI = 44,
00167     // Priority for specials - start
00168     SPCPRI = 60,
00169     // Priority for finals
00170     FINPRI = 00 };
00171 
00172   // The compilation state descriptor
00173   struct ExprCompState {
00174     // Old index of low RPS boundary
00175     uInt rpslow;
00176     // # of values available on value stack
00177     uInt nval;
00178     // Argument count
00179     uInt argcnt;
00180     // Previous saved program counter
00181     uInt pcptr;
00182   };
00183   // The operator description: code; priority; # of arguments; # of arguments
00184   // used up (or produced for functions)
00185   struct ExprOperator {
00186     // The operator code
00187     opTypes code;
00188     // The name (or characters)
00189     String name;
00190     // The category
00191     opCategories category;
00192     // Execution priority
00193     uInt priority;
00194     // # of arguments necessary (or minimum)
00195     uInt narg;
00196     // max # of arguments (for function)
00197     uInt nmaxarg;
00198     // # of results produced/used
00199     Int nresult;
00200     // code info (like par/x index; jump distance
00201     Int info;
00202     // special action
00203     specAction special;
00204     // state
00205     ExprCompState state;
00206   };
00207 
00208   //# Constructors
00209   // Construct the data for the expression analysis
00210   FuncExprData();
00211 
00212   // Destructor
00213   ~FuncExprData() {}
00214 
00215   //# Member functions
00216   // Accessors of the various maps
00217   // <group>
00218   map<String, ExprOperator> &unary2() { return una2_p; }
00219   const map<String, ExprOperator> &unary2() const { return una2_p; }
00220   map<String, ExprOperator> &unary1() { return una1_p; }
00221   const map<String, ExprOperator> &unary1() const { return una1_p; }
00222   map<String, ExprOperator> &binary2() { return bin2_p; }
00223   const map<String, ExprOperator> &binary2() const { return bin2_p; }
00224   map<String, ExprOperator> &binary1() { return bin1_p; }
00225   const map<String, ExprOperator> &binary1() const { return bin1_p; }
00226   map<String, ExprOperator> &special() { return spop_p; }
00227   const map<String, ExprOperator> &special() const { return spop_p; }
00228   map<String, ExprOperator> &function() { return func_p; }
00229   const map<String, ExprOperator> &function() const { return func_p; }
00230   // </group>
00231   // Print an operator map
00232   void print(ostream &os,
00233              const map<String, FuncExprData::ExprOperator> &m) const;
00234   // Print an operation
00235   void print(ostream &os, const FuncExprData::ExprOperator &pos) const;
00236 
00237 private:
00238   //# Data
00239   // Unary operators of 2 characters
00240   map<String, ExprOperator> una2_p;
00241   // Unary operators of 1 character
00242   map<String, ExprOperator> una1_p;
00243   // Binary operators of 2 characters
00244   map<String, ExprOperator> bin2_p;
00245   // Binary operators of 1 character
00246   map<String, ExprOperator> bin1_p;
00247   // Special operators
00248   map<String, ExprOperator> spop_p;
00249   // Function names
00250   map<String, ExprOperator> func_p;
00251   // All operators
00252   map<opTypes, ExprOperator> allop_p;
00253 };
00254 
00255 //# Global Functions
00256 
00257 // <summary> Output function </summary>
00258 
00259 // <group name=output>
00260 // Show a list of all defined operators and functions
00261 ostream &operator<<(ostream &os, const FuncExprData &ed);
00262 // </group>
00263 
00264 
00265 } //# NAMESPACE CASA - END
00266 
00267 #endif
00268 
00269 
00270