Skip to content

Commit

Permalink
提交修改
Browse files Browse the repository at this point in the history
  • Loading branch information
toolgood committed Jan 24, 2022
1 parent 2cf19ba commit 87c61d3
Show file tree
Hide file tree
Showing 33 changed files with 18,775 additions and 19,172 deletions.
71 changes: 36 additions & 35 deletions csharp/ToolGood.Algorithm2.MathParserReplace/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@ static void Main(string[] args)
var str = @"T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17,
T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24,
T__24=25, SUB=26, NUM=27, STRING=28, NULL=29, IF=30, IFERROR=31, ISNUMBER=32,
ISTEXT=33, ISERROR=34, ISNONTEXT=35, ISLOGICAL=36, ISEVEN=37, ISODD=38,
ISNULL=39, ISNULLORERROR=40, AND=41, OR=42, NOT=43, TRUE=44, FALSE=45,
E=46, PI=47, DEC2BIN=48, DEC2HEX=49, DEC2OCT=50, HEX2BIN=51, HEX2DEC=52,
HEX2OCT=53, OCT2BIN=54, OCT2DEC=55, OCT2HEX=56, BIN2OCT=57, BIN2DEC=58,
BIN2HEX=59, ABS=60, QUOTIENT=61, MOD=62, SIGN=63, SQRT=64, TRUNC=65, INT=66,
GCD=67, LCM=68, COMBIN=69, PERMUT=70, DEGREES=71, RADIANS=72, COS=73,
COSH=74, SIN=75, SINH=76, TAN=77, TANH=78, ACOS=79, ACOSH=80, ASIN=81,
ASINH=82, ATAN=83, ATANH=84, ATAN2=85, ROUND=86, ROUNDDOWN=87, ROUNDUP=88,
CEILING=89, FLOOR=90, EVEN=91, ODD=92, MROUND=93, RAND=94, RANDBETWEEN=95,
FACT=96, FACTDOUBLE=97, POWER=98, EXP=99, LN=100, LOG=101, LOG10=102,
MULTINOMIAL=103, PRODUCT=104, SQRTPI=105, SUMSQ=106, ASC=107, JIS=108,
CHAR=109, CLEAN=110, CODE=111, CONCATENATE=112, EXACT=113, FIND=114, FIXED=115,
LEFT=116, LEN=117, LOWER=118, MID=119, PROPER=120, REPLACE=121, REPT=122,
RIGHT=123, RMB=124, SEARCH=125, SUBSTITUTE=126, T=127, TEXT=128, TRIM=129,
UPPER=130, VALUE=131, DATEVALUE=132, TIMEVALUE=133, DATE=134, TIME=135,
NOW=136, TODAY=137, YEAR=138, MONTH=139, DAY=140, HOUR=141, MINUTE=142,
SECOND=143, WEEKDAY=144, DATEDIF=145, DAYS360=146, EDATE=147, EOMONTH=148,
NETWORKDAYS=149, WORKDAY=150, WEEKNUM=151, MAX=152, MEDIAN=153, MIN=154,
QUARTILE=155, MODE=156, LARGE=157, SMALL=158, PERCENTILE=159, PERCENTRANK=160,
AVERAGE=161, AVERAGEIF=162, GEOMEAN=163, HARMEAN=164, COUNT=165, COUNTIF=166,
SUM=167, SUMIF=168, AVEDEV=169, STDEV=170, STDEVP=171, DEVSQ=172, VAR=173,
VARP=174, NORMDIST=175, NORMINV=176, NORMSDIST=177, NORMSINV=178, BETADIST=179,
BETAINV=180, BINOMDIST=181, EXPONDIST=182, FDIST=183, FINV=184, FISHER=185,
FISHERINV=186, GAMMADIST=187, GAMMAINV=188, GAMMALN=189, HYPGEOMDIST=190,
LOGINV=191, LOGNORMDIST=192, NEGBINOMDIST=193, POISSON=194, TDIST=195,
TINV=196, WEIBULL=197, URLENCODE=198, URLDECODE=199, HTMLENCODE=200, HTMLDECODE=201,
BASE64TOTEXT=202, BASE64URLTOTEXT=203, TEXTTOBASE64=204, TEXTTOBASE64URL=205,
REGEX=206, REGEXREPALCE=207, ISREGEX=208, GUID=209, MD5=210, SHA1=211,
SHA256=212, SHA512=213, CRC32=214, HMACMD5=215, HMACSHA1=216, HMACSHA256=217,
HMACSHA512=218, TRIMSTART=219, TRIMEND=220, INDEXOF=221, LASTINDEXOF=222,
SPLIT=223, JOIN=224, SUBSTRING=225, STARTSWITH=226, ENDSWITH=227, ISNULLOREMPTY=228,
ISNULLORWHITESPACE=229, REMOVESTART=230, REMOVEEND=231, JSON=232, VLOOKUP=233,
LOOKUP=234, ARRAY=235, PARAMETER=236, PARAMETER2=237, WS=238;
T__24=25, T__25=26, SUB=27, NUM=28, STRING=29, NULL=30, IF=31, IFERROR=32,
ISNUMBER=33, ISTEXT=34, ISERROR=35, ISNONTEXT=36, ISLOGICAL=37, ISEVEN=38,
ISODD=39, ISNULL=40, ISNULLORERROR=41, AND=42, OR=43, NOT=44, TRUE=45,
FALSE=46, E=47, PI=48, DEC2BIN=49, DEC2HEX=50, DEC2OCT=51, HEX2BIN=52,
HEX2DEC=53, HEX2OCT=54, OCT2BIN=55, OCT2DEC=56, OCT2HEX=57, BIN2OCT=58,
BIN2DEC=59, BIN2HEX=60, ABS=61, QUOTIENT=62, MOD=63, SIGN=64, SQRT=65,
TRUNC=66, INT=67, GCD=68, LCM=69, COMBIN=70, PERMUT=71, DEGREES=72, RADIANS=73,
COS=74, COSH=75, SIN=76, SINH=77, TAN=78, TANH=79, ACOS=80, ACOSH=81,
ASIN=82, ASINH=83, ATAN=84, ATANH=85, ATAN2=86, ROUND=87, ROUNDDOWN=88,
ROUNDUP=89, CEILING=90, FLOOR=91, EVEN=92, ODD=93, MROUND=94, RAND=95,
RANDBETWEEN=96, FACT=97, FACTDOUBLE=98, POWER=99, EXP=100, LN=101, LOG=102,
LOG10=103, MULTINOMIAL=104, PRODUCT=105, SQRTPI=106, SUMSQ=107, ASC=108,
JIS=109, CHAR=110, CLEAN=111, CODE=112, CONCATENATE=113, EXACT=114, FIND=115,
FIXED=116, LEFT=117, LEN=118, LOWER=119, MID=120, PROPER=121, REPLACE=122,
REPT=123, RIGHT=124, RMB=125, SEARCH=126, SUBSTITUTE=127, T=128, TEXT=129,
TRIM=130, UPPER=131, VALUE=132, DATEVALUE=133, TIMEVALUE=134, DATE=135,
TIME=136, NOW=137, TODAY=138, YEAR=139, MONTH=140, DAY=141, HOUR=142,
MINUTE=143, SECOND=144, WEEKDAY=145, DATEDIF=146, DAYS360=147, EDATE=148,
EOMONTH=149, NETWORKDAYS=150, WORKDAY=151, WEEKNUM=152, MAX=153, MEDIAN=154,
MIN=155, QUARTILE=156, MODE=157, LARGE=158, SMALL=159, PERCENTILE=160,
PERCENTRANK=161, AVERAGE=162, AVERAGEIF=163, GEOMEAN=164, HARMEAN=165,
COUNT=166, COUNTIF=167, SUM=168, SUMIF=169, AVEDEV=170, STDEV=171, STDEVP=172,
DEVSQ=173, VAR=174, VARP=175, NORMDIST=176, NORMINV=177, NORMSDIST=178,
NORMSINV=179, BETADIST=180, BETAINV=181, BINOMDIST=182, EXPONDIST=183,
FDIST=184, FINV=185, FISHER=186, FISHERINV=187, GAMMADIST=188, GAMMAINV=189,
GAMMALN=190, HYPGEOMDIST=191, LOGINV=192, LOGNORMDIST=193, NEGBINOMDIST=194,
POISSON=195, TDIST=196, TINV=197, WEIBULL=198, URLENCODE=199, URLDECODE=200,
HTMLENCODE=201, HTMLDECODE=202, BASE64TOTEXT=203, BASE64URLTOTEXT=204,
TEXTTOBASE64=205, TEXTTOBASE64URL=206, REGEX=207, REGEXREPALCE=208, ISREGEX=209,
GUID=210, MD5=211, SHA1=212, SHA256=213, SHA512=214, CRC32=215, HMACMD5=216,
HMACSHA1=217, HMACSHA256=218, HMACSHA512=219, TRIMSTART=220, TRIMEND=221,
INDEXOF=222, LASTINDEXOF=223, SPLIT=224, JOIN=225, SUBSTRING=226, STARTSWITH=227,
ENDSWITH=228, ISNULLOREMPTY=229, ISNULLORWHITESPACE=230, REMOVESTART=231,
REMOVEEND=232, JSON=233, VLOOKUP=234, LOOKUP=235, ARRAY=236, PARAMETER=237,
PARAMETER2=238, WS=239, COMMENT=240, LINE_COMMENT=241;
RULE_prog=0, RULE_expr=1, RULE_expr2=2, RULE_parameter2=3;
RULE_prog=0, RULE_expr=1, RULE_expr2=2, RULE_parameter2=2;
";
var array = str.Split(" ,\r\n\t;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> dict = new Dictionary<string, string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@ public void base_test2()

}

