Exemplo n.º 1
0
 public override string ToString()
 {
     if (Function is ArithmeticBinaryFunction)
     {
         return($"{LeftBracket.GetInstance()}{_terms[0]}{Function}{_terms[1]}{RightBracket.GetInstance()}");
     }
     return($"{Function}{LeftBracket.GetInstance()}{string.Join<Term>(Comma.GetInstance().ToString(), _terms)}{RightBracket.GetInstance()}");
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取实际右括号
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public static string GetRightBracket(RightBracket m)
        {
            string str = string.Empty;

            switch (m)
            {
            case RightBracket.右括号:
                str = ")";
                break;

            default:
                str = ")";
                break;
            }
            return(str);
        }
Exemplo n.º 3
0
 void CreateOperators()
 {
     // Only one of each operation Token needs to be created
     opAdd          = new Add(workStack);
     opSubtract     = new Subtract(workStack);
     opMultiply     = new Multiply(workStack);
     opDivide       = new Divide(workStack);
     opPower        = new Power(workStack);
     opLeftBracket  = new LeftBracket();
     opRightBracket = new RightBracket();
     opUnaryMinus   = new UnaryMinus(workStack);
     opUnaryPlus    = new UnaryPlus();
     opFactorial    = new Factorial(workStack);
     opSqrt         = new Sqrt(workStack);
     opSin          = new Sin(workStack);
     opCos          = new Cos(workStack);
     opTan          = new Tan(workStack);
     opLog          = new Log(workStack);
     opAsin         = new Asin(workStack);
     opAcos         = new Acos(workStack);
     opAtan         = new Atan(workStack);
     functions      = new Dictionary <string, Function>
     {
         { "sqrt", opSqrt },
         { "sin", opSin },
         { "cos", opCos },
         { "tan", opTan },
         { "log", opLog },
         { "asin", opAsin },
         { "acos", opAcos },
         { "atan", opAtan }
     };
     binaryOperators = new Dictionary <char, BinaryOperator>
     {
         { plusChar, opAdd },
         { minusChar, opSubtract },
         { multiplyChar, opMultiply },
         { divideChar, opDivide },
         { powerChar, opPower }
     };
 }
Exemplo n.º 4
0
 public bool IsRightBracket(string value)
 {
     return(RightBracket.Contains(value));
 }
 public override string ToString()
 {
     return($"{LeftBracket.GetInstance()}{Quantifier}{ObjectVariable}{RightBracket.GetInstance()}{SubFormula}");
 }
Exemplo n.º 6
0
 public override string ToString()
 {
     return(Connective switch
     {
         UnaryPropositionalConnective _ => $"{LeftBracket.GetInstance()}{Connective}{_formulas[0]}{RightBracket.GetInstance()}",
         BinaryPropositionalConnective _ => $"{LeftBracket.GetInstance()}{_formulas[0]}{Connective}{_formulas[1]}{RightBracket.GetInstance()}",
         _ => throw new NotSupportedException("Connective must be unary or binary")
     });
Exemplo n.º 7
0
        public override string ToString()
        {
            if (Predicate is ArithmeticPredicate)
            {
                return($"{LeftBracket.GetInstance()}{_terms[0]}{Predicate}{_terms[1]}{RightBracket.GetInstance()}");
            }

            return($"{Predicate}{LeftBracket.GetInstance()}{string.Join<Term>(Comma.GetInstance().ToString(), _terms)}{RightBracket.GetInstance()}");
        }
Exemplo n.º 8
0
        private static IEnumerable <Symbol> ToSymbols(string str)
        {
            var index = 0;
            var isLastForUnaryMinus = true;

            while (index < str.Length)
            {
                switch (str[index])
                {
                case ' ':
                    ++index;
                    continue;

                case '(':
                    yield return(LeftBracket.GetInstance());

                    isLastForUnaryMinus = true;
                    ++index;
                    continue;

                case ')':
                    yield return(RightBracket.GetInstance());

                    isLastForUnaryMinus = false;
                    ++index;
                    continue;

                case ',':
                    yield return(Comma.GetInstance());

                    isLastForUnaryMinus = true;
                    ++index;
                    continue;

                case '\\':
                    yield return(SpecialSymbol(str, ref index));

                    isLastForUnaryMinus = true;
                    continue;
                }

                if (char.IsLetter(str[index]))
                {
                    yield return(LetterSymbol(str, ref index));

                    isLastForUnaryMinus = false;
                    continue;
                }

                if (char.IsDigit(str[index]))
                {
                    yield return(DigitSymbol(str, ref index));

                    isLastForUnaryMinus = false;
                    continue;
                }

                if (IsArithmeticPredicate(str[index]))
                {
                    yield return(ArithmeticPredicateSymbol(str, ref index));

                    isLastForUnaryMinus = true;
                    continue;
                }

                if (str[index] == '-')
                {
                    if (isLastForUnaryMinus)
                    {
                        yield return(UnaryMinus.GetInstance());

                        ++index;
                        continue;
                    }
                }

                if (IsArithmeticBinaryFunction(str[index]))
                {
                    yield return(ArithmeticBinaryFunctionSymbol(str, ref index));

                    isLastForUnaryMinus = true;
                    continue;
                }

                throw new ArgumentException($"the symbol {str[index]} with the number {index} is unexpected");
            }
        }