private static Component GenerateOperatorObject(char operatorCharacter, Component root) { switch (operatorCharacter) { case '>': return(_binaryTree.InsertNode(root, new Implication())); case '=': return(_binaryTree.InsertNode(root, new BiImplication())); case '%': return(_binaryTree.InsertNode(root, new Nand())); case '&': return(_binaryTree.InsertNode(root, new Conjunction())); case '|': return(_binaryTree.InsertNode(root, new Disjunction())); case '~': return(_binaryTree.InsertNode(root, new Negation())); case '@': lastVariableContainingNode = new Universal(); return(_binaryTree.InsertNode(root, lastVariableContainingNode)); case '!': lastVariableContainingNode = new Existential(); return(_binaryTree.InsertNode(root, lastVariableContainingNode)); default: return(null); } }
/// <summary> /// Generate a binary tree based for a proposition formula /// </summary> /// <returns>The root of binary tree</returns> private static void GenerateBinaryTreeProposition() { Component root = _binaryTree.Root; for (var i = 0; i <= Elements.Count - 1; i++) { var currentCharacter = Elements[i]; var currentCharacterType = TypeOfCharacter(currentCharacter, false); if (currentCharacterType == CharacterType.PropositionalVariable) { if (currentCharacter == '0') { _binaryTree.InsertNode(root, new TrueFalse(false)); } else if (currentCharacter == '1') { _binaryTree.InsertNode(root, new TrueFalse(true)); } else { var propositionVariable = new Variable(currentCharacter); _binaryTree.InsertNode(root, propositionVariable); } } else if (currentCharacterType == CharacterType.Connectives) { root = GenerateOperatorObject(currentCharacter, root); } } NodeCounter = 0; }
/// <summary> /// Clear previous parsed formula and its associated binary tree /// </summary> /// Should be called before any external call of ParseRecursively private static void EraseParsedList() { _binaryTree = new BinaryTree(); Elements.Clear(); NodeCounter = 0; Tableaux.VarIndex = 0; _binaryTree.Root = null; lastVariableContainingNode = null; }
/// <summary> /// Generate a binary tree based for a Predicate formula /// </summary> /// <returns>The root of binary tree</returns> private static void GenerateBinaryTreePredicate() { Component root = _binaryTree.Root; for (var i = 0; i <= Elements.Count - 1; i++) { var currentCharacter = Elements[i]; var currentCharacterType = TypeOfCharacter(currentCharacter, true); if (currentCharacterType == CharacterType.PropositionalVariable) { Variable propositionVariable = null; if (lastVariableContainingNode is Universal || lastVariableContainingNode is Existential) { propositionVariable = new Variable(currentCharacter, true); } else if (lastVariableContainingNode is Predicate) { propositionVariable = new Variable(currentCharacter); if (_binaryTree.PropositionalVariables.Get_BindVariables().Exists(x => x.Symbol == currentCharacter)) { propositionVariable.BindVariable = true; } } _binaryTree.InsertNode(lastVariableContainingNode, propositionVariable); } else if (currentCharacterType == CharacterType.Predicate) { lastVariableContainingNode = new Predicate(currentCharacter); root = _binaryTree.InsertNode(root, lastVariableContainingNode); } else if (currentCharacterType == CharacterType.Connectives || currentCharacterType == CharacterType.Quantifier) { root = GenerateOperatorObject(currentCharacter, root); } } NodeCounter = 0; }