Skip to content

Commit 5518bd1

Browse files
author
lzj
committed
修改
1 parent 606db84 commit 5518bd1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ public Operand VisitMulDiv_fun(mathParser.MulDiv_funContext context)
7878
if (secondValue.IsError) { return secondValue; }
7979
return Operand.Create(firstValue.NumberValue * secondValue.NumberValue);
8080
} else if (t == "/") {
81-
secondValue = secondValue.ToNumber("Div fun right value");
82-
if (secondValue.NumberValue == 0) {
83-
return Operand.Error($"Function '{t}' parameter 2 is error!");
84-
}
8581
if (firstValue.Type == OperandType.STRING) {
8682
var a = firstValue.ToDate(null);
8783
if (a.IsError == false) firstValue = a;
@@ -92,8 +88,12 @@ public Operand VisitMulDiv_fun(mathParser.MulDiv_funContext context)
9288

9389
firstValue = firstValue.ToNumber($"Function '{t}' parameter 1 is error!");
9490
if (firstValue.IsError) { return firstValue; }
95-
secondValue = secondValue.ToNumber($"Function '{t}' parameter 2 is error!");
91+
secondValue = secondValue.ToNumber("Div fun right value");
9692
if (secondValue.IsError) { return secondValue; }
93+
if (secondValue.NumberValue == 0)
94+
{
95+
return Operand.Error($"Function '{t}' parameter 2 is error!");
96+
}
9797
return Operand.Create(firstValue.NumberValue / secondValue.NumberValue);
9898
} else if (t == "%") {
9999
firstValue = firstValue.ToNumber("% fun right value");
@@ -837,6 +837,8 @@ public Operand VisitBIN2OCT_fun(mathParser.BIN2OCT_funContext context)
837837
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
838838

839839
var firstValue = args[0].ToText("Function BIN2OCT parameter 1 is error!");
840+
if (firstValue.IsError) { return firstValue; }
841+
840842
if (bit_2.IsMatch(firstValue.TextValue) == false) { return Operand.Error("Function BIN2OCT parameter 1 is error!"); }
841843
var num = Convert.ToString(Convert.ToInt32(firstValue.TextValue, 2), 8);
842844
if (args.Count == 2) {
@@ -864,6 +866,8 @@ public Operand VisitBIN2HEX_fun(mathParser.BIN2HEX_funContext context)
864866
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
865867

866868
var firstValue = args[0].ToText("Function BIN2HEX parameter 1 is error!");
869+
if (firstValue.IsError) { return firstValue; }
870+
867871
if (bit_2.IsMatch(firstValue.TextValue) == false) { return Operand.Error("Function BIN2HEX parameter 1 is error!"); }
868872
var num = Convert.ToString(Convert.ToInt32(firstValue.TextValue, 2), 16).ToUpper();
869873
if (args.Count == 2) {
@@ -883,6 +887,8 @@ public Operand VisitOCT2BIN_fun(mathParser.OCT2BIN_funContext context)
883887
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
884888

885889
var firstValue = args[0].ToText("Function OCT2BIN parameter 1 is error!");
890+
if (firstValue.IsError) { return firstValue; }
891+
886892
if (bit_8.IsMatch(firstValue.TextValue) == false) { return Operand.Error("Function OCT2BIN parameter 1 is error!"); }
887893
var num = Convert.ToString(Convert.ToInt32(firstValue.TextValue, 8), 2);
888894
if (args.Count == 2) {
@@ -910,6 +916,7 @@ public Operand VisitOCT2HEX_fun(mathParser.OCT2HEX_funContext context)
910916
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
911917

912918
var firstValue = args[0].ToText("Function OCT2HEX parameter 1 is error!");
919+
if (firstValue.IsError) { return firstValue; }
913920
if (bit_8.IsMatch(firstValue.TextValue) == false) { return Operand.Error("Function OCT2HEX parameter 1 is error!"); }
914921
var num = Convert.ToString(Convert.ToInt32(firstValue.TextValue, 8), 16).ToUpper();
915922
if (args.Count == 2) {
@@ -928,6 +935,7 @@ public Operand VisitDEC2BIN_fun(mathParser.DEC2BIN_funContext context)
928935
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
929936

930937
var firstValue = args[0].ToNumber("Function DEC2BIN parameter 1 is error!");
938+
if (firstValue.IsError) { return firstValue; }
931939
var num = System.Convert.ToString(firstValue.IntValue, 2);
932940
if (args.Count == 2) {
933941
var secondValue = args[1].ToNumber("Function DEC2BIN parameter 2 is error!");
@@ -945,6 +953,7 @@ public Operand VisitDEC2OCT_fun(mathParser.DEC2OCT_funContext context)
945953
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
946954

947955
var firstValue = args[0].ToNumber("Function DEC2OCT parameter 1 is error!");
956+
if (firstValue.IsError) { return firstValue; }
948957
var num = System.Convert.ToString(firstValue.IntValue, 8);
949958
if (args.Count == 2) {
950959
var secondValue = args[1].ToNumber("Function DEC2OCT parameter 2 is error!");
@@ -962,6 +971,7 @@ public Operand VisitDEC2HEX_fun(mathParser.DEC2HEX_funContext context)
962971
foreach (var item in context.expr()) { var aa = this.Visit(item); if (aa.IsError) { return aa; } args.Add(aa); }
963972

964973
var firstValue = args[0].ToNumber("Function DEC2HEX parameter 1 is error!");
974+
if (firstValue.IsError) { return firstValue; }
965975
var num = System.Convert.ToString(firstValue.IntValue, 16).ToUpper();
966976
if (args.Count == 2) {
967977
var secondValue = args[1].ToNumber("Function DEC2HEX parameter 2 is error!");

0 commit comments

Comments
 (0)