// Example program
#include < iostream >
#include < complex >
#include < string >
#include < list >
#include < vector >
#include < sstream >
using namespace std;
#include < iostream >
#include < complex >
#include < string >
#include < list >
#include < vector >
#include < sstream >
using namespace std;
class var
{
public:
union _DATA
{
int i;
bool b;
double d;
char c;
void* pData; // string*.
// complex*,
// vector < var* > *
// list < var* > *
{
public:
union _DATA
{
int i;
bool b;
double d;
char c;
void* pData; // string*.
// complex*,
// vector < var* > *
// list < var* > *
//void* vector < var* > *pVectorData;
//void* list < var* > *pListData;
};
enum _DATA_TYPE
{
TYPE_NULL = 0,
//void* list < var* > *pListData;
};
enum _DATA_TYPE
{
TYPE_NULL = 0,
TYPE_INT = 1,
TYPE_DOUBLE,
TYPE_CHAR,
TYPE_STRING,
TYPE_COMPLEX,
TYPE_DOUBLE,
TYPE_CHAR,
TYPE_STRING,
TYPE_COMPLEX,
TYPE_VECTOR_DATA = 11,
TYPE_LIST_DATA = 12,
TYPE_LIST_DATA = 12,
TYPE_FOLLOW_RIGHT = 21, //主要用于运算,表示结果取决于右操作数
TYPE_FOLLOW_LEFT = 22, //主要用于运算,表示结果取决于左操作数
TYPE_FOLLOW_LEFT = 22, //主要用于运算,表示结果取决于左操作数
TYPE_ANY = 31, // 表示任意数据类型,为了简化运算表的!
TYPE_EXCEPTION = 32, //无法计算,抛出异常!!!
};
enum _OPERATOR
{
OPERATOR_ADD = 0,
OPERATOR_SUB = 1,
OPERATOR_MUL = 2,
OPERATOR_DIV = 3,
TYPE_EXCEPTION = 32, //无法计算,抛出异常!!!
};
enum _OPERATOR
{
OPERATOR_ADD = 0,
OPERATOR_SUB = 1,
OPERATOR_MUL = 2,
OPERATOR_DIV = 3,
OPERATOR_POW = 11,
OPERATOR_ADD_PRE = 12,
OPERATOR_ADD_AFTER = 13,
};
public:
var() :_type(TYPE_NULL)
{
}
~var()
{
clear();
//cout ## endl##"------- delete object ----------" ## endl;
}
public:
public:
var() :_type(TYPE_NULL)
{
}
~var()
{
clear();
//cout ## endl##"------- delete object ----------" ## endl;
}
public:
var(const int i1)
{
_data.i = i1;
_type = TYPE_INT;
}
var(const double d1)
{
_data.d = d1;
_type = TYPE_DOUBLE;
}
var(const complex < double > & c1)
{
_data.pData = new complex < double > (c1);
_type = TYPE_COMPLEX;
}
var(const string& s)
{
_data.pData = new string(s);
_type = TYPE_STRING;
}
var(const char* s1)
{
_data.pData = new string(s1);
_type = TYPE_STRING;
}
var(const var& v1)
{
_type = v1._type;
{
_data.i = i1;
_type = TYPE_INT;
}
var(const double d1)
{
_data.d = d1;
_type = TYPE_DOUBLE;
}
var(const complex < double > & c1)
{
_data.pData = new complex < double > (c1);
_type = TYPE_COMPLEX;
}
var(const string& s)
{
_data.pData = new string(s);
_type = TYPE_STRING;
}
var(const char* s1)
{
_data.pData = new string(s1);
_type = TYPE_STRING;
}
var(const var& v1)
{
_type = v1._type;
switch (v1._type)
{
case TYPE_NULL:
return;
case TYPE_INT:
_data.i = v1._data.i;
return;
case TYPE_DOUBLE:
_data.d = v1._data.d;
return;
case TYPE_STRING:
_data.pData = new string(*(std::string*)v1._data.pData);
return;
{
case TYPE_NULL:
return;
case TYPE_INT:
_data.i = v1._data.i;
return;
case TYPE_DOUBLE:
_data.d = v1._data.d;
return;
case TYPE_STRING:
_data.pData = new string(*(std::string*)v1._data.pData);
return;
case TYPE_COMPLEX: //
_data.pData = new complex < double > (*(complex < double > *)v1._data.pData);
return;
break;
_data.pData = new complex < double > (*(complex < double > *)v1._data.pData);
return;
break;
case TYPE_VECTOR_DATA:
{
_data.pData = new vector < var* > ();
vector < var* > * pv = (vector < var* > *)_data.pData;
for (auto& dat : *(vector < var* > *)v1._data.pData)
{
var* pvar = new var(*dat);
pv- > push_back(pvar);
}
return;
}
break;
{
_data.pData = new vector < var* > ();
vector < var* > * pv = (vector < var* > *)_data.pData;
for (auto& dat : *(vector < var* > *)v1._data.pData)
{
var* pvar = new var(*dat);
pv- > push_back(pvar);
}
return;
}
break;
case TYPE_LIST_DATA:
{
_data.pData = new list < var* > ();
list < var* > * pl = (list < var* > *)_data.pData;
for (auto& dat : *(list < var* > *)v1._data.pData)