static void Main(string[] args) { Console.WindowWidth = 200; //declare variables string expression; bool stop = false; Console.WriteLine("\t\tTRUTH TABLE GENERATOR"); Console.WriteLine("\t\tBy Nathan Beattie"); Console.WriteLine("Type \"guide\" for instructions on how to use this guide, \"exit\" to quit, or type your expression below"); //get input while (!stop) { Console.Write("Please enter an expression: "); expression = Console.ReadLine(); if (expression == "guide") { DisplayGuide(); } else if (expression == "exit") { return; } else { Table truthTable = new Table(); LogicExpression logEx = new LogicExpression(expression, 0, truthTable); truthTable.TestStuff(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Would you like to test another expression? (y for yes, anything else for no)"); string s = Console.ReadLine(); if (s != "y" && s != "Y") { stop = true; } } } }
public void AddBranch(LogicExpression l) { ExpressionList.Add(l); }
public void ParseExpression() { if (_Expression[0] == '(' && _Expression[_Expression.Length - 1] == ')') { _Expression = _Expression.Substring(1, _Expression.Length - 2); } bool _Brackets = false; for (int x = 0; x < _Expression.Length; x++) { if (_Expression[x] == '(') { if (exp1 == null) { exp1 = _Expression.Substring(x + 1, CloseBracketCalculation(_Expression.Substring(x + 1)) - (x)); } else { exp2 = _Expression.Substring(x + 1, CloseBracketCalculation(_Expression.Substring(x + 1))); } x = CloseBracketCalculation(_Expression.Substring(_Expression.IndexOf('(') + 1)); _Brackets = true; } else if (_Expression[x] == 'u' || _Expression[x] == 'v' || _Expression[x] == '>' || _Expression[x] == '~' || _Expression[x] == '=') // { { if (_Expression[x] == 'u') { modifier = 'u'; SetChildren(x); break; } else if (_Expression[x] == 'v') { modifier = 'v'; SetChildren(x); break; } else if (_Expression[x] == '>') { modifier = '>'; SetChildren(x); break; } else if (_Expression[x] == '=') { modifier = '='; SetChildren(x); break; } else if (_Expression[x] == '~') { modifier = '~'; if (exp1 == null) { exp1 = _Expression.Substring(1, _Expression.Length - 1); } else { exp2 = _Expression.Substring(1, _Expression.Length - 1); } IsNot = true; break; } } } } if (modifier == 'A' && _Brackets == false) { exp1 = _Expression; _IsVariable = true; if (_Expression != "T" && _Expression != "F") { truthTable.AddVariable(exp1); } } if (!_IsVariable) { Part1 = new LogicExpression(exp1, _Level + 1, truthTable); if (!IsNot) { Part2 = new LogicExpression(exp2, _Level + 1, truthTable); } } }