[Test]
public void base_test3()
{
AlgorithmEngine engine = new AlgorithmEngine();

var c = engine.TryEvaluate("(2)+/*123456*/3", 0);
Assert.AreEqual(5, c);

c = engine.TryEvaluate("2+3//eee", 0);
Assert.AreEqual(5, c);

c = engine.TryEvaluate("(2)+/*123456*/3 ee22+22", 0);
Assert.AreEqual(0, c);
}

[Test]
public void base_test4()
{
AlgorithmEngine engine = new AlgorithmEngine();

String c = engine.TryEvaluate("'4dd'&'55' rr", "");
Assert.AreEqual("", c);

}

[Test]
public void base_test5()
{
AlgorithmEngine engine = new AlgorithmEngine();

String c = engine.TryEvaluate("'4dd'&'55'.left(1)", "");
Assert.AreEqual("4dd5", c);

}


[Test]
public void Cylinder_Test()
{
Expand Down
7 changes: 6 additions & 1 deletion csharp/ToolGood.Algorithm2.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class Program
static void Main(string[] args)
{
AlgorithmEngine engine = new AlgorithmEngine();




double a = 0.0;
if (engine.Parse("1+2")) {
var o = engine.Evaluate();
a = o.NumberValue;
}

var b = engine.TryEvaluate("1=1 && 1<2 and 7-8>1", 0);// Support(支持) && || and or
var c = engine.TryEvaluate("2+3", 0);
var d = engine.TryEvaluate("count(array(1,2,3,4))", 0);//{} represents array, return: 4 {}代表数组,返回:4
Expand All @@ -27,7 +32,7 @@ static void Main(string[] args)
var k = engine.TryEvaluate("json('{\"Name\":\"William Shakespeare \",\"Age\":51,\"Birthday\":\"04/26/1564 00:00:00\"}')[Name].Trim()", null);//Return to "William Shakespeare" 返回"William Shakespeare" (不带空格)
var l = engine.TryEvaluate("json('{\"Name1\":\"William Shakespeare \",\"Age\":51,\"Birthday\":\"04/26/1564 00:00:00\"}')['Name'& 1].Trim().substring(2,3)", null); ;//Return "ill" 返回"ill"



Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
Expand Down
6 changes: 0 additions & 6 deletions csharp/ToolGood.Algorithm2/AlgorithmEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,6 @@ public bool Parse(string exp)
parser.AddErrorListener(antlrErrorListener);

var context = parser.prog();
var end = context.Stop.StopIndex;
if (end + 1 < exp.Length) {
_context = null;
LastError = "Parameter exp invalid !";
return false;
}
if (antlrErrorListener.IsError) {
_context = null;
LastError = antlrErrorListener.ErrorMsg;
Expand Down
6 changes: 0 additions & 6 deletions csharp/ToolGood.Algorithm2/AlgorithmEngineEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,6 @@ private ProgContext Parse(string exp)
parser.AddErrorListener(antlrErrorListener);

var context = parser.prog();
var end = context.Stop.StopIndex;
if (end + 1 < exp.Length) {

LastError = "Parameter exp invalid !";
return null;
}
if (antlrErrorListener.IsError) {
LastError = antlrErrorListener.ErrorMsg;
return null;
Expand Down
5 changes: 1 addition & 4 deletions csharp/ToolGood.Algorithm2/AlgorithmEngineHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Antlr4.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using ToolGood.Algorithm.Internals;

namespace ToolGood.Algorithm
Expand Down Expand Up @@ -265,10 +266,6 @@ public DiyNameInfo GetDiyNames(String exp)
parser.AddErrorListener(antlrErrorListener);

var context = parser.prog();
var end = context.Stop.StopIndex;
if (end + 1 < exp.Length) {
throw new Exception("Parameter exp invalid !");
}
if (antlrErrorListener.IsError) {
throw new Exception(antlrErrorListener.ErrorMsg);
}
Expand Down
6 changes: 1 addition & 5 deletions csharp/ToolGood.Algorithm2/ConditionCache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Antlr4.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using ToolGood.Algorithm.Internals;
using static mathParser;

Expand Down Expand Up @@ -130,11 +131,6 @@ private ProgContext Parse(string exp)
parser.AddErrorListener(antlrErrorListener);

var context = parser.prog();
var end = context.Stop.StopIndex;
if (end + 1 < exp.Length) {
LastError = "Parameter exp invalid !";
return null;
}
if (antlrErrorListener.IsError) {
LastError = antlrErrorListener.ErrorMsg;
return null;
Expand Down
7 changes: 1 addition & 6 deletions csharp/ToolGood.Algorithm2/Internals/ConditionCacheInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Antlr4.Runtime;
using System;
using System.Linq;
using static mathParser;

namespace ToolGood.Algorithm.Internals
Expand Down Expand Up @@ -51,12 +52,6 @@ private ProgContext Parse(string exp)
parser.AddErrorListener(antlrErrorListener);

var context = parser.prog();
var end = context.Stop.StopIndex;
if (end + 1 < exp.Length) {

LastError = "Parameter exp invalid !";
return null;
}
if (antlrErrorListener.IsError) {
LastError = antlrErrorListener.ErrorMsg;
return null;
Expand Down
7 changes: 0 additions & 7 deletions csharp/ToolGood.Algorithm2/Internals/DiyNameVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Antlr4.Runtime.Tree;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ToolGood.Algorithm.Internals
{
Expand Down Expand Up @@ -752,10 +749,6 @@ public object VisitOR_fun(mathParser.OR_funContext context)
return VisitChildren(context);
}

public object VisitParameter(mathParser.ParameterContext context)
{
return VisitChildren(context);
}

public object VisitParameter2(mathParser.Parameter2Context context)
{
Expand Down
19 changes: 5 additions & 14 deletions csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using System;
using Antlr4.Runtime.Tree;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Antlr4.Runtime.Tree;
using ToolGood.Algorithm.Internals;
using ToolGood.Algorithm.LitJson;
using ToolGood.Algorithm.MathNet.Numerics;

namespace ToolGood.Algorithm.Internals
{
class MathVisitor : AbstractParseTreeVisitor<Operand>, ImathVisitor<Operand>
{
private static readonly Regex sumifRegex = new Regex(@"(<|<=|>|>=|=|==|!=|<>) *([-+]?\d+(\.(\d+)?)?)", RegexOptions.Compiled);
private static readonly Regex sumifRegex = new Regex(@"(<|<=|>|>=|=|==|===|!=|!==|<>) *([-+]?\d+(\.(\d+)?)?)", RegexOptions.Compiled);
private static readonly Regex bit_2 = new Regex("^[01]+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex bit_8 = new Regex("^[0-8]+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex bit_16 = new Regex("^[0-9a-f]+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
Expand All @@ -29,7 +28,7 @@ class MathVisitor : AbstractParseTreeVisitor<Operand>, ImathVisitor<Operand>

public Operand VisitProg(mathParser.ProgContext context)
{
return VisitChildren(context);
return Visit(context.expr());
}

public Operand VisitMulDiv_fun(mathParser.MulDiv_funContext context)
Expand Down Expand Up @@ -206,7 +205,7 @@ public Operand VisitJudge_fun(mathParser.Judge_funContext context)
if (firstValue.IsNull) {
if (secondValue.IsNull && CharUtil.Equals(type, "=", "==", "===")) {
return Operand.True;
} else if (secondValue.IsNull == false && CharUtil.Equals(type, "<>", "!=")) {
} else if (secondValue.IsNull == false && CharUtil.Equals(type, "<>", "!=","!==")) {
return Operand.True;
}
return Operand.False;
Expand Down Expand Up @@ -3825,14 +3824,6 @@ public Operand VisitPARAMETER_fun(mathParser.PARAMETER_funContext context)
return Operand.Error("Function PARAMETER first parameter is error!");
}

public Operand VisitParameter(mathParser.ParameterContext context)
{
var expr = context.expr();
if (expr != null) {
return this.Visit(expr);
}
return this.Visit(context.parameter2());
}

public Operand VisitParameter2(mathParser.Parameter2Context context)
{
Expand Down
2 changes: 1 addition & 1 deletion csharp/ToolGood.Algorithm2/ToolGood.Algorithm2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Product>ToolGood.Algorithm</Product>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<SignAssembly>true</SignAssembly>
<Version>3.0.2.0</Version>
<Version>3.0.3.0</Version>
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>
Expand Down
Loading

0 comments on commit 87c61d3

Please sign in to comment.