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()}"); }
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()}"); }
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"); } }