Add project files.
This commit is contained in:
25
libpoly/include/Base.h
Normal file
25
libpoly/include/Base.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __POLY_BASE_H__
|
||||
#define __POLY_BASE_H__
|
||||
|
||||
#define MID_UNKNOWN 0
|
||||
#define MID_NUMBER 256
|
||||
#define MID_VARIABLE 512
|
||||
#define MID_SYMBOL 1024
|
||||
|
||||
#define MID_LONG MID_NUMBER + 1
|
||||
#define MID_SQRT MID_NUMBER + 2
|
||||
#define MID_FRACTION MID_NUMBER + 3
|
||||
|
||||
class CBase
|
||||
{
|
||||
public:
|
||||
bool isSymbol();
|
||||
bool isVar();
|
||||
bool isNumber();
|
||||
int id;
|
||||
CBase();
|
||||
virtual ~CBase();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
36
libpoly/include/Constants.h
Normal file
36
libpoly/include/Constants.h
Normal file
@ -0,0 +1,36 @@
|
||||
#define MAXVALUE 0
|
||||
#define NONE MAXVALUE
|
||||
#define ROOT MAXVALUE + 1
|
||||
#define MUL MAXVALUE + 2
|
||||
#define PLU MAXVALUE + 3
|
||||
#define POW MAXVALUE + 4
|
||||
#define MIN MAXVALUE + 5
|
||||
#define DIV MAXVALUE + 6
|
||||
#define OPEN MAXVALUE + 7
|
||||
#define CLOSE MAXVALUE + 8
|
||||
#define NUM MAXVALUE + 9
|
||||
#define ID MAXVALUE + 10
|
||||
#define EOS MAXVALUE + 11
|
||||
#define COS MAXVALUE + 12
|
||||
#define SIN MAXVALUE + 13
|
||||
#define TAN MAXVALUE + 14
|
||||
#define COSEC MAXVALUE + 15
|
||||
#define CSC COSEC
|
||||
#define SEC MAXVALUE + 16
|
||||
#define COT MAXVALUE + 17
|
||||
#define PI ID
|
||||
#define EXP ID
|
||||
#define LOG MAXVALUE + 18
|
||||
#define LN MAXVALUE + 19
|
||||
#define LOG10 MAXVALUE + 20
|
||||
|
||||
#define ABS MAXVALUE + 21
|
||||
#define MINF MAXVALUE + 22
|
||||
#define MAXF MAXVALUE + 23
|
||||
#define IRAND MAXVALUE + 24
|
||||
#define FRAND MAXVALUE + 25
|
||||
#define MOD MAXVALUE + 26
|
||||
#define FLOOR MAXVALUE + 27
|
||||
#define SIGN MAXVALUE + 28
|
||||
|
||||
#define MAXSTACK 100
|
56
libpoly/include/Poly.h
Normal file
56
libpoly/include/Poly.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef __POLY_POLY_H__
|
||||
#define __POLY_POLY_H__
|
||||
|
||||
#include "SymTable.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
class CPoly
|
||||
{
|
||||
public:
|
||||
CPoly();
|
||||
virtual ~CPoly();
|
||||
|
||||
int Analyze(const char * pszStr = NULL);
|
||||
double Eval();
|
||||
void SetStr(const std::string & str);
|
||||
int SetVar(const std::string & strName, double dVar);
|
||||
double GetVar(const std::string & strName);
|
||||
void Clear();
|
||||
|
||||
protected:
|
||||
int my_irandom(double start, double end);
|
||||
double my_frandom(double start, double end);
|
||||
|
||||
void init();
|
||||
int insert(const std::string & s, int tok);
|
||||
int find(const std::string & s);
|
||||
void emit(int t,int tval);
|
||||
void match(int t);
|
||||
void expo();
|
||||
void factor();
|
||||
void term();
|
||||
int lexan();
|
||||
void error();
|
||||
void expr();
|
||||
|
||||
int iToken;
|
||||
double iNumToken;
|
||||
int iLookAhead;
|
||||
int iErrorPos;
|
||||
bool ErrorOccur;
|
||||
unsigned int uiLookPos;
|
||||
|
||||
// NOTE: list is slight faster than vector, why?!
|
||||
std::vector<int> tokenBase;
|
||||
std::vector<double> numBase;
|
||||
std::vector<CSymTable *> lSymbol;
|
||||
std::vector<int> SymbolIndex;
|
||||
int STSize;
|
||||
std::string strData;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
17
libpoly/include/SymTable.h
Normal file
17
libpoly/include/SymTable.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __POLY_SYMTABLE_H__
|
||||
#define __POLY_SYMTABLE_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
class CSymTable
|
||||
{
|
||||
public:
|
||||
CSymTable(int aTok, std::string aStr);
|
||||
virtual ~CSymTable();
|
||||
|
||||
double dVal;
|
||||
int token;
|
||||
std::string strlex;
|
||||
};
|
||||
|
||||
#endif
|
39
libpoly/include/Symbol.h
Normal file
39
libpoly/include/Symbol.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __POLY_SYMBOL_H__
|
||||
#define __POLY_SYMBOL_H__
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#define ST_UNKNOWN 0
|
||||
#define ST_PLUS 11
|
||||
#define ST_MINUS 12
|
||||
#define ST_MULTIPLY 23
|
||||
#define ST_DIVIDE 24
|
||||
#define ST_CARET 35
|
||||
#define ST_OPEN 06
|
||||
#define ST_CLOSE 07
|
||||
|
||||
#define SY_PLUS '+'
|
||||
#define SY_MINUS '-'
|
||||
#define SY_MULTIPLY '*'
|
||||
#define SY_DIVIDE '/'
|
||||
#define SY_CARET '^'
|
||||
#define SY_OPEN '('
|
||||
#define SY_CLOSE ')'
|
||||
|
||||
class CSymbol : public CBase
|
||||
{
|
||||
private:
|
||||
int iType;
|
||||
|
||||
public:
|
||||
CSymbol();
|
||||
virtual ~CSymbol();
|
||||
|
||||
static int issymbol(int ch);
|
||||
void SetType(int Type);
|
||||
int GetType();
|
||||
bool Equal(CSymbol dif);
|
||||
bool Less(CSymbol dif);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user