Add more statements and bug fixes

- Add `Execute(List<string>...` method to interpreter
- Add escape sequence (`!!`)
- Fix `Evaluator.Calulate` method not correctly handling `-` and `+` prefixes
This commit is contained in:
Stone_Red
2022-03-31 13:01:31 +02:00
parent 29bbcebf74
commit 510d2d910c
11 changed files with 101 additions and 41 deletions
+21 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace YesNt.Interpreter.Utilities
@@ -87,7 +88,18 @@ namespace YesNt.Interpreter.Utilities
return null;
}
public static string Calculate(string input, char op = '+')
public static string Calculate(string input)
{
input = Regex.Replace(input, @"(\+ +\+)+", "+");
input = Regex.Replace(input, @"(\- +\-)+", "+");
input = Regex.Replace(input, @"(\- +\+)+", "-");
input = Regex.Replace(input, @"(\+ +\-)+", "-");
string yes = Calculate(input, '+');
return yes;
}
private static string Calculate(string input, char op)
{
if (input is null)
{
@@ -110,6 +122,13 @@ namespace YesNt.Interpreter.Utilities
string[] parts = input.Split(op);
//Weird fix
if (parts.Length >= 2 && string.IsNullOrWhiteSpace(parts[0]))
{
parts[1] = $"{op}{parts[1]}";
parts = parts.Skip(1).ToArray();
}
double number = double.NaN;
foreach (string p in parts)
@@ -173,7 +192,7 @@ namespace YesNt.Interpreter.Utilities
}
}
return number.ToString();
return number.ToString(System.Globalization.CultureInfo.InvariantCulture);
}
}
}