Initial commit: server + serverfiles
This commit is contained in:
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#include "Base.h"
|
||||
|
||||
CBase::CBase()
|
||||
{
|
||||
id = 0;
|
||||
}
|
||||
|
||||
CBase::~CBase()
|
||||
{
|
||||
}
|
||||
|
||||
bool CBase::isNumber()
|
||||
{
|
||||
return (id & MID_NUMBER);
|
||||
}
|
||||
|
||||
bool CBase::isVar()
|
||||
{
|
||||
return (id & MID_VARIABLE);
|
||||
}
|
||||
|
||||
bool CBase::isSymbol()
|
||||
{
|
||||
return (id & MID_SYMBOL);
|
||||
}
|
||||
|
||||
Executable
+25
@@ -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
|
||||
Executable
+36
@@ -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
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
Base.o: Base.cc Base.h
|
||||
Poly.o: Poly.cc Poly.h SymTable.h Constants.h
|
||||
SymTable.o: SymTable.cc SymTable.h
|
||||
Symbol.o: Symbol.cc Symbol.h Base.h
|
||||
main.o: main.cc Poly.h SymTable.h
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
BIN = ./libpoly.a
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ### LINUX-BLOCK-BEGIN (Makefile platform detection)
|
||||
# On FreeBSD "uname -s" reports "FreeBSD", the ifeq is false, and every variable
|
||||
# below is assigned exactly as in the original Makefile. Only the Linux branch
|
||||
# is new. (Note the original's GCC_VERSION probe reads $(CC), which this
|
||||
# Makefile never sets - it is dead in the original too and is kept verbatim.)
|
||||
# ---------------------------------------------------------------------------
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
|
||||
CXX = g++
|
||||
|
||||
# -m32 : 32-bit server build.
|
||||
# -std=c++23 : matches game/src/Makefile and db/src/Makefile, so
|
||||
# libpoly's headers (Poly.h uses std::string,
|
||||
# std::vector, std::list) are parsed the same way in
|
||||
# the library and in its consumers.
|
||||
# -fno-exceptions -fno-rtti and -D_GLIBCXX_USE_CXX11_ABI=1 are kept from the
|
||||
# original: the ABI macro in particular MUST stay 1 or std::string would not
|
||||
# match game/ and db/.
|
||||
CFLAGS = -Wall -O2 -pipe -mtune=i686 -m32 -std=c++23 -D_GLIBCXX_USE_CXX11_ABI=1 -fno-exceptions -fno-rtti
|
||||
|
||||
ARFLAGS_POLY = cr
|
||||
|
||||
else
|
||||
|
||||
CXX = clang++-devel
|
||||
|
||||
GCC_VERSION = $(shell $(CC) --version 2>&1 | grep "(GCC)" | cut -d' ' -f3 | cut -d'.' -f1)
|
||||
|
||||
CFLAGS = -Wall -O2 -pipe -mtune=i686 -D_GLIBCXX_USE_CXX11_ABI=1 -fno-exceptions -fno-rtti
|
||||
|
||||
ARFLAGS_POLY = cru
|
||||
|
||||
endif
|
||||
# ### LINUX-BLOCK-END (Makefile platform detection)
|
||||
|
||||
LIBS =
|
||||
|
||||
# main.cc is deliberately NOT in this list, in the original Makefile as well:
|
||||
# it is a standalone test driver whose first include is <windows.h>.
|
||||
OBJFILES = Base.o Poly.o SymTable.o Symbol.o
|
||||
|
||||
default:
|
||||
$(MAKE) $(BIN)
|
||||
|
||||
$(BIN): $(OBJFILES)
|
||||
ar $(ARFLAGS_POLY) $(BIN) $(OBJFILES) $(LIBS)
|
||||
ranlib $(BIN)
|
||||
chmod 700 $(BIN)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(BIN)
|
||||
|
||||
dep:
|
||||
touch Depend
|
||||
$(CXX) $(CFLAGS) -MM *.cc > Depend
|
||||
|
||||
$(OBJFILES):
|
||||
$(CXX) $(CFLAGS) -c $<
|
||||
|
||||
include Depend
|
||||
Executable
+931
@@ -0,0 +1,931 @@
|
||||
#include <string>
|
||||
#include "Poly.h"
|
||||
#include "Constants.h"
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
double _random()
|
||||
{
|
||||
#ifndef __WIN32__
|
||||
return random() / (2147483648.0);
|
||||
#else
|
||||
return rand() / (2147483648.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int CPoly::my_irandom(double start, double end)
|
||||
{
|
||||
// Make range as inclusive-exclusive
|
||||
int is = int(start + 0.5);
|
||||
int ie = int(end - start + 0.5) + 1;
|
||||
|
||||
return int(_random() * ie + is);
|
||||
}
|
||||
|
||||
double CPoly::my_frandom(double start, double end)
|
||||
{
|
||||
return _random() * (end - start) + start;
|
||||
}
|
||||
|
||||
CPoly::CPoly()
|
||||
: iToken(0), iNumToken(0), iLookAhead(0), iErrorPos(0), ErrorOccur(true),
|
||||
uiLookPos(0), STSize(0)
|
||||
{
|
||||
lSymbol.clear();
|
||||
lSymbol.reserve(50);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
CPoly::~CPoly()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void CPoly::SetStr(const string & str)
|
||||
{
|
||||
strData = str;
|
||||
}
|
||||
|
||||
double CPoly::Eval()
|
||||
{
|
||||
int stNow;
|
||||
double save[MAXSTACK],t;
|
||||
int iSp=0;
|
||||
if (ErrorOccur)
|
||||
{
|
||||
/*THROW(new CEvalException("Evaluate Error"));*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TEST
|
||||
//list<int>::iterator pos = tokenBase.begin();
|
||||
//list<double>::iterator posn = numBase.begin();
|
||||
vector<int>::iterator pos = tokenBase.begin();
|
||||
vector<double>::iterator posn = numBase.begin();
|
||||
while (pos != tokenBase.end())
|
||||
{
|
||||
|
||||
stNow=*pos;
|
||||
++pos;
|
||||
switch (stNow)
|
||||
{
|
||||
case NUM:
|
||||
save[iSp++]=*posn++; break;
|
||||
case ID:
|
||||
save[iSp++]=
|
||||
lSymbol[ *pos ]->dVal;
|
||||
pos++;
|
||||
break;
|
||||
//case '+':
|
||||
case PLU:
|
||||
iSp--;
|
||||
save[iSp-1]+=save[iSp]; break;
|
||||
//case '-':
|
||||
case MIN:
|
||||
iSp--;
|
||||
save[iSp-1]-=save[iSp]; break;
|
||||
//case '*':
|
||||
case MUL:
|
||||
iSp--;
|
||||
save[iSp-1]*=save[iSp]; break;
|
||||
//case '%':
|
||||
case MOD:
|
||||
iSp--;
|
||||
if (save[iSp]==0)
|
||||
{
|
||||
//THROW(new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=fmod(save[iSp-1],save[iSp]); break;
|
||||
//case '/':
|
||||
case DIV:
|
||||
iSp--;
|
||||
if (save[iSp]==0)
|
||||
{
|
||||
//THROW(new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]/=save[iSp]; break;
|
||||
//case '^':
|
||||
case POW:
|
||||
iSp--;
|
||||
save[iSp-1]=pow(save[iSp-1],save[iSp]); break;
|
||||
case ROOT:
|
||||
if (save[iSp-1]<0)
|
||||
{
|
||||
//THROW(new CEvalException("Negative in root"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=sqrt(save[iSp-1]); break;
|
||||
case COS:
|
||||
save[iSp-1]=cos(save[iSp-1]); break;
|
||||
case SIN:
|
||||
save[iSp-1]=sin(save[iSp-1]); break;
|
||||
case SIGN:
|
||||
if (save[iSp-1] == 0.0) save[iSp-1] = 0.0;
|
||||
else if (save[iSp-1] < 0.0) save[iSp-1] = -1.0;
|
||||
else save[iSp-1] = 1.0f;
|
||||
break;
|
||||
case TAN:
|
||||
if (!(t=cos(save[iSp-1])))
|
||||
{
|
||||
//THROW (new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=tan(save[iSp-1]); break;
|
||||
case CSC:
|
||||
if (!(t=sin(save[iSp-1])))
|
||||
{
|
||||
//THROW(new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=1/t; break;
|
||||
case SEC:
|
||||
if (!(t=cos(save[iSp-1])))
|
||||
{
|
||||
//THROW(new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=1/t; break;
|
||||
case COT:
|
||||
if (!(t=sin(save[iSp-1])))
|
||||
{
|
||||
//THROW(new CEvalException("Divide by 0"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=cos(save[iSp-1])/t; break;
|
||||
case LN:
|
||||
if (save[iSp-1]<=0)
|
||||
{
|
||||
//THROW( new CEvalException("Call Log with minus number"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=log(save[iSp-1]); break;
|
||||
case LOG10:
|
||||
if (save[iSp-1]<=0)
|
||||
{
|
||||
//THROW( new CEvalException("Call Log with minus number"));
|
||||
return 0;
|
||||
}
|
||||
save[iSp-1]=log10(save[iSp-1]); break;
|
||||
case LOG:
|
||||
if (save[iSp-1]<=0)
|
||||
{
|
||||
//THROW( new CEvalException("Call Log with minus number"));
|
||||
return 0;
|
||||
}
|
||||
if (save[iSp-2]<=0 || save[iSp-2]==1)
|
||||
{
|
||||
//THROW( new CEvalException("Call Log with minus number"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
save[iSp-2]=log(save[iSp-1])/log(save[iSp-2]);
|
||||
iSp--;
|
||||
break;
|
||||
case ABS: save[iSp-1]=fabs(save[iSp-1]); break;
|
||||
case FLOOR: save[iSp-1]=floor(save[iSp-1]); break;
|
||||
case IRAND:
|
||||
save[iSp-2]=my_irandom(save[iSp-2],save[iSp-1]);
|
||||
iSp--;
|
||||
break;
|
||||
case FRAND:
|
||||
save[iSp-2]=my_frandom(save[iSp-2],save[iSp-1]);
|
||||
iSp--;
|
||||
break;
|
||||
case MINF:
|
||||
save[iSp-2]=(save[iSp-2]<save[iSp-1])?save[iSp-2]:save[iSp-1];
|
||||
iSp--;
|
||||
break;
|
||||
case MAXF:
|
||||
save[iSp-2]=(save[iSp-2]>save[iSp-1])?save[iSp-2]:save[iSp-1];
|
||||
iSp--;
|
||||
break;
|
||||
/*case MOD:
|
||||
save[iSp-2]=fmod(save[iSp-2],save[iSp-1]);
|
||||
iSp--;
|
||||
break;*/
|
||||
default:
|
||||
return 0;
|
||||
//THROW(new CEvalException("Token Error"));
|
||||
}
|
||||
}
|
||||
return save[iSp-1];
|
||||
}
|
||||
|
||||
int CPoly::Analyze(const char * pszStr)
|
||||
{
|
||||
if (pszStr)
|
||||
SetStr(pszStr);
|
||||
|
||||
if (0 == strData.length())
|
||||
return true;
|
||||
|
||||
//DisposeList();
|
||||
ErrorOccur = false;
|
||||
uiLookPos = 0;
|
||||
iLookAhead = lexan();
|
||||
|
||||
expr();
|
||||
|
||||
if (tokenBase.empty())
|
||||
{
|
||||
//THROW(new CParseException("No Data"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return !ErrorOccur;
|
||||
}
|
||||
|
||||
void CPoly::Clear()
|
||||
{
|
||||
int i;
|
||||
//while (!tokenBase.IsEmpty()) listBase.RemoveTail();
|
||||
//while (!numBase.IsEmpty()) numBase.RemoveTail();
|
||||
tokenBase.clear();
|
||||
numBase.clear();
|
||||
|
||||
for (i = 0;i < STSize; ++i)
|
||||
{
|
||||
if (lSymbol[i]) delete lSymbol[i];
|
||||
lSymbol[i]=NULL;
|
||||
}
|
||||
//lSymbol.FreeExtra();
|
||||
lSymbol.clear();
|
||||
SymbolIndex.clear();
|
||||
STSize=0;
|
||||
}
|
||||
|
||||
void CPoly::expr()
|
||||
{
|
||||
int t;
|
||||
|
||||
switch (iLookAhead)
|
||||
{
|
||||
case '+':
|
||||
case '-':
|
||||
uiLookPos--;
|
||||
iLookAhead = NUM;
|
||||
iNumToken = iToken = 0;
|
||||
|
||||
}
|
||||
|
||||
term();
|
||||
|
||||
while (!ErrorOccur)
|
||||
{
|
||||
switch (iLookAhead)
|
||||
{
|
||||
case '+':
|
||||
case '-':
|
||||
t=iLookAhead;
|
||||
match(t);
|
||||
term();
|
||||
emit(t,NONE);
|
||||
continue;
|
||||
case EOS: case ')': case ',': return;
|
||||
default:
|
||||
error();
|
||||
//THROW( new CParseException("Error Parsing"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPoly::error()
|
||||
{
|
||||
iErrorPos=uiLookPos;
|
||||
ErrorOccur=true;
|
||||
}
|
||||
|
||||
int CPoly::lexan()
|
||||
{
|
||||
int t;
|
||||
double tt;
|
||||
|
||||
while (uiLookPos < strData.size())
|
||||
{
|
||||
if (strData[uiLookPos] == ' ' || strData[uiLookPos] == '\t')
|
||||
;
|
||||
else if (isdigit(strData[uiLookPos]))
|
||||
{
|
||||
t = 0;
|
||||
for (;uiLookPos<strData.size();uiLookPos++)
|
||||
{
|
||||
if (isdigit(strData[uiLookPos]))
|
||||
t = t * 10 + strData[uiLookPos] - '0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
iToken=t;
|
||||
tt=0.1;
|
||||
iNumToken=0;
|
||||
if (uiLookPos<strData.size() && strData[uiLookPos]=='.')
|
||||
{
|
||||
uiLookPos++;
|
||||
for (;uiLookPos<strData.size();uiLookPos++,tt*=0.1)
|
||||
{
|
||||
if (isdigit(strData[uiLookPos]))
|
||||
iNumToken+=tt*(strData[uiLookPos]-'0');
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
iNumToken+=iToken;
|
||||
return NUM;
|
||||
}
|
||||
else if (isalpha(strData[uiLookPos]))
|
||||
{
|
||||
string localSymbol("");
|
||||
while (uiLookPos<strData.size() && isalpha(strData[uiLookPos]))
|
||||
{
|
||||
localSymbol+=strData[uiLookPos];
|
||||
uiLookPos++;
|
||||
}
|
||||
iToken= find(localSymbol);
|
||||
if (iToken==-1)
|
||||
{
|
||||
iToken=insert(localSymbol,ID);
|
||||
}
|
||||
return lSymbol[(/*FindIndex*/(iToken))]->token;
|
||||
}
|
||||
else
|
||||
{
|
||||
iToken=0;
|
||||
return strData[uiLookPos++];
|
||||
}
|
||||
uiLookPos++;
|
||||
}
|
||||
return EOS;
|
||||
}
|
||||
|
||||
void CPoly::term()
|
||||
{
|
||||
int t;
|
||||
factor();
|
||||
while (!ErrorOccur)
|
||||
{
|
||||
switch (iLookAhead)
|
||||
{
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
t=iLookAhead;
|
||||
match(t);
|
||||
factor();
|
||||
emit(t,NONE);
|
||||
continue;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPoly::factor()
|
||||
{
|
||||
int t;
|
||||
expo();
|
||||
while (!ErrorOccur)
|
||||
{
|
||||
switch (iLookAhead)
|
||||
{
|
||||
case '^':
|
||||
t=iLookAhead;
|
||||
match(t);
|
||||
expo();
|
||||
emit(t,NONE);
|
||||
continue;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPoly::expo()
|
||||
{
|
||||
int t;
|
||||
switch (iLookAhead)
|
||||
{
|
||||
case '(':
|
||||
match('('); expr(); match(')'); break;
|
||||
case NUM:
|
||||
emit(NUM, iToken); match(NUM); break;
|
||||
case ID:
|
||||
emit(ID,(int)/*FindIndex*/(iToken)); match(ID); break;
|
||||
case ROOT:
|
||||
case SIN:
|
||||
case COT:
|
||||
case TAN:
|
||||
case CSC:
|
||||
case SEC:
|
||||
case LN:
|
||||
case LOG10:
|
||||
case COS:
|
||||
case ABS:
|
||||
case FLOOR:
|
||||
case SIGN:
|
||||
t=iLookAhead;
|
||||
match(iLookAhead); match('('); expr(); match(')'); emit(t,iToken);
|
||||
break;
|
||||
|
||||
case LOG:
|
||||
case MINF:
|
||||
case MAXF:
|
||||
case IRAND:
|
||||
case FRAND:
|
||||
case MOD:
|
||||
t=iLookAhead;
|
||||
match(iLookAhead); match('('); expr(); match(','); expr(); match(')'); emit(t,iToken);
|
||||
break;
|
||||
case EOS:
|
||||
break;
|
||||
default:
|
||||
error();
|
||||
//THROW( new CParseException("Error Parsing"));
|
||||
}
|
||||
}
|
||||
|
||||
void CPoly::match(int t)
|
||||
{
|
||||
if (iLookAhead==t) iLookAhead=lexan(); else error();
|
||||
}
|
||||
|
||||
void CPoly::emit(int t, int tval)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case '+':
|
||||
tokenBase.push_back(PLU);
|
||||
break;
|
||||
case '-':
|
||||
tokenBase.push_back(MIN);
|
||||
break;
|
||||
case '*':
|
||||
tokenBase.push_back(MUL);
|
||||
break;
|
||||
case '/':
|
||||
tokenBase.push_back(DIV);
|
||||
break;
|
||||
case '%':
|
||||
tokenBase.push_back(MOD);
|
||||
break;
|
||||
case '^':
|
||||
tokenBase.push_back(POW);
|
||||
break;
|
||||
case ROOT:
|
||||
case SIN:
|
||||
case TAN:
|
||||
case COT:
|
||||
case COS:
|
||||
case CSC:
|
||||
case SEC:
|
||||
case LOG:
|
||||
case LN:
|
||||
case LOG10:
|
||||
case ABS:
|
||||
case MINF:
|
||||
case MAXF:
|
||||
case IRAND:
|
||||
case FRAND:
|
||||
case MOD:
|
||||
case FLOOR:
|
||||
case SIGN:
|
||||
tokenBase.push_back(t);
|
||||
break;
|
||||
case NUM:
|
||||
tokenBase.push_back(t);
|
||||
numBase.push_back(iNumToken);
|
||||
break;
|
||||
case ID:
|
||||
tokenBase.push_back(t);
|
||||
tokenBase.push_back(tval); break;
|
||||
default:
|
||||
error();
|
||||
Clear();
|
||||
//THROW( new CParseException("Error Parsing"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int CPoly::find(const string & s)
|
||||
{
|
||||
int l, m, r;
|
||||
|
||||
l = 0;
|
||||
r = STSize - 1;
|
||||
|
||||
while (l <= r)
|
||||
{
|
||||
m = (l + r) >> 1;
|
||||
|
||||
if (lSymbol[SymbolIndex[m]]->strlex == s)
|
||||
return SymbolIndex[m];
|
||||
else if (lSymbol[SymbolIndex[m]]->strlex < s)
|
||||
l = m + 1;
|
||||
else
|
||||
r = m - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CPoly::insert(const string & s, int tok)
|
||||
{
|
||||
int i;
|
||||
bool bAdded=false;
|
||||
//s.MakeLower();
|
||||
//transform(s.begin(),s.end(),s.begin(),std::tolower);
|
||||
//lSymbol.SetAtGrow(STSize,new CSymTable(tok,s));
|
||||
lSymbol.push_back(new CSymTable(tok,s));
|
||||
for (i=0;i<STSize;i++)
|
||||
{
|
||||
if (s<lSymbol[SymbolIndex[i]]->strlex)
|
||||
{
|
||||
SymbolIndex.insert(SymbolIndex.begin()+i,STSize);
|
||||
bAdded=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bAdded)
|
||||
{
|
||||
//SymbolIndex.SetAtGrow(STSize,STSize);
|
||||
SymbolIndex.push_back(STSize);
|
||||
}
|
||||
STSize++;
|
||||
return STSize-1;
|
||||
}
|
||||
|
||||
int CPoly::SetVar(const string & strName, double dVar)
|
||||
{
|
||||
//transform(strName.begin(),strName.end(),s.begin(),std::tolower);
|
||||
if (ErrorOccur) return false;
|
||||
int index = find(strName);
|
||||
if (index == -1) return false;
|
||||
CSymTable * stVar = lSymbol[(/*FindIndex*/(index))];
|
||||
stVar->dVal = dVar;
|
||||
return true;
|
||||
}
|
||||
|
||||
double CPoly::GetVar(const std::string & strName)
|
||||
{
|
||||
if (ErrorOccur) return false;
|
||||
int index = find(strName);
|
||||
if (index == -1) return false;
|
||||
CSymTable * stVar = lSymbol[(/*FindIndex*/(index))];
|
||||
if(!stVar)
|
||||
return -1;
|
||||
return stVar->dVal;
|
||||
}
|
||||
|
||||
void CPoly::init()
|
||||
{
|
||||
insert("min",MINF);
|
||||
insert("max",MAXF);
|
||||
insert("number", IRAND);
|
||||
insert("irandom", IRAND);
|
||||
insert("irand", IRAND);
|
||||
insert("frandom",FRAND);
|
||||
insert("frand",FRAND);
|
||||
insert("rt",ROOT);
|
||||
insert("sqrt",ROOT);
|
||||
insert("cos",COS);
|
||||
insert("sin",SIN);
|
||||
insert("tan",TAN);
|
||||
insert("cot",COT);
|
||||
insert("csc",CSC);
|
||||
insert("cosec",COSEC);
|
||||
insert("sec",SEC);
|
||||
insert("pi",PI);
|
||||
SetVar("pi",3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068);
|
||||
insert("e",EXP);
|
||||
SetVar("e",2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427);
|
||||
insert("log",LOG);
|
||||
insert("ln",LN);
|
||||
insert("log10",LOG10);
|
||||
insert("abs",ABS);
|
||||
insert("mod",MOD);
|
||||
insert("floor", FLOOR);
|
||||
insert("sign",SIGN);
|
||||
}
|
||||
|
||||
/*
|
||||
void CPoly::AddSymTable(CPtrList* ns)
|
||||
{
|
||||
int i, len = ns->GetCount();
|
||||
CSymTable* a, *b;
|
||||
int index;
|
||||
POSITION pos;
|
||||
pos = ns->GetHeadPosition();
|
||||
for (i=0;i<len;i++)
|
||||
{
|
||||
a = ((CSymTable*)ns->GetNext(pos));
|
||||
if ((index=find(a->strlex))==-1)
|
||||
{
|
||||
lSymbol[insert(a->strlex,a->token)]->dVal = a->dVal;
|
||||
//lSymbol.SetAtGrow(STSize,b);
|
||||
//STSize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
(lSymbol.GetAt(FindIndex(index)))->dVal = a->dVal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void CPoly::Diff(CString& str)
|
||||
{
|
||||
int stNow, cc;
|
||||
int i;
|
||||
CString* mstr,*bstr;
|
||||
if (ErrorOccur) //THROW(new CEvalException("Diff Error"));
|
||||
return;
|
||||
mstr = new CString[tokenBase.GetCount()];
|
||||
bstr = new CString[tokenBase.GetCount()];
|
||||
POSITION pos = tokenBase.GetHeadPosition();
|
||||
POSITION posn = numBase.GetHeadPosition();
|
||||
cc=0;
|
||||
while (pos != NULL)
|
||||
{
|
||||
|
||||
stNow=tokenBase.GetNext(pos);
|
||||
switch (stNow)
|
||||
{
|
||||
case NUM:
|
||||
//save[iSp++]=numBase.GetNext(posn);
|
||||
mstr[cc]="0";bstr[cc].Format("%f",numBase.GetNext(posn));
|
||||
for (i=bstr[cc].GetLength()-1;i>=0;i--)
|
||||
if (bstr[cc][i] != '0')
|
||||
break;
|
||||
if (i>0)
|
||||
bstr[cc]=bstr[cc].Left(i+1);
|
||||
i=bstr[cc].GetLength()-1;
|
||||
if (bstr[cc][i]=='.')
|
||||
{
|
||||
bstr[cc]=bstr[cc].Left(i);
|
||||
}
|
||||
cc++; break;
|
||||
|
||||
case ID:
|
||||
////save[iSp++]=
|
||||
//lSymbol.GetAt(
|
||||
//lSymbol.FindIndex(
|
||||
//(POSITION )tokenBase.GetNext(pos)
|
||||
// )
|
||||
//)->dVal;
|
||||
bstr[cc] = lSymbol.GetAt(tokenBase.GetNext(pos))->strlex;
|
||||
if (bstr[cc] != "x") mstr[cc]="0";
|
||||
else mstr[cc] = "1";
|
||||
cc++;
|
||||
break;
|
||||
case '+':
|
||||
cc--;
|
||||
if (bstr[cc-1]=="0")
|
||||
{
|
||||
if (bstr[cc]=="0")
|
||||
bstr[cc-1]="0";
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc]+")";
|
||||
}
|
||||
else if (bstr[cc]=="0")
|
||||
{
|
||||
bstr[cc-1]="("+bstr[cc-1]+")";
|
||||
}
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc-1]+"+"+bstr[cc]+")";
|
||||
bstr[cc]="";
|
||||
|
||||
if (mstr[cc-1]=="0")
|
||||
{
|
||||
if (mstr[cc]=="0")
|
||||
mstr[cc-1]="0";
|
||||
else
|
||||
mstr[cc-1]="("+mstr[cc]+")";
|
||||
}
|
||||
else if (mstr[cc]=="0")
|
||||
{
|
||||
mstr[cc-1]="("+mstr[cc-1]+")";
|
||||
}
|
||||
else
|
||||
mstr[cc-1]="("+mstr[cc-1]+"+"+mstr[cc]+")";
|
||||
mstr[cc]="";
|
||||
|
||||
break;
|
||||
case '-':
|
||||
cc--;
|
||||
if (bstr[cc-1]=="0")
|
||||
{
|
||||
if (bstr[cc]=="0")
|
||||
bstr[cc-1]="0";
|
||||
else
|
||||
bstr[cc-1]="(-"+bstr[cc]+")";
|
||||
}
|
||||
else if (bstr[cc]=="0")
|
||||
{
|
||||
bstr[cc-1]="("+bstr[cc-1]+")";
|
||||
}
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc-1]+"-"+bstr[cc]+")";
|
||||
bstr[cc]="";
|
||||
|
||||
if (mstr[cc-1]=="0")
|
||||
{
|
||||
if (mstr[cc]=="0")
|
||||
mstr[cc-1]="0";
|
||||
else
|
||||
mstr[cc-1]="(-"+mstr[cc]+")";
|
||||
}
|
||||
else if (mstr[cc]=="0")
|
||||
{
|
||||
mstr[cc-1]="("+mstr[cc-1]+")";
|
||||
}
|
||||
else
|
||||
mstr[cc-1]="("+mstr[cc-1]+"-"+mstr[cc]+")";
|
||||
mstr[cc]="";
|
||||
|
||||
break;
|
||||
case '*':
|
||||
cc--;
|
||||
if (mstr[cc-1]=="0" || bstr[cc]=="0")
|
||||
{
|
||||
if (mstr[cc]=="0" || bstr[cc-1]=="0")
|
||||
{
|
||||
mstr[cc-1]="0";
|
||||
}
|
||||
else
|
||||
{
|
||||
mstr[cc-1]="("+ mstr[cc] + "*" +bstr[cc-1] +")";
|
||||
}
|
||||
}
|
||||
else if (mstr[cc]=="0" || bstr[cc-1]=="0")
|
||||
{
|
||||
mstr[cc-1] = "("+mstr[cc-1] + "*" + bstr[cc] + ")";
|
||||
}
|
||||
else
|
||||
mstr[cc-1] = "(("+mstr[cc-1] + "*" + bstr[cc] + ")+(" +mstr[cc] + "*" +bstr[cc-1] +"))";
|
||||
|
||||
if (bstr[cc-1]=="0" || bstr[cc]=="0")
|
||||
{
|
||||
bstr[cc-1]="0";
|
||||
}
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc-1]+"*"+bstr[cc]+")";
|
||||
mstr[cc]=""; bstr[cc]="";
|
||||
break;
|
||||
case '/':
|
||||
cc--;
|
||||
if (bstr[cc]=="0") THROW(new CEvalException("Divide by Zero"));
|
||||
if (mstr[cc-1]=="0"||bstr[cc]=="0")
|
||||
{
|
||||
if (mstr[cc]=="0" || bstr[cc-1]=="0")
|
||||
{
|
||||
mstr[cc-1]="0";
|
||||
}
|
||||
else
|
||||
mstr[cc-1]="((-" +mstr[cc]+"*"+bstr[cc-1]+ ")/("+bstr[cc]+")^2)";
|
||||
}
|
||||
else if (mstr[cc]=="0"||bstr[cc-1]=="0")
|
||||
{
|
||||
mstr[cc-1]="((" +mstr[cc-1]+"*"+bstr[cc] + ")/("+bstr[cc]+")^2)";
|
||||
}
|
||||
else
|
||||
mstr[cc-1]="((" +mstr[cc-1]+"*"+bstr[cc]+ "-" +mstr[cc]+"*"+bstr[cc-1]+ ")/("+bstr[cc]+")^2)";
|
||||
if (bstr[cc-1]=="0")
|
||||
bstr[cc-1]="0";
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc-1]+")/("+bstr[cc]+")";
|
||||
break;
|
||||
case '^':
|
||||
cc--;
|
||||
if (mstr[cc-1]=="0")
|
||||
{
|
||||
if (mstr[cc]=="0")
|
||||
{
|
||||
mstr[cc-1]="0";
|
||||
mstr[cc]="";
|
||||
}
|
||||
else
|
||||
{
|
||||
mstr[cc-1]="ln("+bstr[cc-1]+")*("+bstr[cc-1]+")^("+bstr[cc]+")*("+mstr[cc]+")";
|
||||
mstr[cc]="";
|
||||
}
|
||||
}
|
||||
else if (mstr[cc]=="0")
|
||||
{
|
||||
mstr[cc-1]="("+bstr[cc]+")*("+bstr[cc-1]+")^("+bstr[cc]+"-1)*("+mstr[cc-1]+")";
|
||||
mstr[cc]="";
|
||||
}
|
||||
else
|
||||
{
|
||||
mstr[cc-1]="(ln("+bstr[cc-1]+")*("+bstr[cc-1]+")^("+bstr[cc]+")*("+mstr[cc]+")+("+bstr[cc]+")*("+bstr[cc-1]+")^("+bstr[cc]+"-1)*("+mstr[cc-1]+"))";
|
||||
mstr[cc]="";
|
||||
|
||||
}
|
||||
|
||||
if (bstr[cc-1]=="0")
|
||||
{
|
||||
bstr[cc-1]="0";
|
||||
}
|
||||
else if (bstr[cc-1]=="1")
|
||||
{
|
||||
bstr[cc-1]="1";
|
||||
}
|
||||
else if (bstr[cc]=="1")
|
||||
{
|
||||
|
||||
}
|
||||
else if (bstr[cc]=="0")
|
||||
{
|
||||
bstr[cc-1]="0";
|
||||
}
|
||||
else
|
||||
bstr[cc-1]="("+bstr[cc-1]+")^("+bstr[cc]+")";
|
||||
|
||||
bstr[cc]="";
|
||||
break;
|
||||
case ROOT:
|
||||
cc--;
|
||||
if (mstr[cc]=="0")
|
||||
mstr[cc]="0";
|
||||
else
|
||||
mstr[cc]="("+mstr[cc]+"/2/rt("+bstr[cc]+"))";
|
||||
bstr[cc]="rt("+bstr[cc] +")";
|
||||
cc++;
|
||||
break;
|
||||
case COS:
|
||||
cc--;
|
||||
mstr[cc]="(-"+mstr[cc]+"*sin("+bstr[cc]+"))";
|
||||
bstr[cc]="cos("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case SIN:
|
||||
cc--;
|
||||
mstr[cc]="("+mstr[cc]+"*cos("+bstr[cc]+"))";
|
||||
bstr[cc]="sin("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case TAN:
|
||||
cc--;
|
||||
mstr[cc]="(sec("+bstr[cc]+")^2*"+mstr[cc]+")";
|
||||
bstr[cc]="tan("+bstr[cc]+")";
|
||||
|
||||
cc++;
|
||||
break;
|
||||
case CSC:
|
||||
cc--;
|
||||
mstr[cc]="(-csc("+bstr[cc]+")*cot("+bstr[cc]+")*"+mstr[cc]+")";
|
||||
bstr[cc]="csc("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case SEC:
|
||||
cc--;
|
||||
mstr[cc]="(sec("+bstr[cc]+")*tan("+bstr[cc]+")*"+mstr[cc]+")";
|
||||
bstr[cc]="sec("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case COT:
|
||||
cc--;
|
||||
mstr[cc]="(-csc("+bstr[cc]+")^2*"+mstr[cc]+")";
|
||||
bstr[cc]="cot("+bstr[cc]+")";
|
||||
|
||||
cc++;
|
||||
case LN:
|
||||
cc--;
|
||||
mstr[cc]="("+mstr[cc]+"/"+bstr[cc]+")";
|
||||
bstr[cc]="ln("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case LOG10:
|
||||
cc--;
|
||||
mstr[cc]="("+mstr[cc]+"/"+bstr[cc]+"/ln(10))";
|
||||
bstr[cc]="log10("+bstr[cc]+")";
|
||||
cc++;
|
||||
break;
|
||||
case LOG:
|
||||
cc--;
|
||||
mstr[cc-1]="("+mstr[cc]+"/"+bstr[cc]+"/ln("+bstr[cc-1]+")-ln("+bstr[cc]+")*"+mstr[cc-1]+"/ln("+bstr[cc-1]+")^2/"+bstr[cc-1]+")";
|
||||
bstr[cc-1]="log("+bstr[cc-1]+","+bstr[cc]+")";
|
||||
mstr[cc]="";
|
||||
bstr[cc]="";
|
||||
|
||||
break;
|
||||
default:
|
||||
//THROW(new CEvalException("Out of Case"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
str=mstr[cc-1];
|
||||
delete[] mstr;
|
||||
delete[] bstr;
|
||||
}*/
|
||||
|
||||
/*int CPoly::FindIndex(int tval)
|
||||
{
|
||||
return tval;
|
||||
}
|
||||
*/
|
||||
Executable
+56
@@ -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
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#include "SymTable.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
CSymTable::CSymTable(int aTok, string aStr) : dVal(0), token(aTok), strlex(aStr)
|
||||
{
|
||||
}
|
||||
|
||||
CSymTable::~CSymTable()
|
||||
{
|
||||
}
|
||||
|
||||
Executable
+17
@@ -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
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#include "Symbol.h"
|
||||
|
||||
CSymbol::CSymbol()
|
||||
{
|
||||
id = MID_SYMBOL;
|
||||
iType = ST_UNKNOWN;
|
||||
}
|
||||
|
||||
CSymbol::~CSymbol()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSymbol::Equal(CSymbol dif)
|
||||
{
|
||||
if (dif.iType/10 == iType/10)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSymbol::Less(CSymbol dif)
|
||||
{
|
||||
if (dif.iType/10 > iType/10) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int CSymbol::GetType()
|
||||
{
|
||||
return iType;
|
||||
}
|
||||
|
||||
void CSymbol::SetType(int Type)
|
||||
{
|
||||
iType=Type;
|
||||
}
|
||||
|
||||
int CSymbol::issymbol(int ch)
|
||||
{
|
||||
switch(ch)
|
||||
{
|
||||
case SY_PLUS : return ST_PLUS;
|
||||
case SY_MINUS : return ST_MINUS;
|
||||
case SY_MULTIPLY: return ST_MULTIPLY;
|
||||
case SY_DIVIDE : return SY_DIVIDE;
|
||||
case SY_CARET : return SY_CARET;
|
||||
case SY_OPEN : return SY_OPEN;
|
||||
case SY_CLOSE : return ST_CLOSE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+39
@@ -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
|
||||
Executable
+208
@@ -0,0 +1,208 @@
|
||||
<?xml version="1.0" encoding="ks_c_5601-1987"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="libpoly"
|
||||
ProjectGUID="{BD8E86DD-07BA-49B0-BF04-3282DA8377EB}"
|
||||
RootNamespace="libpoly"
|
||||
SccProjectName="SAK"
|
||||
SccAuxPath="SAK"
|
||||
SccLocalPath="SAK"
|
||||
SccProvider="SAK"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(ProjectDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(ProjectDir)../../Extern/include;"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__WIN32__;_USE_32BIT_TIME_T"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_d.lib"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ProjectDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="../external"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__WIN32__"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Base.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\main.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Poly.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Symbol.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\SymTable.cc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Base.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Constants.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Poly.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Symbol.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\SymTable.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#ifdef __WIN32__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "Poly.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
printf( "12345\n" );
|
||||
|
||||
#ifndef __WIN32__
|
||||
srandom(time(0) + getpid());
|
||||
#else
|
||||
srand(time(0) + GetCurrentProcessId());
|
||||
#endif
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
cout << "argc != 3" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CPoly p;
|
||||
p.SetStr(argv[1]); // "min(5,max(-5,(x-y+10)))+min(5,max(-5,(x-y+10)))"
|
||||
|
||||
if (!p.Analyze())
|
||||
{
|
||||
cout << "Analyze failed" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("B = %d\n", atoi(argv[2]));
|
||||
|
||||
p.SetVar("b", atoi(argv[2]));
|
||||
p.SetVar("k", 20);
|
||||
|
||||
cout << (int) p.Eval() << endl;
|
||||
cout << p.Eval() << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user