Home

Download

Features

Screenshots

Usage

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

fparser.hh

00001 /***************************************************************************\
00002 |* Function parser v2.2 by Warp                                            *|
00003 |*                                                                         *|
00004 |* Qt translations, degrees/angle, more functions(cot,sec,csc),            *|
00005 |* and modified log function added by                                      *|
00006 |* Fungmeista (mizunoami44@users.sourceforge.net).                         *|
00007 |* ----------------------------                                            *|
00008 |* Parses and evaluates the given funtion with the given variable values.  *|
00009 |*                                                                         *|
00010 \***************************************************************************/
00011 
00012 #ifndef ONCE_FPARSER_H_
00013 #define ONCE_FPARSER_H_
00014 
00015 #include <string>
00016 #include <map>
00017 
00022 class FunctionParser
00023 {
00024 public:
00025     int Parse(const std::string& Function, const std::string& Vars);
00026     const char* ErrorMsg(void) const;
00027     double Eval(const double* Vars);
00028     inline int EvalError(void) const { return EvalErrorType; }
00029 
00030 
00031 
00032     FunctionParser(int mode = RADIANS); //angle added by Fungmeista
00033     ~FunctionParser();
00034     static const int DEGREES = 0;      //added by Fungmeista
00035     static const int RADIANS = 1;      // ditto
00036 
00037 
00038 protected:
00039     int ParseErrorType; //moved from private to protected by Fungmeista
00040     
00041 //========================================================================
00042 private:
00043 //========================================================================
00044     int varAmount, EvalErrorType;
00045 
00046     typedef std::map<std::string, unsigned> VarMap_t;
00047     VarMap_t Variables;
00048 
00049     struct Comp
00050     {   Comp();
00051         Comp(const Comp&);
00052         ~Comp();
00053 
00054         unsigned* ByteCode;
00055         unsigned ByteCodeSize;
00056         double* Immed;
00057         unsigned ImmedSize;
00058         double* Stack;
00059         unsigned StackSize, StackPtr;
00060         bool thisIsACopy;
00061     } Comp;
00062 
00063     VarMap_t::const_iterator FindVariable(const char*);
00064     int CheckSyntax(const char*);
00065     bool Compile(const char*);
00066     bool IsVariable(int);
00067     void AddCompiledByte(unsigned);
00068     int CompileIf(const char*, int);
00069     int CompileElement(const char*, int);
00070     int CompilePow(const char*, int);
00071     int CompileMult(const char*, int);
00072     int CompileAddition(const char*, int);
00073     int CompileComparison(const char*, int);
00074     int CompileAnd(const char*, int);
00075     int CompileOr(const char*, int);
00076     int CompileExpression(const char*, int, bool=false);
00077 
00078     FunctionParser(const FunctionParser&);
00079     int mode;                  //added by Fungmeista for angle mode (radians/degrees)
00080 };
00081 
00082 #endif

Generated on Mon Jun 2 22:43:22 2003 for Fung-Calc by doxygen1.2.17