11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Linq ;
5+ using System . Text ;
46using Antlr4 . Runtime ;
57using Antlr4 . Runtime . Misc ;
68using ToolGood . Algorithm . Internals ;
@@ -23,7 +25,7 @@ public class AlgorithmEngine
2325 /// </summary>
2426 public string LastError { get ; private set ; }
2527 private ProgContext _context ;
26- private Dictionary < string , Operand > _dict = new Dictionary < string , Operand > ( ) ;
28+ protected Dictionary < string , Operand > _dict = new Dictionary < string , Operand > ( ) ;
2729 /// <summary>
2830 /// 自定义 函数
2931 /// </summary>
@@ -698,5 +700,44 @@ public MyDate TryEvaluate_MyDate(string exp, MyDate def)
698700 }
699701 #endregion
700702
703+ #region EvaluateFormula
704+ /// <summary>
705+ /// 计算公式
706+ /// </summary>
707+ /// <param name="formula">公式</param>
708+ /// <param name="splitChars">分隔符</param>
709+ /// <returns></returns>
710+ public String EvaluateFormula ( String formula , params char [ ] splitChars )
711+ {
712+ if ( string . IsNullOrEmpty ( formula ) ) return "" ;
713+ return EvaluateFormula ( formula , splitChars . ToList ( ) ) ;
714+ }
715+ /// <summary>
716+ /// 计算公式
717+ /// </summary>
718+ /// <param name="formula">公式</param>
719+ /// <param name="splitChars">分隔符</param>
720+ /// <returns></returns>
721+ public String EvaluateFormula ( String formula , List < char > splitChars )
722+ {
723+ if ( string . IsNullOrEmpty ( formula ) ) return "" ;
724+
725+ List < String > sp = CharUtil . SplitFormula ( formula , splitChars ) ;
726+
727+ StringBuilder stringBuilder = new StringBuilder ( ) ;
728+ for ( int i = 0 ; i < sp . Count ; i ++ ) {
729+ String s = sp [ i ] ;
730+ if ( s . Length == 1 && splitChars . Contains ( s [ 0 ] ) ) {
731+ stringBuilder . Append ( s ) ;
732+ } else {
733+ // TODO 替换此处
734+ String d = TryEvaluate ( s , "" ) ;
735+ stringBuilder . Append ( d . ToString ( ) ) ;
736+ }
737+ }
738+ return stringBuilder . ToString ( ) ;
739+ }
740+ #endregion
741+
701742 }
702743}
0 commit comments