From c449ae346c8ce38cf411797594eb9fda18576d8a Mon Sep 17 00:00:00 2001 From: "S. Hi" <128063668+blackborn66@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:23:41 +0200 Subject: [PATCH 1/2] problem with unary operators solved --- MathParser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MathParser.cs b/MathParser.cs index 175ac37..9af29d8 100644 --- a/MathParser.cs +++ b/MathParser.cs @@ -305,7 +305,7 @@ private string LexicalAnalysisInfixNotation(string expression, ref int pos) if (supportedOperators.ContainsKey(token.ToString())) { // Determine it is unary or binary operator - bool isUnary = pos == 0 || expression[pos - 1] == '('; + bool isUnary = pos == 0 || expression[pos - 1] == '(' || supportedOperators.ContainsKey(expression[pos - 1].ToString()); pos++; switch (token.ToString()) @@ -739,4 +739,4 @@ private int NumberOfArguments(string token) #endregion } -} \ No newline at end of file +} From 2d4dd55e29089eb32f85c66091f39da317b81f31 Mon Sep 17 00:00:00 2001 From: "S. Hi" <128063668+blackborn66@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:18:25 +0200 Subject: [PATCH 2/2] ")" was wrong in my former changes --- MathParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MathParser.cs b/MathParser.cs index 9af29d8..01e11a7 100644 --- a/MathParser.cs +++ b/MathParser.cs @@ -305,7 +305,7 @@ private string LexicalAnalysisInfixNotation(string expression, ref int pos) if (supportedOperators.ContainsKey(token.ToString())) { // Determine it is unary or binary operator - bool isUnary = pos == 0 || expression[pos - 1] == '(' || supportedOperators.ContainsKey(expression[pos - 1].ToString()); + bool isUnary = pos == 0 || "+-*/^(".Contains(expression[pos - 1].ToString()); pos++; switch (token.ToString())