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") });
private static void CheckOrder(Symbol left, Symbol right) { var err = left switch { Comma _ => (right is Comma), ArithmeticBinaryFunction _ => (right is ArithmeticBinaryFunction), ArithmeticPredicate _ => (right is ArithmeticPredicate), ObjectVariable _ => (right is ObjectVariable), IndividualConstant <BigInteger> _ => (right is IndividualConstant <BigInteger>), Quantifier _ => (right is Quantifier), BinaryPropositionalConnective _ => (right is BinaryPropositionalConnective), _ => false }; if (err) { throw new ArgumentException($"symbols {left} and {right} cannot be placed side by side"); } }
private static void CalcBinaryPropositionalConnective(Stack <object> stack, BinaryPropositionalConnective connective) { if (stack.Count < 2) { throw new ArgumentException($"two formulas were expected for {connective}"); } try { var right = (Formula)stack.Pop(); var left = (Formula)stack.Pop(); var newFormula = new PropositionalConnectiveFormula(connective, left, right); stack.Push(newFormula); } catch (Exception) { throw new ArgumentException($"two formulas were expected for {connective}"); } }