Exemple #1
0
        // EmptyLogicException, DifferentSyntaxesUsedException, UnexpectedSymbolException, InvalidVariableNameException, UnclosedBracketException
        private static LogicExpression SplitWordsByOperator(String[] paramArrayOfString, int paramInt1, Operator paramInt2,
            ParserSyntax paramParserSyntax)
        {
            if (paramInt1 == 0)
                throw new UnexpectedSymbolException("Operator at beginning of list of arguments");
            if (paramInt1 == paramArrayOfString.Length - 1)
            {
                throw new UnexpectedSymbolException("Operator at end of list of arguments");
            }
            int m;
            if ((paramInt2 == Operator.OperatorXor) || (paramInt2 == Operator.OperatorImplies) || (paramInt2 == Operator.OperatorBiimplies))
            {
                var arrayOfLogicExpression1 = new LogicExpression[2];

                var arrayOfString1 = new String[paramInt1];
                var arrayOfString2 = new String[paramArrayOfString.Length - paramInt1 - 1];

                for (var mm = 0; mm < arrayOfString1.Length; mm++)
                {
                    arrayOfString1[mm] = paramArrayOfString[mm];
                }

                m = paramInt1 + 1;

                for (int n = 0; n < arrayOfString2.Length; n++)
                {
                    arrayOfString2[n] = paramArrayOfString[(m++)];
                }
                arrayOfLogicExpression1[0] = ParseWords(arrayOfString1, paramParserSyntax);
                arrayOfLogicExpression1[1] = ParseWords(arrayOfString2, paramParserSyntax);

                var localLogicBranch1 = new OperatorExpression(paramInt2)
                                            {
                                                Branches = arrayOfLogicExpression1
                                            };
                return localLogicBranch1;
            }

            int i = 2;
            for (int k = paramInt1 - 1; k >= 0; k--)
            {
                var j = GetOperatorValue(paramArrayOfString[k]);

                if (j == Operator.NonOperator)
                    continue;
                if (j != paramInt2)
                {
                    break;
                }
                paramParserSyntax.UpdateLogicSyntax(GetLogicSyntax(paramArrayOfString[k]));

                i++;
            }

            var arrayOfLogicExpression2 = new LogicExpression[i];

            m = paramArrayOfString.Length - 1;

            for (int i2 = arrayOfLogicExpression2.Length - 1; i2 >= 0; i2--)
            {
                int i1 = 0;

                int i3;
                for (i3 = m; i3 >= 0; i3--)
                {
                    var j = GetOperatorValue(paramArrayOfString[i3]);

                    if (j != paramInt2)
                        i1++;
                    else if (j == paramInt2)
                    {
                        break;
                    }
                }
                var arrayOfString3 = new String[i1];

                i3 = m - i1;
                int i4 = i1 - 1;

                for (int i5 = m; i5 > i3; i5--)
                {
                    arrayOfString3[(i4--)] = paramArrayOfString[i5];
                }

                m = m - i1 - 1;

                arrayOfLogicExpression2[i2] = ParseWords(arrayOfString3, paramParserSyntax);
            }

            var localLogicBranch2 = new OperatorExpression(paramInt2)
                                        {
                                            Branches = arrayOfLogicExpression2
                                        };
            return localLogicBranch2;
        }
