@@ -11,6 +11,7 @@ public partial class AlgorithmEngine
1111 {
1212 private Random rand ;
1313 private List < string > m_Operators = new List < string > ( ) { "." , "(" , ")" , "!" , "*" , "/" , "%" , "+" , "-" , "<" , ">" , "=" , "&" , "|" , "," , "==" , "!=" , ">=" , "<=" , "<>" , "@" } ;
14+ private List < string > m_Operators2 = new List < string > ( ) { "<" , ">" , "=" , "==" , "!=" , ">=" , "<=" , "<>" } ;
1415 private List < object > m_tokens = new List < object > ( ) ; //最终逆波兰式堆栈
1516 private Dictionary < string , List < object > > tokenDict = new Dictionary < string , List < object > > ( ) ;
1617 private Dictionary < string , Func < List < Operand > , Operand > > funcDict = new Dictionary < string , Func < List < Operand > , Operand > > ( ) ;
@@ -178,7 +179,7 @@ private List<object> parse(string exp)
178179
179180 while ( curPos < texts . Count ) {
180181 //获取 当前操作数
181- curOpd = getOperand ( texts , curPos ) ;
182+ curOpd = getOperand ( texts , ref curPos ) ;
182183 if ( curOpd != "" ) {
183184 if ( operators . Count > 0 && hasPoint ) {
184185 Operator op = operators . Pop ( ) ;
@@ -240,6 +241,24 @@ private List<object> parse(string exp)
240241 continue ;
241242 }
242243
244+ //if (optType== OperatorType.SUB &&( operators.Peek().Type== OperatorType.LT || operators.Peek().Type == OperatorType.LE
245+ // || operators.Peek().Type== OperatorType.GT || operators.Peek().Type == OperatorType.GE
246+ // || operators.Peek().Type == OperatorType.ET || operators.Peek().Type == OperatorType.UT
247+ // )) {
248+ // while (operators.Count > 0) {
249+ // if (Operator.ComparePriority(optType, operators.Peek().Type) <= 0 && operators.Peek().Type != OperatorType.LB) {
250+ // operands.Add(operators.Pop());
251+
252+ // if (operators.Count == 0) {
253+ // operators.Push(new Operator(optType, curOpt, funcCount));
254+ // break;
255+ // }
256+ // } else {
257+ // operators.Push(new Operator(optType, curOpt, funcCount));
258+ // break;
259+ // }
260+ // }
261+ //} else
243262 //若当前运算符优先级大于运算符栈顶的运算符,则将当前运算符直接存入运算符堆栈.
244263 if ( Operator . ComparePriority ( optType , operators . Peek ( ) . Type ) > 0 ) {
245264 operators . Push ( new Operator ( optType , curOpt , funcCount ) ) ;
@@ -288,7 +307,7 @@ private int getFunctionCount(List<string> texts, int curPos)
288307 }
289308 return count + hasCount ;
290309 }
291- private string getOperand ( List < string > texts , int curPos )
310+ private string getOperand ( List < string > texts , ref int curPos )
292311 {
293312 var t = texts [ curPos ] ;
294313 if ( t . StartsWith ( "[" ) ) {
@@ -300,6 +319,15 @@ private string getOperand(List<string> texts, int curPos)
300319 return "" ;
301320 }
302321 }
322+ if ( curPos > 0 && t == "-" && curPos + 1 < texts . Count ) {
323+ if ( m_Operators2 . Contains ( texts [ curPos - 1 ] ) ) {
324+ curPos ++ ;
325+ return t + texts [ curPos ] ;
326+ }
327+ }
328+
329+
330+
303331 if ( m_Operators . Contains ( t . ToLower ( ) ) ) {
304332 return "" ;
305333 }
@@ -588,7 +616,7 @@ private object evaluate(List<object> tokens)
588616 list . Insert ( 0 , opds . Pop ( ) ) ;
589617 list . Insert ( 0 , opds . Pop ( ) ) ;
590618 opds . Push ( getChild ( list ) ) ;
591- break ;
619+ break ;
592620 #endregion
593621
594622 #region 乘,*,multiplication
0 commit comments