00001
00010 #ifndef __JBLPARSERRESULT_H
00011 #define __JBLPARSERRESULT_H
00012
00013 #include "jbltools/sfh/JBLToken.h"
00014 #include "jbltools/sfh/Float_FF.h"
00015 #include <string>
00016 #include <iosfwd>
00017
00018 class FloatFun;
00019 class IntFun;
00020 class BaseCut;
00021
00022
00024
00046 class JBLParserResult {
00047 public:
00048
00050 JBLParserResult();
00052 JBLParserResult(const JBLParserResult &rhs);
00053 private:
00055 JBLParserResult(int intvalue_
00056 );
00058 JBLParserResult(Float_FF floatvalue_
00059 );
00061 JBLParserResult(bool boolvalue_
00062 );
00064 JBLParserResult(IntFun &intfunvalue_
00065 );
00067 JBLParserResult(FloatFun &floatfunvalue_
00068 );
00070 JBLParserResult(BaseCut &basecutvalue_
00071 );
00073 JBLParserResult(const std::string& name_
00074 );
00075 public:
00077 ~JBLParserResult();
00078
00080 JBLParserResult& operator= (const JBLParserResult &rhs);
00081
00083 bool isEmpty() const {return type == EMPTY;}
00085 bool isNumber() const {return type & NUMBER;}
00087 bool isInt() const {return type == INT;}
00089 bool isFloat() const {return type == FLOAT;}
00091 bool isBool() const {return type == BOOL;}
00093 bool isIntFun() const {return type == INTFUN;}
00095 bool isFloatFun() const {return type == FLOATFUN;}
00097 bool isFun() const {return type & FUN;}
00099 bool isBaseCut() const {return type== BASECUT;}
00101 bool isIdentifier() const {return type== IDENTIFIER;}
00103 int listlength() const;
00104
00106 const std::string& getName() const {return name;}
00107
00109 static JBLParserResult parseExpression (const std::string& input);
00110
00112 static JBLParserResult parseExpression (std::istream& is);
00113
00115 int getIntValue() const;
00117 Float_FF getFloatValue() const;
00119 bool getBoolValue() const;
00120
00122 IntFun *getIntFunValue() const;
00124 FloatFun *getFloatFunValue() const;
00126 BaseCut *getBaseCutValue() const;
00127
00129 std::ostream& print(std::ostream& os
00130 ) const;
00132 JBLParserResult& addCopyToList(const JBLParserResult &rhs
00133 );
00134 private:
00135 static JBLToken token;
00136
00137 static JBLParserResult expression (std::istream& is);
00138 static JBLParserResult assignment_expression (std::istream& is);
00139 static JBLParserResult conditional_expression (std::istream& is);
00140 static JBLParserResult logical_OR_expression (std::istream& is);
00141 static JBLParserResult logical_AND_expression (std::istream& is);
00142 static JBLParserResult inclusive_OR_expression (std::istream& is);
00143 static JBLParserResult exclusive_OR_expression (std::istream& is);
00144 static JBLParserResult AND_expression (std::istream& is);
00145 static JBLParserResult equality_expression (std::istream& is);
00146 static JBLParserResult relational_expression (std::istream& is);
00147 static JBLParserResult shift_expression (std::istream& is);
00148 static JBLParserResult additive_expression (std::istream& is);
00149 static JBLParserResult multiplicative_expression (std::istream& is);
00150 static JBLParserResult cast_expression (std::istream& is);
00151 static JBLParserResult unary_expression (std::istream& is);
00152 static JBLParserResult postfix_expression (std::istream& is);
00153 static JBLParserResult primary_expression (std::istream& is);
00154 static JBLParserResult argument_expression_list (std::istream& is);
00155 static JBLParserResult syntaxError (const std::string& text);
00156
00157 template <class T1, class T2>
00158 static JBLParserResult comparison (int op, const T1& lhs, const T2& rhs);
00159
00160 static JBLParserResult makeoperation (int op, const std::string& opname, JBLParserResult& lhs, JBLParserResult& rhs);
00161
00162 static JBLParserResult makefloatfunction (const std::string& fname, JBLParserResult& arglist);
00163
00164 private:
00165 enum Type {EMPTY=0, INT=1, FLOAT=2, NUMBER=3, BOOL=4, INTFUN=8, FLOATFUN=16, FUN=24, BASECUT=32, IDENTIFIER=64};
00166
00167 public:
00168 typedef Float_FF (*Fun_f_f) (Float_FF);
00169 typedef Float_FF (*Fun_f_f_f) (Float_FF,Float_FF);
00170 typedef Float_FF (*Fun_f_f_i) (Float_FF,Float_FF);
00171 typedef int (*Fun_i_i) (int);
00172 typedef bool (*Fun_b_b) (bool);
00173 typedef FloatFun& (*Fun_FF_FF) (const FloatFun&);
00174 typedef FloatFun& (*Fun_FF_FF_FF)(const FloatFun&,const FloatFun&);
00175 typedef FloatFun& (*Fun_FF_FF_IF)(const FloatFun&,const IntFun&);
00176 typedef IntFun& (*Fun_IF_IF) (const IntFun&);
00177 typedef BaseCut& (*Fun_BC_BC) (const BaseCut&);
00178
00179
00180 private:
00181
00182 Type type;
00183 int intvalue;
00184 Float_FF floatvalue;
00185 bool boolvalue;
00186 IntFun *intfunvalue;
00187 FloatFun *floatfunvalue;
00188 BaseCut *basecutvalue;
00189 std::string name;
00190 JBLParserResult *next;
00191
00192 public:
00193 static void initMaps();
00194
00195
00196 struct Init {
00197 Init();
00198 static int counter;
00199 };
00200
00201 };
00202
00203 static JBLParserResult::Init the_Init_Object;
00204
00206
00210 std::istream& operator>> (std::istream& is, JBLParserResult& result);
00211
00213
00217 std::ostream& operator<< (std::ostream& os, const JBLParserResult& result);
00218
00219 #endif