Exemple #2
0
        private static LogicExpression ParseWords(String[] paramArrayOfString, ParserSyntax paramParserSyntax)
        {
            if (paramArrayOfString.Length == 1)
            {
                String[] arrayOfString = BreakDownInToWords(paramArrayOfString[0]);

                if (arrayOfString.Length == 1)
                {
                    return paramParserSyntax.GenerateLiteral(paramArrayOfString[0]);
                }
                paramArrayOfString = arrayOfString;
            }
            for (int j = paramArrayOfString.Length - 1; j >= 0; j--)
            {
                var i = GetOperatorValue(paramArrayOfString[j]);

                LogicSyntax k;
                switch (i)
                {
                    case (Operator.OperatorImplies):
                        k = GetLogicSyntax(paramArrayOfString[j]);
                        if (k != 0)
                        {
                            paramParserSyntax.UpdateLogicSyntax(k);
                        }
                        return SplitWordsByOperator(paramArrayOfString, j, Operator.OperatorImplies, paramParserSyntax);
                    case Operator.OperatorBiimplies:
                        k = GetLogicSyntax(paramArrayOfString[j]);
                        if (k != 0)
                        {
                            paramParserSyntax.UpdateLogicSyntax(k);
                        }
                        return SplitWordsByOperator(paramArrayOfString, j, Operator.OperatorBiimplies, paramParserSyntax);
                }
            }
            {
                for (int j = paramArrayOfString.Length - 1; j >= 0; j--)
                {
                    var i = GetOperatorValue(paramArrayOfString[j]);

                    if (i == Operator.Or)
                    {
                        paramParserSyntax.UpdateLogicSyntax(GetLogicSyntax(paramArrayOfString[j]));

                        return SplitWordsByOperator(paramArrayOfString, j, Operator.Or, paramParserSyntax);
                    }
                    if (paramArrayOfString[j].Equals("!="))
                    {
                        return SplitWordsByOperator(paramArrayOfString, j, Operator.OperatorXor, paramParserSyntax);
                    }
                }
            }
            for (int j = paramArrayOfString.Length - 1; j >= 0; j--)
            {
                if (GetOperatorValue(paramArrayOfString[j]) != 0)
                    continue;
                paramParserSyntax.UpdateLogicSyntax(GetLogicSyntax(paramArrayOfString[j]));

                return SplitWordsByOperator(paramArrayOfString, j, 0, paramParserSyntax);
            }

            if (paramParserSyntax.NegationSyntax == NegationSyntax.Unknown)
            {
                if (paramArrayOfString[0].Equals("NOT", StringComparison.InvariantCultureIgnoreCase))
                    paramParserSyntax.UpdateNegationSyntax(NegationSyntax.Written);
                else if (paramArrayOfString[0].Equals("~"))
                    paramParserSyntax.UpdateNegationSyntax(NegationSyntax.Before);
                else if (paramArrayOfString[(paramArrayOfString.Length - 1)].Equals("'"))
                {
                    paramParserSyntax.UpdateNegationSyntax(NegationSyntax.After);
                }

            }

            bool negated = false;
            var kk = paramArrayOfString.Length - 1;
            LogicExpression localLogicExpression = null;
            int m;
            switch (paramParserSyntax.NegationSyntax)
            {
                case NegationSyntax.Written:
                    for (m = 0; m < kk; m++)
                    {
                        if (!paramArrayOfString[m].Equals("NOT", StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new UnexpectedSymbolException("Expected 'NOT' instead of (or operator after) '" + paramArrayOfString[m] + "'");
                        }

                        negated = negated == false;
                    }
                    localLogicExpression = Parse(paramArrayOfString[kk], paramParserSyntax);
                    break;
                case NegationSyntax.Before:
                    for (m = 0; m < kk; m++)
                    {
                        if (!paramArrayOfString[m].Equals("~", StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new UnexpectedSymbolException("Expected '~' instead of (or operator after) '" + paramArrayOfString[m] + "'");
                        }

                        negated = negated == false;
                    }
                    localLogicExpression = Parse(paramArrayOfString[kk], paramParserSyntax);
                    break;
                case NegationSyntax.After:
                    for (m = kk; m > 0; m--)
                    {
                        if (!paramArrayOfString[m].Equals("'", StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new UnexpectedSymbolException("Expected \"'\" instead of (or operator before) '" + paramArrayOfString[m] +
                                                                "'");
                        }

                        negated = !negated;
                    }
                    localLogicExpression = Parse(paramArrayOfString[0], paramParserSyntax);
                    break;
            }

            localLogicExpression.Negated = negated;
            return localLogicExpression;
        }