Beispiel #1
0
        public static int GetBoolExpressionResolve(List <string> expression, bool debugMode)
        {
            var openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);

            while (openingBracket != -1)
            {
                var closingBracket           = BracketsProcessor.GetDeepestClosingBracketsIndex(expression, openingBracket);
                var bracketsInLineExpression =
                    BracketsProcessor.GetBracketsExpression(expression, openingBracket, closingBracket);

                int num;

                if (closingBracket - openingBracket == 3)
                {
                    num = Convert.ToInt32(!_GetStringToBool(expression[openingBracket + 2]));
                }
                else
                {
                    num = _ResolveInLineExpression(bracketsInLineExpression, debugMode);
                }

                expression.RemoveRange(
                    openingBracket,
                    closingBracket - openingBracket + 1
                    );
                expression.Insert(openingBracket, "" + num);

                openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);
            }

            return(_ResolveInLineExpression(expression, debugMode));
        }
Beispiel #2
0
        public static double ResolveExpression(List <string> expression)
        {
            var openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);

            while (openingBracket != -1)
            {
                var closingBracket           = BracketsProcessor.GetDeepestClosingBracketsIndex(expression, openingBracket);
                var bracketsInLineExpression =
                    BracketsProcessor.GetBracketsExpression(expression, openingBracket, closingBracket);

                var num = double.NaN;

                if (closingBracket - openingBracket == 3)
                {
                    num = Convert.ToDouble(
                        (expression[openingBracket + 1] + expression[openingBracket + 2]).Replace("--", ""));
                }
                else
                {
                    num = _ResolveInLineExpression(bracketsInLineExpression);
                }

                if (openingBracket - 1 >= 0)
                {
                    switch (expression[openingBracket - 1])
                    {
                    case "S":
                        num = Math.Sin(num);
                        openingBracket--;
                        break;

                    case "C":
                        num = Math.Cos(num);
                        openingBracket--;
                        break;

                    case "T":
                        num = Math.Tan(num);
                        openingBracket--;
                        break;
                    }
                }

                expression.RemoveRange(
                    openingBracket,
                    closingBracket - openingBracket + 1
                    );
                expression.Insert(openingBracket, "" + num);

                openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);
            }

            return(_ResolveInLineExpression(expression));
        }
Beispiel #3
0
        public static string ResolveExpression(List <string> expression)
        {
            var openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);

            while (openingBracket != -1)
            {
                var closingBracket           = BracketsProcessor.GetDeepestClosingBracketsIndex(expression, openingBracket);
                var bracketsInLineExpression =
                    BracketsProcessor.GetBracketsExpression(expression, openingBracket, closingBracket);

                var matrix = "";

                if (closingBracket - openingBracket == 3)
                {
                    matrix = _MatrixToString(_MatrixPowMinusOne(ProcessMatrix(expression[openingBracket + 2])));
                }
                else
                {
                    matrix = _ResolveInLineExpression(bracketsInLineExpression);
                }

                if (openingBracket - 1 >= 0 && expression[openingBracket - 1] == "I")
                {
                    var processedMatrix = ProcessMatrix(matrix);
                    if (!MatrixOperationValidator.ValidateInversion(processedMatrix))
                    {
                        return("error (matrix inversion)");
                    }

                    matrix = _InvertMatrix(processedMatrix);
                    openingBracket--;
                }

                expression.RemoveRange(
                    openingBracket,
                    closingBracket - openingBracket + 1
                    );
                expression.Insert(openingBracket, matrix);

                openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);
            }

            return(_ResolveInLineExpression(expression));
        }
Beispiel #4
0
        public static string Resolve(List <List <string> > expression, bool debugMode)
        {
            foreach (var elem in expression)
            {
                Console.WriteLine();
                foreach (var s in elem)
                {
                    Console.Write($" {s}");
                }
            }

            var openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);

            while (openingBracket != -1)
            {
                var closingBracket =
                    BracketsProcessor.GetDeepestClosingBracketsIndex(expression, openingBracket);

                var bracketsExpression =
                    BracketsProcessor.GetBracketsExpression(expression, openingBracket, closingBracket);

                var resolvedBracketsExpression = ResolveInlineExpression(bracketsExpression);

                if (openingBracket - 1 >= 0)
                {
                    switch (expression[openingBracket - 1][1])
                    {
                    case "-":
                        resolvedBracketsExpression =
                            MultiplyInlineExpressionByX(new List <string> {
                            "X", "-1", "0"
                        }, bracketsExpression);
                        openingBracket--;
                        break;

                    case "*":
                        resolvedBracketsExpression =
                            MultiplyInlineExpressionByX(expression[openingBracket - 2], bracketsExpression);
                        openingBracket -= 2;
                        break;
                    }
                }

                expression.RemoveRange(
                    openingBracket,
                    closingBracket - openingBracket + 1
                    );

                for (var i = 0; i < resolvedBracketsExpression.Count; i++)
                {
                    expression.Insert(openingBracket + i, resolvedBracketsExpression[i]);
                }

                Console.WriteLine();
                foreach (var elem in expression)
                {
                    Console.WriteLine();
                    foreach (var s in elem)
                    {
                        Console.Write($" {s}");
                    }
                }

                openingBracket = BracketsProcessor.GetDeepestOpeningBracketsIndex(expression);
            }

            expression = ResolveInlineExpression(expression);

            Console.WriteLine();
            foreach (var elem in expression)
            {
                Console.WriteLine();
                foreach (var s in elem)
                {
                    Console.Write($" {s}");
                }
            }

            return(Stringify(expression));
        }