有限状态机

  1 #pragma once
  2 #include "..\..\dscript\table.h"
  3 #include "..\..\dscript\table\D_resEditListCtrl.h"
  4 #include "..\PropertyGridEx\DrawLotsDlg.h"
  5 #include "..\dbase_header.h"
  6 #include <afx.h>
  7 #include "..\..\dscript\dscript_enum_header.h"
  8 #include "..\..\dscript\gNewPbCalcRule\countDeal.h"
  9 
 10 using namespace std;
 11 class Cfyq_expression;
 12 class Cfyq_Name;
 13 class Cfyq_node;
 14 class Cfyq_Var;
 15 class Cfyq_scope;
 16 class Cfyq_const;
 17 class Cfyq_offset;
 18 class Cfyq_jzj;
 19 class Cfyq_opt;
 20 class Cfyq_set;
 21 typedef std::vector<Cfyq_node*>    vec_fyq_Node;
 22 typedef std::vector<Cfyq_Var*>    vec_fyq_Var;
 23 typedef std::vector<Cfyq_const*>    vec_fyq_Const;
 24 typedef std::vector<Cfyq_scope*>    vec_fyq_Scope;
 25 typedef std::vector<Cfyq_opt*>    vec_fyq_opt;
 26 typedef std::vector<Cfyq_set*>    vec_fyq_set;
 27 enum CFyq_NodeKind{FNK_Name, FNK_Param, FNK_Scope, FNK_Const, FNK_Value, FNK_Set, FNK_Define, FNK_Offset,FNK_Node,FNK_Jzj};
 28 
 29 class   Cfyq_Interpreter : public CTableRow
 30 {
 31 
 32 public:
 33     Cfyq_Interpreter();
 34     ~Cfyq_Interpreter();
 35 public:
 36     bool Interpreter(const CString& strFormula);
 37     void backInterpreter(Cfyq_node* startName,CString& backstr);
 38     void pushback(Cfyq_node* startName, CString& backstr);
 39     bool push( char input );
 40     void ChangeNode(Cfyq_node* pState);
 41     void ChangeBackNode(Cfyq_node* pstate);
 42 
 43     bool NextStrIs(const CString& str);
 44     bool NextStrIsIgnoreSpace(const CString& str);
 45     bool LastStrIsIgnoreSpace(const CString& str);
 46     static bool IsTrueChar(char c);
 47     static bool IsChineseChar(char c);
 48     virtual bool toString(CString& txt);
 49     bool CheckName(  CString& title );
 50     bool CheckParam( CString& title );
 51     bool CheckConst( CString& title );
 52 public:
 53     Cfyq_node* GetCurNode(){ return m_pCurNode; }
 54     Cfyq_Name* GetCurName(){ return m_pCurName; }
 55     Cfyq_node* GetCurBackNode();
 56     Cfyq_node* CreateNode(CFyq_NodeKind kind);
 57     vec_fyq_Node& GetvecExpression(){ return m_vecExpression; }
 58 public:
 59     //检查集合
 60     vecSysCodeKindDataInfo m_param_obj;
 61     vecSysCodeKindDataInfo m_name_obj;
 62     vecSysCodeKindDataInfo m_const_obj;
 63 private:
 64     CString m_strFormula;//公式
 65     UINT m_nCurIndex;//当前索引
 66     Cfyq_node* m_pCurNode;//当前状态
 67     Cfyq_Name* m_pCurName;//当前name
 68     Cfyq_node* m_pCurBackNode;//反解析当前状态
 69     vec_fyq_Node m_vecExpression;//State存放集合
 70 };
 71 //节点
 72 class  Cfyq_node : public CTableRow
 73 {
 74     DECLARE_SERIAL_EXTDLL( Cfyq_node )
 75 public:
 76     Cfyq_node();
 77     virtual ~Cfyq_node();
 78 public:
 79     virtual int Accept( Cfyq_Interpreter* pInterpreter, char input );
 80     virtual bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
 81     virtual void NextBackNode(Cfyq_node* startName,CString& str, Cfyq_Interpreter* pInterpreter,bool bLast);
 82     virtual CFyq_NodeKind GetNodeGrade();
 83     virtual void ErrorMsg(CString& str);
 84     void Serialize(CArchive& ar);
 85 public:
 86     CString& GetContent();
 87 public:
 88     vec_fyq_Node m_vecSubNode;
 89     double m_dValue;
 90     CString m_sValue;
 91     CString m_strContent;
 92     bool m_bStateInputChar;
 93 protected:
 94     Cfyq_Interpreter* m_pInterpreter;
 95 };
 96 
 97 //元素
 98 class  Cfyq_element : public Cfyq_node
 99 {
100     DECLARE_SERIAL_EXTDLL( Cfyq_element )
101 public:
102     Cfyq_element();
103     ~Cfyq_element(){};
104 public:
105     bool IsClose();;
106     void SetClose(bool val);
107     int AppendChar( Cfyq_Interpreter* pInterpreter, char input );
108     void Serialize(CArchive& ar);
109 private:
110     bool m_bIsCloseFlag;
111 };
112 
113 //常量
114 class  Cfyq_const : public Cfyq_element
115 {
116     DECLARE_SERIAL_EXTDLL( Cfyq_const )
117 public:
118     Cfyq_const(){}
119     ~Cfyq_const(){}
120 public:
121     int Accept( Cfyq_Interpreter* pInterpreter, char input );
122     bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
123     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
124     virtual CFyq_NodeKind GetNodeGrade() {return FNK_Const;}
125     virtual void ErrorMsg(CString& str);
126     void Serialize(CArchive& ar);
127 };
128 
129 //用户变量 {kjb:正偏离扣减}
130 class  Cfyq_Var : public Cfyq_element
131 {
132     DECLARE_SERIAL_EXTDLL( Cfyq_Var )
133 public:
134     CString m_sEngName;//英文名
135     bool m_bInited;//是否被赋值
136     CString m_sExplain;//中文解释
137     CString m_dValueToStr; //数字字符串
138     int m_nLifePeriod;//生命周期 0是测试阶段 1是代理阶段
139 public:
140     Cfyq_Var();
141     ~Cfyq_Var(){};
142     void SetEngName(CString name);
143     void SetExplain(CString Explain);
144     int Accept( Cfyq_Interpreter* pInterpreter, char input );
145     bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
146 
147     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
148 
149     virtual CFyq_NodeKind GetNodeGrade() {return FNK_Value;}
150 
151     virtual void ErrorMsg(CString& str);
152 
153     void Serialize(CArchive& ar);
154 };
155 
156 //:取值范围
157 class  Cfyq_scope : public Cfyq_element
158 {
159     DECLARE_SERIAL_EXTDLL( Cfyq_scope )
160 public:
161     Cfyq_scope();
162     ~Cfyq_scope();
163 protected:
164     int m_bFlag;//0:- 范围用法;1:,去除用法
165     int  m_MinMax[105][4]; //最大可支持105个范围区间
166     int m_nrow;
167 public:
168 
169     int GetMinCount(int index);
170     int GetMaxCount(int index);
171     int GetMin(int index);
172     int GetMax(int index);
173 
174     void SetRow(int row);
175     int GetRow();
176     bool SetScope();
177     bool ReplaceScope(CString strTemp);
178     bool SetScopeToName(Cfyq_Interpreter* pInterpreter);
179     int GetFlag();
180     void Serialize(CArchive& ar);
181     virtual void ErrorMsg(CString& str);
182 public:
183     int Accept( Cfyq_Interpreter* pInterpreter, char input );
184     bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
185     virtual CFyq_NodeKind GetNodeGrade();
186 };
187 
188 
189 class  Cfyq_Name : public Cfyq_element
190 {
191     DECLARE_SERIAL_EXTDLL( Cfyq_Name )
192 public:
193     Cfyq_Name();
194     ~Cfyq_Name();
195 protected:
196     CString        m_sParam;
197     Cfyq_scope*    m_pScope;
198     Cfyq_jzj*   m_pjzj;
199 public:
200     virtual int Accept( Cfyq_Interpreter* pInterpreter, char input );
201     virtual bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
202     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
203 
204     CString GetParam();
205     void SetParam(CString val);
206     Cfyq_scope* GetScope();
207     void SetScope(Cfyq_scope* val);
208     Cfyq_jzj* Getjzj() const;
209     void Setjzj(Cfyq_jzj* jzj);
210 
211     virtual void ErrorMsg(CString& str);
212 
213     virtual CFyq_NodeKind GetNodeGrade();
214 
215     void Serialize(CArchive& ar);
216 public:
217     int m_bcanSerial;
218     int m_bcanSerialjzj;
219 };
220 
221 class  Cfyq_jzj : public Cfyq_element
222 {
223     DECLARE_SERIAL_DSCRIPT( Cfyq_jzj )
224 public:
225     Cfyq_jzj();
226     ~Cfyq_jzj();
227     int Accept(Cfyq_Interpreter* pInterpreter, char input);
228     bool NextNode(Cfyq_Interpreter* pInterpreter, char  input);
229     virtual CFyq_NodeKind GetNodeGrade();
230     void Serialize(CArchive& ar);
231     bool SetjzjToName(Cfyq_Interpreter* pInterpreter);
232 public:
233     long m_nkind;
234 };
235 
236 //参数
237 class  Cfyq_Param: public Cfyq_element
238 {
239     DECLARE_SERIAL_EXTDLL( Cfyq_Param )
240 public:
241     Cfyq_Param();
242     ~Cfyq_Param(){}
243 public:
244     bool SetParamToName(Cfyq_Interpreter* pInterpreter);
245     virtual int Accept( Cfyq_Interpreter* pInterpreter, char input );
246     virtual bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
247     virtual CFyq_NodeKind GetNodeGrade();
248     virtual void ErrorMsg(CString& str);
249     void Serialize(CArchive& ar);
250 };
251 
252 //操作符
253 class  Cfyq_opt: public Cfyq_node
254 {
255     DECLARE_SERIAL_EXTDLL( Cfyq_opt )
256 public:
257     Cfyq_opt();
258     ~Cfyq_opt();
259 protected:
260     vec_fyq_Node m_nodes; 
261 public:
262     void Serialize(CArchive& ar);
263 };
264 
265 
266 //:定义
267 class  Cfyq_define: public Cfyq_opt
268 {
269     DECLARE_SERIAL_EXTDLL( Cfyq_define )
270 public:
271     Cfyq_define();
272     ~Cfyq_define(){}
273 public:
274     virtual int Accept( Cfyq_Interpreter* pInterpreter, char input );
275     virtual bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
276     virtual CFyq_NodeKind GetNodeGrade();
277     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
278     void Serialize(CArchive& ar);
279 };
280 
281 //=赋值
282 class  Cfyq_set: public Cfyq_opt
283 {
284     DECLARE_SERIAL_EXTDLL( Cfyq_set )
285 public:
286     Cfyq_set();
287     ~Cfyq_set();
288     virtual int Accept( Cfyq_Interpreter* pInterpreter, char input );
289     virtual bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
290     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
291     virtual CFyq_NodeKind GetNodeGrade();
292     void Serialize(CArchive& ar);
293 };
294 
295 
296 //=偏差计算: 左侧为引入的系统变量,右侧为固定的用户参数分别 偏离范围,正偏离扣分,右偏离扣分
297 class  Cfyq_offset: public Cfyq_opt
298 {
299     DECLARE_SERIAL_EXTDLL( Cfyq_offset )
300 public:
301     Cfyq_offset();
302     ~Cfyq_offset(){}
303     Cfyq_Name* m_pName;
304     int m_bcanSerial;
305 public:
306     int Accept( Cfyq_Interpreter* pInterpreter, char input );
307     bool NextNode( Cfyq_Interpreter* pInterpreter, char  input );
308     virtual CFyq_NodeKind GetNodeGrade() {return FNK_Offset;}
309     void Serialize(CArchive& ar);
310     void NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast);
311     void SetFyqName(Cfyq_Name* val);
312     Cfyq_Name* GetFyqName();
313 };
314 
315 /*
316 
317 =  赋值操作
318 +->偏差赋值 分两种形式,+>大于基准价,偏离;->小于基准价,偏离
319 [] 取值范围分两种形式:1、“,”标志去除 例如[1,2]去掉1个最高,2个最低分
320         “-”标志的范围[1,2],例如[0-3]表示0-3分,可简写为[3]
321 ()入口参数
322 
323 */
324 
325 
326 /*表达式 名称 描述了表达式的基本功能界面
327 
328 文法示例:
329 zz(corp)[3]:pf,nomark;  
330 企业资质(暗标)3分  
331 xmbz:ml;                          项目班子成员目录
332 bj(tbbj)[10]=jzj(1,2) -> bj>jzj ? {kja}/{step} : {kjb}/{step};  
333 投标报价满分10,正偏离基准价{step}扣减{kja},负偏离基准价{step}扣减{kjb}
334 
335 */
336 
337 class FLY_DBASE_API  Cfyq_expression : public Cfyq_Name
338 {
339     DECLARE_SERIAL_EXTDLL(Cfyq_expression)
340 public:
341     Cfyq_expression();
342     ~Cfyq_expression();
343     //字符串到对象
344     bool InitExpression(const CString& expression );
345     //对象到字符串
346     void BackExpression();
347     //将基准价范围用文字的形式表现出来
348     virtual bool toString();
349     //目前计算不通过表达式计算
350     virtual void Calc(CString& str);
351 
352     void Serialize(CArchive& ar);
353 
354     //范围相关-------去高去低
355     void FindScope(vec_fyq_Scope& m_vecScope, Cfyq_node* node);
356     vec_fyq_Scope& GetScopeFromTree();
357     double GetScopeFromVec(int Flag, int index, int row);
358     void SetVecVarNode(vecVarNode_ZBFileInfo& vecVarNode) { m_vecVarNode = vecVarNode; }
359     std::vector<std::vector<int>>& GetScopeMinMax();
360     vecCountDeal& GetCountDeal();
361 
362 
363     //变量相关
364     void FindVar(vec_fyq_Var& m_VecVar, Cfyq_node* node);
365     vec_fyq_Var& GetVarFromTree();
366     void AddVar(CString explain, CString doublestr);
367     void AddVar(vec_fyq_Var& m_VecVar, Cfyq_node* node, CString explain, CString doublestr);
368     double GetdVar(int index);
369     void ChangeVecVarFromTree(const CString& strVar, CString str);
370     void ChangeVecVarFromTree(const CString& strVar, double dval);
371 
372     //常量相关
373     bool IsExistConst(const CString& strVar);
374     void FindConst(vec_fyq_Const& m_VecConst,Cfyq_node *node);
375     vec_fyq_Const& GetConstFromTree();
376     //增加常量主要针对k,q,m
377     void AddConst(CString str);
378     void AddConst(vec_fyq_Const& m_vecConst, Cfyq_node* node, CString str);
379 
380     //显示当前的计算方法
381     void AddJzjKind(long kind);
382     void AddJzjKind(Cfyq_node* node,long kind);
383     long GetJzjKind() {    return m_njzjKind;}
384 
385 public:
386     vec_fyq_Var m_vecVar;
387     vec_fyq_Const m_vecConst;
388     vec_fyq_Scope m_vecScope;
389     Cfyq_Interpreter *m_pInterpreter;
390     std::vector<std::vector<int>> vecScope;
391     vecVarNode_ZBFileInfo m_vecVarNode;
392     vecCountDeal m_vecCountDeal;
393     int m_nrow;
394     int m_njzjKind;
395     CString m_strToDB;
396 }; 
   1 #include "StdAfx.h"
   2 #include "fyq_interpreter.h"
   3 #include <afx.h>
   4 
   5 
   6 IMPLEMENT_SERIAL( Cfyq_node, CTableRow, 0)
   7 Cfyq_node::Cfyq_node()
   8 {
   9     m_dValue = 0;        
  10     m_bStateInputChar = false;
  11     m_pInterpreter = NULL;
  12 };
  13 
  14 
  15 Cfyq_node::~Cfyq_node()
  16 {
  17 
  18 }
  19 
  20 //  1、没有必要空格是忽略的
  21 //     2、有必要(字符之间是有必要,符号之间->之间是有必要)
  22 //     3、开闭 ),] 状态 是否闭合 -》  
  23 //  
  24 //     进入字符状态,且未闭合
  25 int Cfyq_node::Accept(Cfyq_Interpreter* pInterpreter, char input)
  26 {
  27     return 0;
  28 }
  29 
  30 bool Cfyq_node::NextNode(Cfyq_Interpreter* pInterpreter, char input)
  31 {
  32     return false;
  33 }
  34 
  35 void Cfyq_node::NextBackNode(Cfyq_node* startName, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
  36 {
  37     return;
  38 }
  39 
  40 CFyq_NodeKind Cfyq_node::GetNodeGrade()
  41 {
  42     return FNK_Node;
  43 }
  44 
  45 void Cfyq_node::ErrorMsg(CString& str)
  46 {
  47     return;
  48 }
  49 
  50 void Cfyq_node::Serialize(CArchive& ar)
  51 {
  52     int rightcode = 1;
  53     if( ar.IsStoring() )
  54     { 
  55         ar << rightcode;
  56         ar << m_dValue;
  57         ar << m_sValue;
  58         ar << m_strContent;
  59         ar << m_vecSubNode;
  60     }
  61     else
  62     {
  63         ar >> rightcode;
  64         ar >> m_dValue;
  65         ar >> m_sValue;
  66         ar >> m_strContent;
  67         ar >> m_vecSubNode;
  68     }
  69 }
  70 
  71 CString& Cfyq_node::GetContent()
  72 {
  73     return m_strContent;
  74 }
  75 
  76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79 
  80 IMPLEMENT_SERIAL( Cfyq_const, Cfyq_element, 0)
  81 int Cfyq_const::Accept(Cfyq_Interpreter* pInterpreter, char input)
  82 {
  83     if( Cfyq_Interpreter::IsTrueChar( input ) )
  84         return AppendChar(pInterpreter, input);
  85 
  86     switch( input )
  87     {
  88     case ',':
  89     case ';':
  90             return 2;
  91     }
  92 
  93     return 0;
  94 }
  95 
  96 bool Cfyq_const::NextNode(Cfyq_Interpreter* pInterpreter, char input)
  97 {
  98     if(!pInterpreter->CheckConst(m_strContent))
  99         return false;
 100 
 101     switch( input )
 102     {
 103     case ',':
 104         {
 105             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Const));
 106             return true;
 107         }
 108     case ';':
 109         {
 110             return true;
 111         }
 112     default:
 113         return false;
 114     }
 115 }
 116 
 117 
 118 void Cfyq_const::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
 119 {
 120     CString strTemp;
 121     if (bLast)
 122         strTemp.Format("%s", m_strContent);
 123     else
 124         strTemp.Format("%s,", m_strContent);
 125     str += strTemp;
 126     pInterpreter->ChangeBackNode(node);
 127 }
 128 
 129 void Cfyq_const::ErrorMsg(CString& str)
 130 {
 131     CString strTmp = "常量出现错误!\n";
 132     str += strTmp;
 133 }
 134 
 135 void Cfyq_const::Serialize(CArchive& ar)
 136 {
 137     Cfyq_node::Serialize(ar);
 138     int rightcode = 1;
 139     if(ar.IsStoring())
 140     {
 141         ar << rightcode;
 142     }
 143     else
 144     {
 145         ar >> rightcode;
 146     }
 147 }
 148 
 149 IMPLEMENT_SERIAL( Cfyq_Var, Cfyq_element, 0)
 150 Cfyq_Var::Cfyq_Var()
 151 {
 152     m_bInited = false;
 153     CString m_sEngName = "";
 154     CString m_sExplain = "";
 155     CString m_dValueToStr = "";
 156     m_nLifePeriod = 0;
 157 }
 158 
 159 
 160 
 161 void Cfyq_Var::SetEngName(CString name)
 162 {
 163     m_sEngName = name;
 164 }
 165 
 166 void Cfyq_Var::SetExplain(CString Explain)
 167 {
 168     m_sExplain = Explain;
 169 }
 170 
 171 int Cfyq_Var::Accept(Cfyq_Interpreter* pInterpreter, char input)
 172 {
 173     if( Cfyq_Interpreter::IsTrueChar( input ) || Cfyq_Interpreter::IsChineseChar( input ) || (':' == input && !IsClose()) )
 174         return AppendChar(pInterpreter, input);
 175 
 176     switch( input )
 177     {
 178     case ')':
 179         SetClose(true);
 180 
 181         
 182         if(m_strContent.Find(":") == -1)
 183         {
 184             SetEngName(m_strContent);
 185             SetExplain("");
 186         }
 187         else
 188         {
 189             CString strleft = m_strContent.Left(m_strContent.Find(":"));
 190             CString strRight = m_strContent.Mid(m_strContent.Find(":")+1,m_strContent.GetLength());
 191             SetEngName(strleft);
 192             SetExplain(strRight);
 193         }
 194         
 195 
 196         {
 197             if(pInterpreter->NextStrIsIgnoreSpace(",$(")||pInterpreter->NextStrIsIgnoreSpace(";")||pInterpreter->NextStrIsIgnoreSpace(":"))
 198                 return 3;
 199             else
 200                 return 0;
 201         }
 202     case ',':
 203         {
 204             if(pInterpreter->NextStrIsIgnoreSpace("$("))
 205                 return 3;
 206             else 
 207                 return 0;
 208         }
 209     case '$':
 210         {
 211             if(pInterpreter->NextStrIsIgnoreSpace("("))
 212                 return 2;
 213             else 
 214                 return 0;
 215         }
 216     case '(':
 217         {
 218             if(pInterpreter->LastStrIsIgnoreSpace("$"))
 219                 return 3;
 220             else
 221                 return 0;
 222         }
 223     case ':':
 224         {
 225             return 2;
 226         }
 227     case ';':
 228         {
 229             return 2;
 230         }
 231     }
 232 
 233     return 0;
 234 }
 235 
 236 bool Cfyq_Var::NextNode(Cfyq_Interpreter* pInterpreter, char input)
 237 {
 238     if(!IsClose())
 239         return false;
 240 
 241     switch( input )
 242     {
 243     case '$':
 244         {
 245             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Value));
 246             return true;
 247         }
 248     case ':':
 249         {
 250             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Define));
 251             return true;
 252         }
 253     case ';':
 254         {
 255             return true;
 256         }
 257     default:
 258         return false;
 259     }
 260 }
 261 
 262 void Cfyq_Var::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
 263 {
 264     CString strTemp;
 265     if (bLast)
 266     {
 267         if (!m_dValueToStr.IsEmpty())
 268             strTemp.Format("$(%s:%s)", m_sExplain, m_dValueToStr);
 269         else
 270             strTemp.Format("$(%s:%s)", m_sExplain, m_sEngName);
 271     }
 272     else
 273     {
 274         if (!m_dValueToStr.IsEmpty())
 275             strTemp.Format("$(%s:%s),", m_sExplain, m_dValueToStr);
 276         else
 277             strTemp.Format("$(%s:%s),", m_sExplain, m_sEngName);
 278     }
 279     str += strTemp;
 280     pInterpreter->ChangeBackNode(node);
 281 }
 282 
 283 void Cfyq_Var::ErrorMsg(CString& str)
 284 {
 285     CString strTmp = "变量出现错误!\n";
 286     str += strTmp;
 287 }
 288 
 289 void Cfyq_Var::Serialize(CArchive& ar)
 290 {
 291     Cfyq_node::Serialize(ar);
 292     int rightcode = 1;
 293     if(ar.IsStoring())
 294     {
 295         ar << rightcode;
 296         ar << m_sEngName;
 297         ar << m_sExplain;
 298         ar << m_nLifePeriod;
 299     }
 300     else
 301     {
 302         ar >> rightcode;
 303         ar >> m_sEngName;
 304         ar >> m_sExplain;
 305         ar >> m_nLifePeriod;
 306     }
 307 }
 308 
 309 int Cfyq_scope::GetMinCount(int index)
 310 {
 311     return m_MinMax[index][0];
 312 }
 313 
 314 int Cfyq_scope::GetMaxCount(int index)
 315 {
 316     return m_MinMax[index][1];
 317 }
 318 
 319 int Cfyq_scope::GetMin(int index)
 320 {
 321     return m_MinMax[index][2];
 322 }
 323 
 324 int Cfyq_scope::GetMax(int index)
 325 {
 326     return m_MinMax[index][3];
 327 }
 328 
 329 void Cfyq_scope::SetRow(int row)
 330 {
 331     m_nrow = row;
 332 }
 333 
 334 int Cfyq_scope::GetRow()
 335 {
 336     return m_nrow;
 337 }
 338 
 339 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 340 IMPLEMENT_SERIAL( Cfyq_scope, Cfyq_element, 0)
 341 //解析范围
 342 bool Cfyq_scope::SetScope()
 343 {
 344     CString strLeft,strMid,strRight,strLast;
 345     int nMidIndex;
 346     //上下限
 347     if(m_strContent == m_strContent.SpanIncluding("0123456789.-"))
 348     {
 349         if(m_strContent == m_strContent.SpanIncluding("0123456789."))
 350         {
 351             m_MinMax[0][0] = 0;
 352             m_MinMax[0][1] = atoi(m_strContent);
 353             return true;
 354         }
 355         else
 356         {    
 357             nMidIndex = m_strContent.Find("-");
 358             strLeft =  m_strContent.Left(nMidIndex);
 359             strRight = m_strContent.Mid(nMidIndex + 1,m_strContent.GetLength() -1 );
 360             if(strLeft == strLeft.SpanIncluding("0123456789.")
 361                 && strRight == strRight.SpanIncluding("0123456789."))
 362             {
 363                 m_MinMax[0][0] = atoi(strLeft);
 364                 m_MinMax[0][1] = atoi(strRight);
 365                 m_MinMax[0][2] = 0;
 366                 return true;
 367             }
 368             else
 369             {
 370                 return false;
 371             }
 372         }
 373         m_bFlag = 0;
 374         SetRow(0);
 375     }
 376     //数轴
 377     else
 378     {
 379         if(m_strContent.Find(";") == -1)
 380         {
 381             int nMidIndex = m_strContent.Find(',') == -1;
 382             if(nMidIndex != -1)
 383             {
 384                 SetRow(1);
 385                 if( m_strContent.Find(',') != -1)
 386                 {    
 387                     CString strTmp;
 388                     int ipos = 0;
 389                     while(AfxExtractSubString(strTmp,m_strContent,ipos,','))
 390                     {
 391                         ipos++;
 392                         switch(ipos)
 393                         {
 394                         case 1:
 395                             strLeft = strTmp;
 396                             break;
 397                         case 2:
 398                             strMid = strTmp;
 399                             break;
 400                         case 3:
 401                             strRight = strTmp;
 402                             break;
 403                         case 4:
 404                             strLast = strTmp;
 405                         }
 406                     }
 407                     if(strLeft == strLeft.SpanIncluding("0123456789.")
 408                         && strRight == strRight.SpanIncluding("0123456789.") 
 409                         && strMid == strMid.SpanIncluding("0123456789.")
 410                         && strLast == strLast.SpanIncluding("0123456789."))
 411                     {
 412                         m_MinMax[0][0] = atoi(strLeft);
 413                         m_MinMax[0][1] = atoi(strMid);
 414                         m_MinMax[0][2] = atoi(strRight);
 415                         m_MinMax[0][3] = atoi(strLast);
 416                         return true;
 417                     }
 418                     else
 419                     {
 420                         return false;
 421                     }
 422                 }
 423 
 424             }
 425 
 426             else
 427             {
 428                 return false;
 429             }
 430         }
 431         else
 432         {
 433             int i = 0;
 434             CString strTmp;
 435             while(AfxExtractSubString(strTmp,m_strContent,i,';'))
 436             {
 437                 CString strTmpdot;
 438                 int ipos = 0;
 439                 while(AfxExtractSubString(strTmpdot,strTmp,ipos,','))
 440                 {
 441                     ipos++;
 442                     switch(ipos)
 443                     {
 444                     case 1:
 445                         strLeft = strTmpdot;
 446                         break;
 447                     case 2:
 448                         strMid = strTmpdot;
 449                         break;
 450                     case 3:
 451                         strRight = strTmpdot;
 452                         break;
 453                     case 4:
 454                         strLast = strTmpdot;
 455                         break;
 456                     }
 457                 }
 458                 if (strLeft == strLeft.SpanIncluding("0123456789.")
 459                     && strRight == strRight.SpanIncluding("0123456789.")
 460                     && strMid == strMid.SpanIncluding("0123456789.")
 461                     && strLast == strLast.SpanIncluding("0123456789."))
 462                 {
 463                     m_MinMax[i][0] = atoi(strLeft);
 464                     m_MinMax[i][1] = atoi(strMid);
 465                     m_MinMax[i][2] = atoi(strRight);
 466                     m_MinMax[i][3] = atoi(strLast);
 467                     i++;
 468                     continue;
 469                 }
 470                 else
 471                 {
 472                     return false;
 473                 }
 474             }
 475             SetRow(i);
 476         }
 477         m_bFlag = 1;
 478     }
 479     return true;
 480 }
 481 
 482 bool Cfyq_scope::ReplaceScope(CString strTemp)
 483 {
 484     m_strContent = strTemp;
 485     memset(m_MinMax, -1, sizeof(m_MinMax));
 486     CString strLeft, strMid, strRight, strLast;
 487     int nMidIndex;
 488     //上下限
 489     if (m_strContent == m_strContent.SpanIncluding("0123456789.-"))
 490     {
 491         if (m_strContent == m_strContent.SpanIncluding("0123456789."))
 492         {
 493             m_MinMax[0][0] = 0;
 494             m_MinMax[0][1] = atoi(m_strContent);
 495             return true;
 496         }
 497         else
 498         {
 499             nMidIndex = m_strContent.Find("-");
 500             strLeft = m_strContent.Left(nMidIndex);
 501             strRight = m_strContent.Mid(nMidIndex + 1, m_strContent.GetLength() - 1);
 502             if (strLeft == strLeft.SpanIncluding("0123456789.")
 503                 && strRight == strRight.SpanIncluding("0123456789."))
 504             {
 505                 m_MinMax[0][0] = atoi(strLeft);
 506                 m_MinMax[0][1] = atoi(strRight);
 507                 m_MinMax[0][2] = 0;
 508                 return true;
 509             }
 510             else
 511             {
 512                 return false;
 513             }
 514         }
 515         m_bFlag = 0;
 516         SetRow(0);
 517     }
 518     //数轴
 519     else
 520     {
 521         if (m_strContent.Find(";") == -1)
 522         {
 523             int nMidIndex = m_strContent.Find(',') == -1;
 524             if (nMidIndex != -1)
 525             {
 526                 SetRow(1);
 527                 if (m_strContent.Find(',') != -1)
 528                 {
 529                     CString strTmp;
 530                     int ipos = 0;
 531                     while (AfxExtractSubString(strTmp, m_strContent, ipos, ','))
 532                     {
 533                         ipos++;
 534                         switch (ipos)
 535                         {
 536                         case 1:
 537                             strLeft = strTmp;
 538                             break;
 539                         case 2:
 540                             strMid = strTmp;
 541                             break;
 542                         case 3:
 543                             strRight = strTmp;
 544                             break;
 545                         case 4:
 546                             strLast = strTmp;
 547                         }
 548                     }
 549                     if (strLeft == strLeft.SpanIncluding("0123456789.")
 550                         && strRight == strRight.SpanIncluding("0123456789.")
 551                         && strMid == strMid.SpanIncluding("0123456789.")
 552                         && strLast == strLast.SpanIncluding("0123456789."))
 553                     {
 554                         m_MinMax[0][0] = atoi(strLeft);
 555                         m_MinMax[0][1] = atoi(strMid);
 556                         m_MinMax[0][2] = atoi(strRight);
 557                         m_MinMax[0][3] = atoi(strLast);
 558                         return true;
 559                     }
 560                     else
 561                     {
 562                         return false;
 563                     }
 564                 }
 565 
 566             }
 567 
 568             else
 569             {
 570                 return false;
 571             }
 572         }
 573         else
 574         {
 575             int i = 0;
 576             CString strTmp;
 577             while (AfxExtractSubString(strTmp, m_strContent, i, ';'))
 578             {
 579                 CString strTmpdot;
 580                 int ipos = 0;
 581                 while (AfxExtractSubString(strTmpdot, strTmp, ipos, ','))
 582                 {
 583                     ipos++;
 584                     switch (ipos)
 585                     {
 586                     case 1:
 587                         strLeft = strTmpdot;
 588                         break;
 589                     case 2:
 590                         strMid = strTmpdot;
 591                         break;
 592                     case 3:
 593                         strRight = strTmpdot;
 594                         break;
 595                     case 4:
 596                         strLast = strTmpdot;
 597                         break;
 598                     }
 599                 }
 600                 if (strLeft == strLeft.SpanIncluding("0123456789.")
 601                     && strRight == strRight.SpanIncluding("0123456789.")
 602                     && strMid == strMid.SpanIncluding("0123456789.")
 603                     && strLast == strLast.SpanIncluding("0123456789."))
 604                 {
 605                     m_MinMax[i][0] = atoi(strLeft);
 606                     m_MinMax[i][1] = atoi(strMid);
 607                     m_MinMax[i][2] = atoi(strRight);
 608                     m_MinMax[i][3] = atoi(strLast);
 609                     i++;
 610                     continue;
 611                 }
 612                 else
 613                 {
 614                     return false;
 615                 }
 616             }
 617             SetRow(i);
 618         }
 619         m_bFlag = 1;
 620     }
 621     return true;
 622 }
 623 
 624 bool Cfyq_scope::SetScopeToName(Cfyq_Interpreter* pInterpreter)
 625 {
 626     pInterpreter->GetCurName()->SetScope(this);
 627     return true;
 628 }
 629 
 630 int Cfyq_scope::GetFlag()
 631 {
 632     return m_bFlag;
 633 }
 634 
 635 void Cfyq_scope::Serialize(CArchive& ar)
 636 {
 637     Cfyq_node::Serialize(ar);
 638     int rightcode = 1;
 639     if(ar.IsStoring())
 640     {
 641         ar << rightcode;
 642         ar << m_bFlag;
 643         ar << m_nrow;
 644         if(m_nrow)
 645         for(int i = 0;i < m_nrow;++i)
 646             for(int j = 0;j < 4;++j)
 647         {
 648             ar << m_MinMax[i][j];
 649         }
 650     }
 651     else
 652     {
 653         ar >> rightcode;
 654         ar >> m_bFlag;
 655         ar >> m_nrow;
 656         if (m_nrow)
 657         for (int i = 0; i < m_nrow; ++i)
 658             for (int j = 0; j < 4; ++j)
 659             {
 660                 ar >> m_MinMax[i][j];
 661             }
 662     }
 663     
 664 }
 665 
 666 void Cfyq_scope::ErrorMsg(CString& str)
 667 {
 668     CString strTmp = "范围出现错误!\n";
 669     str += strTmp;
 670 }
 671 
 672 int Cfyq_scope::Accept(Cfyq_Interpreter* pInterpreter, char input)
 673 {
 674     if( Cfyq_Interpreter::IsTrueChar( input ) )
 675         return AppendChar(pInterpreter, input);
 676 
 677     switch( input )
 678     {
 679     case '=':
 680     case ':':
 681     case '{':
 682             return 2;
 683     case ']':
 684         {
 685             SetClose(true);
 686 
 687             if(pInterpreter->NextStrIsIgnoreSpace("=")||pInterpreter->NextStrIsIgnoreSpace(":")||pInterpreter->NextStrIsIgnoreSpace("->")
 688             ||pInterpreter->NextStrIsIgnoreSpace("{"))
 689                 return 3;
 690             else
 691                 return 0;
 692         }
 693     case '-':
 694         {
 695             if(pInterpreter->NextStrIs(">"))
 696                 return 2;
 697             m_strContent += input;
 698             return 1;
 699         }
 700     case ',':
 701         {
 702             m_strContent += input;
 703             return 1;
 704         }
 705     case ';':
 706         {
 707             m_strContent += input;
 708             return 1;
 709         }
 710     }
 711 
 712     return 0;
 713 }
 714 
 715 bool Cfyq_scope::NextNode(Cfyq_Interpreter* pInterpreter, char input)
 716 {
 717     if(!IsClose())
 718         return false;
 719     if(!SetScope())
 720         return false;
 721     else
 722         SetScopeToName(pInterpreter);
 723     switch( input )
 724     {
 725     case '=':
 726         {
 727             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Set));
 728             return true;
 729         }
 730     case '-':
 731         {
 732             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Offset));
 733             return true;
 734         }
 735     case ':':
 736         {
 737             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Define));
 738             return true;
 739         }
 740     case '{':
 741         {
 742             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Jzj));
 743             return true;
 744         }
 745     default:
 746         return false;
 747     }
 748 }
 749 
 750 
 751 CFyq_NodeKind Cfyq_scope::GetNodeGrade()
 752 {
 753     return FNK_Scope;
 754 }
 755 
 756 Cfyq_scope::Cfyq_scope()
 757 {
 758     memset(m_MinMax,-1,sizeof(m_MinMax));
 759     m_bFlag = -1; 
 760     m_nrow = 0;
 761 }
 762 
 763 Cfyq_scope::~Cfyq_scope()
 764 {
 765 
 766 }
 767 
 768 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 769 
 770 IMPLEMENT_SERIAL( Cfyq_opt, Cfyq_node, 0)
 771 
 772 void Cfyq_opt::Serialize(CArchive& ar)
 773 {
 774     int rightcode = 1;
 775     if( ar.IsStoring() )
 776     { 
 777         ar << rightcode;
 778     }
 779     else
 780     {
 781         ar >> rightcode;
 782     }
 783 
 784 }
 785 
 786 Cfyq_opt::Cfyq_opt()
 787 {
 788 
 789 }
 790 
 791 Cfyq_opt::~Cfyq_opt()
 792 {
 793 
 794 }
 795 
 796 int Cfyq_offset::Accept(Cfyq_Interpreter* pInterpreter, char input)
 797 {
 798     if(input == ' ')
 799         return 3;
 800     if( Cfyq_Interpreter::IsTrueChar( input ) )
 801         return 0;
 802 
 803     switch( input )
 804     {
 805     case '>':
 806         {
 807             if(pInterpreter->NextStrIsIgnoreSpace("$("))
 808                 return 3;
 809             else
 810                 return 0;
 811         }
 812     case '$':
 813         {
 814             if(pInterpreter->NextStrIsIgnoreSpace("("))
 815                 return 2;
 816             else
 817                 return 0;
 818         }
 819     }
 820 
 821     return 0;
 822 }
 823 
 824 bool Cfyq_offset::NextNode(Cfyq_Interpreter* pInterpreter, char input)
 825 {
 826     switch( input )
 827     {
 828     case '$':
 829         {
 830             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Value));
 831             return true;
 832         }
 833     default:
 834         return false;
 835     }
 836 }
 837 IMPLEMENT_SERIAL( Cfyq_offset, Cfyq_opt, 0)
 838 Cfyq_offset::Cfyq_offset()
 839 {
 840     Cfyq_Name* m_pName = NULL;
 841     int m_bcanSerial = 0;
 842 }
 843 
 844 void Cfyq_offset::Serialize(CArchive& ar)
 845 {
 846     int rightcode = 1;
 847     Cfyq_node::Serialize(ar);
 848     CString tmpStr;
 849     if( ar.IsStoring() )
 850     { 
 851         ar << rightcode;
 852         ar << m_bcanSerial;
 853         if (m_bcanSerial)
 854         {
 855             m_pName->Serialize(ar);
 856         }
 857     }
 858     else
 859     {
 860         ar >> rightcode;
 861         ar >> m_bcanSerial;
 862         if (m_bcanSerial)
 863         {
 864             m_pName = new Cfyq_Name();
 865             m_pName->Serialize(ar);
 866         }
 867     }
 868 }
 869 
 870 void Cfyq_offset::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
 871 {
 872     if (m_pName)
 873     {
 874         m_pName->NextBackNode(node, str, pInterpreter, 1);
 875     }
 876     str += "->";
 877     pInterpreter->ChangeBackNode(node);
 878 }
 879 
 880 void Cfyq_offset::SetFyqName(Cfyq_Name* val)
 881 {
 882     m_pName = val;
 883     m_bcanSerial = 1;
 884 }
 885 
 886 Cfyq_Name* Cfyq_offset::GetFyqName()
 887 {
 888     return m_pName;
 889 }
 890 
 891 void Cfyq_expression::Calc(CString& str)
 892 {
 893 //     GetVarFromTree();
 894 //     double bj = 1010,jzj = 500;
 895 // 
 896 //     double Acost = (bj - jzj ) / jzj;//偏离率
 897 //     if ( bEqual(Acost, 0 ,MinE))
 898 //     {
 899 //         m_dValue = m_pInterpreter->GetScope(1,1);
 900 //         m_sValue.Format( "基准价:%s,无偏离 ,得分:%s" , GetForamtedNumber(m_dValue), GetForamtedNumber(m_dValue) );
 901 //         str = m_sValue;
 902 //         return;
 903 //     }
 904 // 
 905 //     CString sAcost,sbj,sjzj,sbdiv;
 906 //     sbj = GetForamtedNumber(bj),sjzj = GetForamtedNumber(jzj);
 907 //     sAcost.Format(  "(%s-%s)/%s" ,sbj, sjzj,sjzj );
 908 // 
 909 // 
 910 //     double step   = GetdVar(0);
 911 //     step = step / 100;
 912 //     int bdiv      = Keep0Bit( Acost / step );
 913 //     double kj_zpc = GetdVar(1);
 914 //     double kj_fpc = GetdVar(2);
 915 // 
 916 //     if (Acost > 0) 
 917 //     {
 918 //         m_dValue = m_pInterpreter->GetScope(0,1) - bdiv * kj_zpc;
 919 //         m_sValue.Format( "基准价:%s,偏离率:%s 报价得分:%s - %d*%s" , 
 920 //             GetForamtedNumber(jzj), 
 921 //             GetForamtedNumber(Acost), 
 922 //             GetForamtedNumber(m_pInterpreter->GetScope(0,1)), bdiv, GetForamtedNumber(kj_zpc) );
 923 //     }
 924 //     else
 925 //     {
 926 //         m_dValue = m_pInterpreter->GetScope(0,1) + bdiv * kj_zpc;
 927 //         m_sValue.Format( "基准价:%s,偏离率:%s 报价得分:%s + %d*%s" , 
 928 //             GetForamtedNumber(jzj), 
 929 //             GetForamtedNumber(Acost), 
 930 //             GetForamtedNumber(m_pInterpreter->GetScope(0,1)), bdiv, GetForamtedNumber(kj_zpc) );
 931 //     }
 932 // 
 933 // 
 934 //     if ( m_dValue < 0)
 935 //         m_dValue = 0;
 936 //     str = m_sValue;
 937 //     return ;
 938 };
 939 
 940 IMPLEMENT_SERIAL( Cfyq_expression, Cfyq_Name, 0)
 941 Cfyq_expression::Cfyq_expression()
 942 {
 943     m_pInterpreter = new Cfyq_Interpreter();
 944     m_nrow = 0;
 945 
 946     //m_pScoringSystemDefine = NULL;
 947 }
 948 
 949 Cfyq_expression::~Cfyq_expression()
 950 { 
 951     if ( m_pInterpreter )
 952     {
 953         delete m_pInterpreter;
 954         m_pInterpreter = NULL;
 955     }
 956     ClearVecPtr(m_vecVar);
 957 }
 958 
 959 bool Cfyq_expression::InitExpression(const CString& expression )
 960 {
 961     //解析公式
 962 
 963     if(!m_pInterpreter->Interpreter(expression))
 964         return false;        
 965 
 966     //拿到解析到的Vec
 967     vec_fyq_Node& vecExpression = m_pInterpreter->GetvecExpression();
 968 
 969     //获得根节点
 970     Cfyq_Name* FirstName = nullptr;
 971 
 972     Cfyq_node* root = this;
 973 
 974     Cfyq_node* pCurNode = root;
 975     Cfyq_Name* pCurName = nullptr;
 976     for(auto it = vecExpression.begin(); it!=vecExpression.end(); it++)
 977     {
 978         if(!FirstName)
 979         {
 980             FirstName = (Cfyq_Name*)(*it);
 981             this->m_strContent = FirstName->GetContent();
 982             this->m_sParam = FirstName->GetParam();
 983             this->m_pScope = FirstName->GetScope();
 984             continue;
 985         }
 986         if (FNK_Set == (*it)->GetNodeGrade())
 987         {
 988             root->m_vecSubNode.push_back(*it);
 989             pCurNode = *it;
 990         }
 991         else if( FNK_Define == (*it)->GetNodeGrade())
 992         {
 993             root->m_vecSubNode.push_back(*it);
 994             pCurNode = *it;
 995         }
 996         else if( FNK_Offset == (*it)->GetNodeGrade() )
 997         {
 998             pCurNode->m_vecSubNode.push_back(*it);
 999             pCurNode = (*it);
1000             Cfyq_offset* offset = (Cfyq_offset*)(*it);
1001             if(!pCurName)
1002                 return false;
1003             offset->SetFyqName(pCurName);
1004         }
1005         else if( FNK_Const == (*it)->GetNodeGrade() || FNK_Value == (*it)->GetNodeGrade() )
1006         {
1007             pCurNode->m_vecSubNode.push_back(*it);
1008         }
1009         else if( FNK_Name == (*it)->GetNodeGrade() )
1010         {
1011             pCurName =  (Cfyq_Name*)(*it);
1012             m_nrow = pCurName->GetScope()->GetRow();
1013             m_njzjKind = pCurName->Getjzj()->m_nkind;
1014         }
1015     }
1016     return true;
1017 };//初始化
1018 
1019 
1020 
1021 void Cfyq_expression::BackExpression()
1022 {
1023     m_strToDB = "";
1024     m_pInterpreter->backInterpreter(this, m_strToDB);
1025 }
1026 
1027 std::vector<std::vector<int>>& Cfyq_expression::GetScopeMinMax()
1028 {
1029     double dMinCount;
1030     double dMaxCount;
1031     double dMaxNumber;
1032     double dMinNumber;
1033     int k = 0;
1034     int curRow = 0;
1035     GetScopeFromTree();
1036     vecScope.clear();
1037     while(1)
1038     {
1039         dMinCount = GetScopeFromVec(1, 0, curRow);
1040         dMaxCount = GetScopeFromVec(1, 1, curRow);
1041         dMinNumber = GetScopeFromVec(1, 2, curRow);
1042         dMaxNumber = GetScopeFromVec(1, 3, curRow);
1043         if (dMinCount == -1 || dMaxCount == -1)
1044         {
1045             break;
1046         }
1047         vector<int> vec;
1048         vec.push_back(dMinCount);
1049         vec.push_back(dMaxCount);
1050         vec.push_back(dMaxNumber);
1051         vec.push_back(dMinNumber);
1052         vecScope.push_back(vec);
1053         curRow++;
1054     }
1055     return vecScope;
1056 }
1057 
1058 
1059 bool Cfyq_expression::toString()
1060 {
1061     GetVarFromTree();
1062     GetScopeFromTree();
1063     if(m_vecVar.empty())
1064     {
1065         m_sValue = "";
1066         return false;
1067     }
1068     double nStep = GetdVar(0);
1069     double nKja = GetdVar(1);
1070     double nKjb = GetdVar(2);
1071     double dMinCount;
1072     double dMaxCount;
1073     double dMaxNumber;
1074     double dMinNumber;
1075     CString txt1,txt2,txt3;
1076     CString str;
1077 
1078     int curRow = 0;
1079     if((dMaxCount = GetScopeFromVec(1,1,curRow++)) > -1)
1080     {
1081         str.Format("若有效标书小于等于%.0lf家,则不去掉最高最低价。\r\n", dMaxCount);
1082         txt1 += str;
1083     }
1084     while(curRow < m_nrow)
1085     {
1086         dMinCount = GetScopeFromVec(1, 0, curRow);
1087         dMaxCount = GetScopeFromVec(1, 1, curRow);
1088         dMinNumber = GetScopeFromVec(1, 2, curRow);
1089         dMaxNumber = GetScopeFromVec(1, 3, curRow);
1090         if (curRow == m_nrow - 1)
1091         {
1092             str.Format("若有效标书大于等于%.0lf家,则去掉%.0lf个最高价和%.0lf个最低价。\r\n", dMinCount, dMinNumber, dMaxNumber);
1093             txt1 += str;
1094             break;
1095         }
1096         curRow++;
1097         str.Format("若有效标书大于等于%.0lf家,小于%.0lf家,则去掉%.0lf个最高价和%.0lf个最低价。\r\n", dMinCount,
1098             dMaxCount,dMaxNumber,dMinNumber);
1099         txt1 += str;
1100     }
1101     if( nKjb > 0 )
1102     {
1103         txt2.Format("每低于 %.2lf%扣 %.2lf 分(不足 %.2lf%按 %.2lf%计)。 \r\n",nStep,nKjb,nStep,nStep);
1104     }
1105     else
1106     {
1107         nKjb = 0 - nKjb;
1108         txt2.Format("每低于 %.2lf%加 %.2lf 分(不足 %.2lf%按 %.2lf%计)。 \r\n",nStep,nKjb,nStep,nStep);
1109     }
1110 
1111 
1112     if(nKja > 0 )
1113     {
1114         txt3.Format("每高于 %.2lf%扣 %.2lf 分(不足 %.2lf%按 %.2lf%计)。 \r\n",nStep,nKja,nStep,nStep);
1115     }
1116     else
1117     {
1118         nKja = 0 - nKja;
1119         txt3.Format("每高于 %.2lf%加 %.2lf 分(不足 %.2lf%按 %.2lf%计)。 \r\n",nStep,nKja,nStep,nStep);
1120     }
1121     m_sValue = txt1 + txt2 + txt3;
1122     return true;
1123 }
1124 
1125 
1126 void Cfyq_expression::FindVar(vec_fyq_Var& m_VecVar,Cfyq_node *node)
1127 {
1128     if(node->GetNodeGrade() == FNK_Value)
1129     {
1130         if(std::find(m_VecVar.begin(), m_VecVar.end(), node) == m_VecVar.end())
1131             m_VecVar.push_back((Cfyq_Var*)node);
1132         return ;
1133     }
1134     for(int i  = 0;i < node->m_vecSubNode.size();++i)
1135     {
1136         FindVar(m_VecVar,node->m_vecSubNode[i]);
1137     }
1138 }
1139 
1140 vec_fyq_Var& Cfyq_expression::GetVarFromTree()
1141 {
1142     //ClearVecPtr(m_vecVar);
1143     FindVar(m_vecVar,this);
1144     return m_vecVar;
1145 }
1146 
1147 void Cfyq_expression::FindConst(vec_fyq_Const& m_VecConst,Cfyq_node *node)
1148 {
1149     if(node->GetNodeGrade() == FNK_Const)
1150     {
1151         if(std::find(m_vecConst.begin(), m_vecConst.end(), node) == m_vecConst.end())
1152             m_vecConst.push_back((Cfyq_const*)node);
1153         return ;
1154     }
1155     for(int i  = 0;i < node->m_vecSubNode.size();++i)
1156     {
1157         FindConst(m_vecConst,node->m_vecSubNode[i]);
1158     }
1159 }
1160 
1161 vec_fyq_Const& Cfyq_expression::GetConstFromTree()
1162 {
1163     FindConst(m_vecConst,this);
1164     return m_vecConst;
1165 }
1166 
1167 
1168 void Cfyq_expression::Serialize(CArchive& ar)
1169 {
1170     int rightcode = 1;
1171     Cfyq_node::Serialize(ar);
1172     if( ar.IsStoring() )
1173     { 
1174         ar << rightcode;
1175         ar << m_vecVar;
1176         ar << m_nrow;
1177     }
1178     else
1179     {
1180         ar >> rightcode;
1181         ar >> m_vecVar;
1182         ar >> m_nrow;
1183     }        
1184 }
1185 
1186 double Cfyq_expression::GetdVar(int index)
1187 {
1188     for(int i = 0;i < m_vecVar.size();++i)
1189     {
1190         if(i == index)
1191         {
1192             return m_vecVar[i]->m_dValue;
1193         }
1194     }
1195     return -1;
1196 }
1197 void Cfyq_expression::ChangeVecVarFromTree(const CString& strVar,double dval)
1198 {
1199     if (m_vecVar.empty())
1200     {
1201         GetVarFromTree();
1202     }
1203     auto it = find_if(m_vecVar.begin(), m_vecVar.end(), [strVar](const Cfyq_Var* var)
1204     {
1205         return var->m_sEngName.CompareNoCase(strVar) == 0;
1206     });
1207     if(it != m_vecVar.end())
1208     {
1209         CString strTemp;
1210         strTemp.Format("%lf", dval);
1211         (*it)->m_dValueToStr = strTemp;
1212         (*it)->m_dValue = dval;
1213     }
1214 }
1215 
1216 void Cfyq_expression::ChangeVecVarFromTree(const CString& strVar, CString str)
1217 {
1218     if (m_vecVar.empty())
1219     {
1220         GetVarFromTree();
1221     }
1222     auto it = find_if(m_vecVar.begin(), m_vecVar.end(), [strVar](const Cfyq_Var* var)
1223     {
1224         return var->m_sEngName.CompareNoCase(strVar) == 0;
1225     });
1226     if (it != m_vecVar.end())
1227     {
1228         (*it)->m_dValueToStr = str;
1229     }
1230 }
1231 
1232 void Cfyq_expression::FindScope(vec_fyq_Scope& m_vecScope, Cfyq_node* node)
1233 {
1234     if (node->GetNodeGrade() == FNK_Offset)
1235     {
1236         if (find(m_vecScope.begin(), m_vecScope.end(), ((Cfyq_offset*)node)->GetFyqName()->GetScope())
1237             == m_vecScope.end())
1238             m_vecScope.push_back(((Cfyq_offset*)node)->GetFyqName()->GetScope());
1239         return;
1240     }
1241     for_each(node->m_vecSubNode.begin(), node->m_vecSubNode.end(), [&](Cfyq_node* refer) {
1242         FindScope(m_vecScope, refer);
1243     });
1244 //     for each(Cfyq_node * tempnode in node->m_vecSubNode)
1245 //     {
1246 //         FindScope(m_vecScope, tempnode);
1247 //     }
1248 //     for (int i = 0; i < node->m_vecSubNode.size(); ++i)
1249 //     {
1250 //         FindScope(m_vecScope, node->m_vecSubNode[i]);
1251 //     }
1252 }
1253 
1254 vec_fyq_Scope& Cfyq_expression::GetScopeFromTree()
1255 {
1256     FindScope(m_vecScope, this);
1257     return m_vecScope;
1258 }
1259 
1260 double Cfyq_expression::GetScopeFromVec(int Flag, int index, int row)
1261 {
1262     for (auto it = m_vecScope.begin(); it != m_vecScope.end(); it++)
1263     {
1264         if ((*it) != NULL && Flag == ((Cfyq_scope*)(*it))->GetFlag())
1265         {
1266             switch (index)
1267             {
1268             case 0:
1269                 return ((Cfyq_scope*)(*it))->GetMinCount(row);
1270                 break;
1271             case 1:
1272                 return ((Cfyq_scope*)(*it))->GetMaxCount(row);
1273                 break;
1274             case 2:
1275                 return  ((Cfyq_scope*)(*it))->GetMin(row);
1276                 break;
1277             case 3:
1278                 return  ((Cfyq_scope*)(*it))->GetMax(row);
1279                 break;
1280             }
1281         }
1282     }
1283     return -1;
1284 }
1285 
1286 void Cfyq_expression::AddVar(vec_fyq_Var& m_VecVar, Cfyq_node* node, CString explain, CString doublestr)
1287 {
1288     if (node->GetNodeGrade() == FNK_Offset)
1289     {
1290         Cfyq_Var* var = new Cfyq_Var();
1291         var->m_sExplain = explain;
1292         var->m_dValueToStr = doublestr;
1293         var->m_strContent = explain + ":" + doublestr;
1294         auto vec = ((Cfyq_offset*)(node))->m_vecSubNode;
1295         auto it1 = find_if(vec.begin(), vec.end(), [var](Cfyq_node* node)
1296         {
1297             return var->m_strContent.CompareNoCase(node->m_strContent) == 0;
1298         });
1299         if (it1 == vec.end())
1300         {
1301             var->m_nLifePeriod = 1;
1302             ((Cfyq_offset*)(node))->m_vecSubNode.push_back(var);
1303         }
1304 
1305         auto it2 = find_if(m_VecVar.begin(), m_VecVar.end(), [var](Cfyq_node* node)
1306         {
1307             return var->m_strContent.CompareNoCase(node->m_strContent) == 0;
1308         });
1309         if (it2 == m_VecVar.end())
1310         {
1311             m_VecVar.push_back(var);
1312         }
1313         return;
1314     }
1315     for (int i = 0; i < node->m_vecSubNode.size(); ++i)
1316     {
1317         AddVar(m_VecVar, node->m_vecSubNode[i], explain, doublestr);
1318     }
1319 }
1320 
1321 void Cfyq_expression::AddVar(CString explain, CString doublestr)
1322 {
1323     GetVarFromTree();
1324     AddVar(m_vecVar, this, explain, doublestr);
1325 }
1326 
1327 vecCountDeal& Cfyq_expression::GetCountDeal()
1328 {
1329     m_vecCountDeal.clear();
1330     int dMinCount;
1331     int dMaxCount;
1332     int dMaxNumber;
1333     int dMinNumber;
1334     int curRow = 0;
1335     GetScopeFromTree();
1336     int start = 0;
1337     while (curRow < m_nrow)
1338     {
1339         dMinCount = GetScopeFromVec(1, 0, curRow);
1340         dMaxCount = GetScopeFromVec(1, 1, curRow);
1341         dMinNumber= GetScopeFromVec(1, 2, curRow);
1342         dMaxNumber= GetScopeFromVec(1, 3, curRow);
1343         CCountDeal deal(dMinCount, dMaxCount, dMinNumber, dMaxNumber);
1344         m_vecCountDeal.push_back(deal);
1345         curRow++;
1346     }
1347     return m_vecCountDeal;
1348 }
1349 
1350 void Cfyq_expression::AddJzjKind(Cfyq_node* node, long kind)
1351 {
1352     if (node->GetNodeGrade() == FNK_Offset)
1353     {
1354         CString str;
1355         str.Format("%d", kind);
1356         ((Cfyq_offset*)node)->GetFyqName()->Getjzj()->m_strContent = str;
1357         ((Cfyq_offset*)node)->GetFyqName()->Getjzj()->m_nkind = kind;
1358         return;
1359     }
1360     for (int i = 0; i < node->m_vecSubNode.size(); ++i)
1361     {
1362         AddJzjKind(node->m_vecSubNode[i], kind);
1363     }
1364 }
1365 
1366 void Cfyq_expression::AddJzjKind(long kind)
1367 {
1368     AddJzjKind(this, kind);
1369 }
1370 
1371 void Cfyq_expression::AddConst(vec_fyq_Const& m_vecConst, Cfyq_node* node, CString str)
1372 {
1373 
1374     if (node->GetNodeGrade() == FNK_Define)
1375     {
1376         Cfyq_const* pconst = new Cfyq_const();
1377         pconst->m_strContent = str;
1378         auto vec = ((Cfyq_offset*)(node))->m_vecSubNode;
1379         auto it1 = find_if(vec.begin(), vec.end(), [pconst](Cfyq_node* node)
1380         {
1381             return pconst->m_strContent.CompareNoCase(node->m_strContent) == 0;
1382         });
1383         if (it1 == vec.end())
1384         {
1385             ((Cfyq_offset*)(node))->m_vecSubNode.push_back(pconst);
1386         }
1387 
1388         auto it2 = find_if(m_vecConst.begin(), m_vecConst.end(), [pconst](Cfyq_node* node)
1389         {
1390             return pconst->m_strContent.CompareNoCase(node->m_strContent) == 0;
1391         });
1392         if (it2 == m_vecConst.end())
1393         {
1394             m_vecConst.push_back(pconst);
1395         }
1396         return;
1397     }
1398     for (int i = 0; i < node->m_vecSubNode.size(); ++i)
1399     {
1400         AddConst(m_vecConst, node->m_vecSubNode[i], str);
1401     }
1402 }
1403 
1404 void Cfyq_expression::AddConst(CString str)
1405 {
1406     GetConstFromTree();
1407     AddConst(m_vecConst, this, str);
1408     if (m_vecConst.empty())
1409     {
1410 
1411     }
1412 }
1413 
1414 bool Cfyq_expression::IsExistConst(const CString& strVar)
1415 {
1416     GetConstFromTree();
1417     auto it = find_if(m_vecConst.begin(), m_vecConst.end(), [strVar](Cfyq_const* pconst)
1418     {
1419         return strVar.CompareNoCase(pconst->m_strContent) == 0;
1420     });
1421     if(it == m_vecConst.end())
1422         return false;
1423     return true;
1424 }
1425 
1426 Cfyq_Interpreter::Cfyq_Interpreter( )
1427 {
1428     m_nCurIndex = 0;
1429     m_pCurNode = CreateNode(FNK_Name);
1430     m_pCurName = (Cfyq_Name*)m_pCurNode;
1431     m_vecExpression.push_back(GetCurNode());
1432     m_strFormula = "";
1433 
1434     m_name_obj.push_back( new CSysCodeKindDataInfo(  1, 1,"pdf", "pdf",0 ) );
1435     m_name_obj.push_back( new CSysCodeKindDataInfo(  2, 1,"rtf", "rtf",0 ) );
1436 
1437     //第二个参数为0不可复制
1438     m_name_obj.push_back( new CSysCodeKindDataInfo( 11, 0,"zz",     "资质/资格",0 ) );
1439     m_name_obj.push_back( new CSysCodeKindDataInfo( 12, 0,"yj",     "业绩",0 ) );
1440     m_name_obj.push_back( new CSysCodeKindDataInfo( 13, 0,"db",     "答辩",0 ) );
1441     m_name_obj.push_back( new CSysCodeKindDataInfo( 14, 0,"bj",     "报价得分",0 ) );
1442     m_name_obj.push_back( new CSysCodeKindDataInfo( 15, 0,"jzj", "基准价",0 ) );
1443     m_name_obj.push_back( new CSysCodeKindDataInfo( 16, 0,"hjqk", "获奖情况",0 ) );
1444     m_name_obj.push_back( new CSysCodeKindDataInfo( 17, 0,"tbxx", "投标信息",0 ) );
1445     m_name_obj.push_back( new CSysCodeKindDataInfo( 18, 0,"cgmx", "采购明细",0 ) );
1446     m_name_obj.push_back( new CSysCodeKindDataInfo( 19, 0,"khscore", "获奖情况",0 ) );
1447 
1448     m_param_obj.push_back( new CSysCodeKindDataInfo( 1, 1,"tbbj", "投标报价",0 ) );
1449     m_param_obj.push_back( new CSysCodeKindDataInfo( 2, 1,"csbj", "措施费用",0 ) );
1450     m_param_obj.push_back( new CSysCodeKindDataInfo( 3, 1,"qtbj", "其他费用",0 ) );
1451     m_param_obj.push_back( new CSysCodeKindDataInfo( 4, 1,"qd", "清单",0 ) );
1452     m_param_obj.push_back( new CSysCodeKindDataInfo( 5, 1,"kzj" , "控制价",0 ) );
1453 
1454     m_param_obj.push_back( new CSysCodeKindDataInfo( 11, 2,"corp", "单位",    0 ) );
1455     m_param_obj.push_back( new CSysCodeKindDataInfo( 12, 2,"emp" , "人员",    0 ) );
1456     m_param_obj.push_back( new CSysCodeKindDataInfo( 13, 2,"fzr" , "负责人",0 ) );
1457 
1458     m_param_obj.push_back( new CSysCodeKindDataInfo( 21, 3,"pf", "打分" ,0 ) );
1459     m_param_obj.push_back( new CSysCodeKindDataInfo( 22, 3,"hg" , "合格",0 ) );
1460     m_param_obj.push_back( new CSysCodeKindDataInfo( 23, 3,"pfml" , "打分+目录",0 ) );
1461     m_param_obj.push_back( new CSysCodeKindDataInfo( 24, 3,"hgml" , "合格+目录",0 ) );
1462 
1463 
1464     //const
1465     //m_const_obj.push_back( new CSysCodeKindDataInfo( 1, 0,"NoCopy" , "不可复制",0 ) );
1466     m_const_obj.push_back( new CSysCodeKindDataInfo( 1, 0,"OnlyOne" , "重复性检查",0 ) );
1467     m_const_obj.push_back( new CSysCodeKindDataInfo( 1, 0,"CheckQDZFile" , "检查QDZ是否存在",0 ) );
1468     m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "ParamChange", "参数是否可以修改", 0));
1469     m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "CalMethod", "计算方法", 0));
1470     m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "MaxMin", "去高去低", 0));
1471     m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "mb", "明标", 0));
1472     m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "ab", "暗标", 0));
1473     //m_const_obj.push_back(new CSysCodeKindDataInfo(1, 0, "Can", "去高去低", 0));
1474 };
1475 
1476 Cfyq_Interpreter::~Cfyq_Interpreter()
1477 {
1478     ClearVecPtr( m_name_obj  );
1479     ClearVecPtr( m_param_obj );
1480     ClearVecPtr( m_const_obj );
1481 };
1482 
1483 bool Cfyq_Interpreter::CheckName(  CString& title )
1484 {
1485     for( UINT i=0; i< m_name_obj.size(); i++ )
1486     {
1487         if( 0 == title.CompareNoCase( m_name_obj[i]->GetCode() ) )
1488         {
1489             return true;
1490         }
1491     }
1492     return false;
1493 };
1494 
1495 bool Cfyq_Interpreter::CheckParam( CString& title )
1496 {
1497     for( UINT i=0; i< m_param_obj.size(); i++ )
1498     {
1499         if( 0 == title.CompareNoCase( m_param_obj[i]->GetCode() ) )
1500         {
1501             return true;
1502         }
1503     }
1504     return false;    
1505 };
1506 
1507 bool Cfyq_Interpreter::CheckConst(CString& title)
1508 {
1509     for( UINT i=0; i< m_const_obj.size(); i++ )
1510     {
1511         if( 0 == title.CompareNoCase( m_const_obj[i]->GetCode() ) )
1512         {
1513             return true;
1514         }
1515     }
1516     return false;    
1517 }
1518 
1519 bool Cfyq_Interpreter::Interpreter(const CString& strFormula)
1520 {
1521     ClearVecPtr(m_vecExpression);
1522     m_strFormula = strFormula;
1523 
1524     m_nCurIndex = 0;
1525     m_pCurNode = CreateNode(FNK_Name);
1526     m_pCurName = (Cfyq_Name*)m_pCurNode;
1527     
1528     m_vecExpression.push_back(GetCurNode());
1529 
1530 
1531 
1532     if ( m_strFormula.IsEmpty())
1533         return false;
1534 
1535     m_strFormula.Trim();
1536     if(m_strFormula[m_strFormula.GetLength() - 1] != ';')
1537     {
1538         AfxMessageBox("表达式没有结束符!");
1539         return false;
1540     }
1541 
1542     for( m_nCurIndex=0; m_nCurIndex < m_strFormula.GetLength(); m_nCurIndex++  )
1543     {
1544         if( !push( m_strFormula[m_nCurIndex] ) )
1545         {
1546             CString strErrorMsg;
1547             strErrorMsg.Format("Error Index:%d ",m_nCurIndex);
1548             m_pCurNode->ErrorMsg(strErrorMsg);
1549             AfxMessageBox(strErrorMsg);
1550             return false;
1551         }
1552     };
1553 
1554     return true;
1555 }
1556 
1557 void Cfyq_Interpreter::backInterpreter(Cfyq_node* startName, CString& backstr)
1558 {
1559     startName->NextBackNode(startName, backstr, this, 0);
1560     pushback(startName, backstr);
1561     backstr += ";";
1562 }
1563 
1564 void Cfyq_Interpreter::pushback(Cfyq_node* startName, CString& backstr)
1565 {
1566     int len = startName->m_vecSubNode.size();
1567     if (!len)
1568     {
1569         return;
1570     }
1571     for (int i = 0; i < startName->m_vecSubNode.size(); ++i)
1572     {
1573         if (i == startName->m_vecSubNode.size() - 1)
1574             startName->m_vecSubNode[i]->NextBackNode(startName->m_vecSubNode[i], backstr, this, 1);
1575         else
1576             startName->m_vecSubNode[i]->NextBackNode(startName->m_vecSubNode[i], backstr, this, 0);
1577         pushback(startName->m_vecSubNode[i], backstr);
1578     }
1579 }
1580 
1581 bool Cfyq_Interpreter::push(char input)
1582 {
1583     Cfyq_node* pCurNode = GetCurNode();
1584     if( NULL == pCurNode)
1585         return false;
1586 
1587     switch( pCurNode->Accept( this, input ) )
1588     {
1589     case 1://可以接受
1590         return true;
1591     case 2://可以跳转
1592         return pCurNode->NextNode( this, input );
1593     case 3://忽略
1594         return true;
1595     default:
1596         return false;
1597     }
1598 }
1599 
1600 void Cfyq_Interpreter::ChangeNode(Cfyq_node* pNode)
1601 {
1602     m_vecExpression.push_back(pNode);
1603 
1604     if( FNK_Name == pNode->GetNodeGrade() )
1605         m_pCurName = (Cfyq_Name*)pNode;
1606 
1607     m_pCurNode = pNode;
1608 }
1609 
1610 void Cfyq_Interpreter::ChangeBackNode(Cfyq_node* pstate)
1611 {
1612     m_pCurBackNode = pstate;
1613 }
1614 
1615 bool Cfyq_Interpreter::IsTrueChar(char c)
1616 {
1617     if(('a'<=c && 'z'>=c) || 
1618         ('0'<=c && '9'>=c) ||
1619         ('A'<=c && 'Z'>=c) ||
1620         c == ' ' || c == '.')
1621     {
1622         return true;
1623     }
1624     return false;
1625 }
1626 
1627 bool Cfyq_Interpreter::IsChineseChar(char c)
1628 {
1629     if( c >= 0x80 || c<0 )
1630         return true;
1631 
1632     return false;
1633 }
1634 
1635 bool Cfyq_Interpreter::toString(CString& txt)
1636 {
1637 
1638     return true;
1639 }
1640 
1641 
1642 bool Cfyq_Interpreter::NextStrIs(const CString& str)
1643 {
1644     if(m_nCurIndex + 1 == m_strFormula.Find(str,m_nCurIndex))
1645         return true;
1646 
1647     return false;
1648 }
1649 
1650 bool Cfyq_Interpreter::NextStrIsIgnoreSpace(const CString& str)
1651 {
1652     if(0 == str.GetLength())
1653         return true;
1654     int n = 0;
1655     for(int index = m_nCurIndex+1; index<m_strFormula.GetLength(); index++)
1656     {
1657         if(m_strFormula.GetAt(index)==' ')
1658             continue;
1659         if(m_strFormula.GetAt(index)!=str.GetAt(n++))
1660             return false;
1661         if(n >= str.GetLength())
1662             return true;
1663     }
1664     return false;
1665 }
1666 
1667 bool Cfyq_Interpreter::LastStrIsIgnoreSpace(const CString& str)
1668 {
1669     if(0 == str.GetLength())
1670         return true;
1671     int n = str.GetLength()-1;
1672     for(int index = m_nCurIndex-1; index >= 0; index--)
1673     {
1674         if(m_strFormula.GetAt(index)==' ')
1675             continue;
1676         if(m_strFormula.GetAt(index)!=str.GetAt(n--))
1677             return false;
1678         if(n <= -1 )
1679             return true;
1680     }
1681     return false;
1682 }
1683 
1684 Cfyq_node* Cfyq_Interpreter::GetCurBackNode()
1685 {
1686     return m_pCurBackNode;
1687 }
1688 
1689 Cfyq_node* Cfyq_Interpreter::CreateNode(CFyq_NodeKind kind)
1690 {
1691     switch(kind)
1692     {
1693     case FNK_Name:
1694         return new Cfyq_Name();
1695     case FNK_Param:
1696         return new Cfyq_Param();
1697     case FNK_Scope:
1698         return new Cfyq_scope();
1699     case FNK_Const:
1700         return new Cfyq_const();
1701     case FNK_Value:
1702         return new Cfyq_Var();
1703     case FNK_Set:
1704         return new Cfyq_set();
1705     case FNK_Define:
1706         return new Cfyq_define();
1707     case FNK_Offset:
1708         return new Cfyq_offset();
1709     case FNK_Jzj:
1710         return new Cfyq_jzj();
1711     default:
1712         break;
1713     }
1714     return nullptr;
1715 }
1716 
1717 IMPLEMENT_SERIAL( Cfyq_Name, Cfyq_element, 0)
1718 
1719 int Cfyq_Name::Accept(Cfyq_Interpreter* pInterpreter, char input)
1720 {
1721     if( Cfyq_Interpreter::IsTrueChar( input ) )
1722         return AppendChar(pInterpreter, input);
1723 
1724     switch( input )
1725     {
1726     case ':':
1727     case '(':
1728     case '[':
1729     case '=':
1730         {
1731             return 2;
1732         }
1733     case '-':
1734         {
1735             if(pInterpreter->NextStrIs(">"))
1736                 return 2;
1737             else
1738                 return 0;
1739         }
1740     }
1741 
1742     return 0;
1743 }
1744 
1745 bool Cfyq_Name::NextNode(Cfyq_Interpreter* pInterpreter, char input)
1746 {
1747     if(!pInterpreter->CheckName(m_strContent))
1748     {
1749         return false;
1750     }
1751     switch( input )
1752     {
1753     case ':':
1754         {
1755             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Define));
1756             return true;
1757         }
1758     case '(':
1759         {
1760             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Param));
1761             return true;
1762         }
1763     case '[':
1764         {
1765             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Scope));
1766             return true;
1767         }
1768     case '=':
1769         {
1770             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Set));
1771             return true;
1772         }
1773     case '-':
1774         {
1775             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Offset));
1776             return true;
1777         }
1778     default:
1779         return false;
1780     }
1781     return false;
1782 }
1783 
1784 CString Cfyq_Name::GetParam()
1785 {
1786     return m_sParam;
1787 }
1788 
1789 void Cfyq_Name::SetParam(CString val)
1790 {
1791     m_sParam = val;
1792 }
1793 
1794 Cfyq_scope* Cfyq_Name::GetScope()
1795 {
1796     return m_pScope;
1797 }
1798 
1799 Cfyq_Name::Cfyq_Name()
1800 {
1801     m_bcanSerial = 0;
1802     m_bcanSerialjzj = 0;
1803     m_pScope = NULL;
1804     m_pjzj = NULL;
1805     m_sParam = "";
1806 }
1807 
1808 Cfyq_Name::~Cfyq_Name()
1809 {
1810 
1811 }
1812 
1813 void Cfyq_Name::SetScope(Cfyq_scope* val)
1814 {
1815     m_pScope = val;
1816     m_bcanSerial = 1;
1817 }
1818 
1819 void Cfyq_Name::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
1820 {
1821     CString strTemp;
1822     str += m_strContent;
1823     if (!m_sParam.IsEmpty())
1824     {
1825         strTemp.Format("(%s)", m_sParam);
1826         str += strTemp;
1827     }
1828     if (m_pScope)
1829     {
1830         strTemp.Format("[%s]", m_pScope->m_strContent);
1831         str += strTemp;
1832     }
1833     if (m_pjzj)
1834     {
1835         strTemp.Format("{%s}", m_pjzj->m_strContent);
1836         str += strTemp;
1837     }
1838     pInterpreter->ChangeBackNode(node);
1839 }
1840 
1841 Cfyq_jzj* Cfyq_Name::Getjzj() const
1842 {
1843     return m_pjzj;
1844 }
1845 
1846 void Cfyq_Name::Setjzj(Cfyq_jzj* jzj)
1847 {
1848     m_bcanSerialjzj = 1;
1849     m_pjzj = jzj;
1850 }
1851 
1852 void Cfyq_Name::ErrorMsg(CString& str)
1853 {
1854     CString strTmp = "名字出现错误!\n";
1855     str += strTmp;
1856 }
1857 
1858 CFyq_NodeKind Cfyq_Name::GetNodeGrade()
1859 {
1860     return FNK_Name;
1861 }
1862 
1863 void Cfyq_Name::Serialize(CArchive& ar)
1864 {
1865     Cfyq_node::Serialize(ar);
1866     
1867     int rightcode = 1;
1868     if(ar.IsStoring())
1869     {
1870         ar << rightcode;
1871         ar << m_sParam;
1872         ar << m_bcanSerial;
1873         if(m_bcanSerial)
1874             m_pScope->Serialize(ar);
1875     }
1876     else 
1877     {
1878         ar >> rightcode;
1879         ar >> m_sParam;
1880         ar >> m_bcanSerial;
1881         if(m_bcanSerial)
1882         {
1883             m_pScope = new Cfyq_scope();
1884             m_pScope->Serialize(ar);
1885         }
1886     }
1887 }
1888 
1889 IMPLEMENT_SERIAL( Cfyq_Param, Cfyq_element, 0)
1890 
1891 bool Cfyq_Param::SetParamToName(Cfyq_Interpreter* pInterpreter)
1892 {
1893     pInterpreter->GetCurName()->SetParam(m_strContent);
1894     return true;
1895 }
1896 
1897 int Cfyq_Param::Accept(Cfyq_Interpreter* pInterpreter, char input)
1898 {
1899     if( Cfyq_Interpreter::IsTrueChar( input ) )
1900         return AppendChar(pInterpreter, input);
1901 
1902     switch( input )
1903     {
1904     case '[':
1905         {
1906             return 2;        
1907         }
1908     case '=':
1909         {
1910             return 2;
1911         }
1912     case ')':
1913         {
1914             SetClose(true);//闭合
1915             if(pInterpreter->NextStrIsIgnoreSpace("[")||pInterpreter->NextStrIsIgnoreSpace("="))
1916                 return 3;
1917             else 
1918                 return 0;    
1919         }
1920     }
1921 
1922     return 0;
1923 }
1924 
1925 bool Cfyq_Param::NextNode(Cfyq_Interpreter* pInterpreter, char input)
1926 {
1927     if(!IsClose())
1928         return false;
1929     if(pInterpreter->CheckParam(m_strContent))
1930         SetParamToName(pInterpreter);
1931     else
1932         return false;
1933 
1934     switch( input )
1935     {
1936     case '[':
1937         {
1938             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Scope));
1939             return true;
1940         }
1941     case '=':
1942         {
1943             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Set));
1944             return true;
1945         }
1946     default:
1947         return false;
1948     }
1949     return false;
1950 }
1951 
1952 CFyq_NodeKind Cfyq_Param::GetNodeGrade()
1953 {
1954     return FNK_Param;
1955 }
1956 
1957 void Cfyq_Param::ErrorMsg(CString& str)
1958 {
1959     CString strTmp = "参数出现错误!\n";
1960     str += strTmp;
1961 }
1962 
1963 Cfyq_Param::Cfyq_Param()
1964 {
1965 
1966 }
1967 
1968 void Cfyq_Param::Serialize(CArchive& ar)
1969 {
1970     Cfyq_node::Serialize(ar);
1971     int rightcode = 1;
1972     if(ar.IsStoring())
1973     {
1974         ar << rightcode;
1975     }
1976     else 
1977     {
1978         ar >> rightcode;
1979     }
1980 }
1981 
1982 IMPLEMENT_SERIAL( Cfyq_set, Cfyq_opt, 0)
1983 
1984 int Cfyq_set::Accept(Cfyq_Interpreter* pInterpreter, char input)
1985 {
1986     if(input == ' ')
1987         return 3;
1988     if( Cfyq_Interpreter::IsTrueChar( input ) )
1989         return 2;
1990 
1991     return 0;
1992 }
1993 
1994 bool Cfyq_set::NextNode(Cfyq_Interpreter* pInterpreter, char input)
1995 {
1996     pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Name));
1997     pInterpreter->GetCurNode()->m_strContent.AppendChar(input);
1998     pInterpreter->GetCurNode()->m_bStateInputChar = true;
1999     return true;
2000 }
2001 
2002 
2003 void Cfyq_set::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
2004 {
2005     str += "=";
2006     pInterpreter->ChangeBackNode(node);
2007 }
2008 
2009 CFyq_NodeKind Cfyq_set::GetNodeGrade()
2010 {
2011     return FNK_Set;
2012 }
2013 
2014 Cfyq_set::Cfyq_set()
2015 {
2016 
2017 }
2018 
2019 Cfyq_set::~Cfyq_set()
2020 {
2021 
2022 }
2023 
2024 void Cfyq_set::Serialize(CArchive& ar)
2025 {
2026     int rightcode = 1;
2027     Cfyq_node::Serialize(ar);
2028     if( ar.IsStoring() )
2029     { 
2030         ar << rightcode;
2031     }
2032     else
2033     {
2034         ar >> rightcode;
2035     }
2036 }
2037 
2038 IMPLEMENT_SERIAL( Cfyq_define, Cfyq_opt, 0)
2039 
2040 int Cfyq_define::Accept(Cfyq_Interpreter* pInterpreter, char input)
2041 {
2042     if(input == ' ')
2043         return 3;
2044     if( Cfyq_Interpreter::IsTrueChar( input ) )
2045         return 2;
2046 
2047     return 0;
2048 }
2049 
2050 bool Cfyq_define::NextNode(Cfyq_Interpreter* pInterpreter, char input)
2051 {
2052     pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Const));
2053     pInterpreter->GetCurNode()->m_strContent.AppendChar(input);
2054     pInterpreter->GetCurNode()->m_bStateInputChar = true;
2055     return true;
2056 }
2057 
2058 CFyq_NodeKind Cfyq_define::GetNodeGrade()
2059 {
2060     return FNK_Define;
2061 }
2062 
2063 void Cfyq_define::NextBackNode(Cfyq_node* node, CString& str, Cfyq_Interpreter* pInterpreter, bool bLast)
2064 {
2065     str += ":";
2066     pInterpreter->ChangeBackNode(node);
2067 }
2068 
2069 Cfyq_define::Cfyq_define()
2070 {
2071 
2072 }
2073 
2074 
2075 void Cfyq_define::Serialize(CArchive& ar)
2076 {
2077     int rightcode = 1;
2078     Cfyq_node::Serialize(ar);
2079     if( ar.IsStoring() )
2080     { 
2081         ar << rightcode;
2082     }
2083     else
2084     {
2085         ar >> rightcode;
2086     }
2087 }
2088 
2089 IMPLEMENT_SERIAL( Cfyq_element, Cfyq_node, 0)
2090 Cfyq_element::Cfyq_element() : m_bIsCloseFlag(false)
2091 {
2092 
2093 }
2094 
2095 bool Cfyq_element::IsClose()
2096 {
2097     return m_bIsCloseFlag;
2098 }
2099 
2100 void Cfyq_element::SetClose(bool val)
2101 {
2102     m_bIsCloseFlag = val;
2103 }
2104 
2105 int Cfyq_element::AppendChar(Cfyq_Interpreter* pInterpreter, char input)
2106 {
2107     //进入字符状态
2108     if(m_bStateInputChar)
2109     {
2110         if(input==' ')
2111             m_bStateInputChar = false;
2112         else
2113         {
2114             m_strContent += input;
2115             return 1;
2116         }
2117     }
2118     //非字符状态
2119     else
2120     {
2121         if(input != ' ')
2122         {
2123             if(m_strContent.GetLength() == 0)
2124             {
2125                 m_bStateInputChar = true;
2126                 m_strContent += input;
2127                 return 1;
2128             }
2129             else
2130                 return 0;
2131         }
2132     }
2133     return 3;
2134 }
2135 
2136 void Cfyq_element::Serialize(CArchive& ar)
2137 {
2138     int rightcode = 1;
2139     if(ar.IsStoring())
2140     {
2141         ar << rightcode;
2142     }
2143     else
2144     {
2145         ar >> rightcode;
2146     }
2147 }
2148 IMPLEMENT_SERIAL( Cfyq_jzj, Cfyq_element, 0)
2149 
2150 
2151 Cfyq_jzj::Cfyq_jzj()
2152 {
2153     m_nkind = -1;
2154     m_strContent = "";
2155 }
2156 
2157 Cfyq_jzj::~Cfyq_jzj()
2158 {
2159 
2160 }
2161 
2162 void Cfyq_jzj::Serialize(CArchive& ar)
2163 {
2164     Cfyq_node::Serialize( ar );
2165     int rightcode = 1; 
2166     if( ar.IsStoring() )
2167     {
2168         ar << rightcode;
2169     }
2170     else
2171     {
2172         ar >> rightcode;
2173     }
2174 }
2175 
2176 bool Cfyq_jzj::SetjzjToName(Cfyq_Interpreter* pInterpreter)
2177 {
2178     pInterpreter->GetCurName()->Setjzj(this);
2179     return true;
2180 }
2181 
2182 int Cfyq_jzj::Accept(Cfyq_Interpreter* pInterpreter, char input)
2183 {
2184     if( Cfyq_Interpreter::IsTrueChar( input ) )
2185         return AppendChar(pInterpreter, input);
2186     switch( input )
2187     {
2188     case '}':
2189         {
2190             SetClose(true);
2191             if(pInterpreter->NextStrIsIgnoreSpace("->"))
2192                 return 3;
2193             else
2194                 return 0;
2195         }
2196     case '-':
2197         {
2198             if(pInterpreter->NextStrIs(">"))
2199                 return 2;
2200             m_strContent += input;
2201             return 1;
2202         }
2203     }
2204 
2205     return 0;
2206 }
2207 
2208 bool Cfyq_jzj::NextNode(Cfyq_Interpreter* pInterpreter, char input)
2209 {
2210     if(!IsClose())
2211         return false;
2212     else
2213         SetjzjToName(pInterpreter);
2214     switch( input )
2215     {
2216     case '-':
2217         {
2218             pInterpreter->ChangeNode(pInterpreter->CreateNode(FNK_Offset));
2219             return true;
2220         }
2221     default:
2222         return false;
2223     }
2224 }
2225 
2226 CFyq_NodeKind Cfyq_jzj::GetNodeGrade()
2227 {
2228     return FNK_Jzj;
2229 }
posted @ 2019-12-22 14:32  冷眼旁观你的泪  阅读(704)  评论(0编辑  收藏  举报