static void Main(string[] args) { int count = 0; Constant currentConstant = new Constant(); Evaluate expression; while (true) { Console.Write("[{0}]> ", count); string input = Console.ReadLine(); expression = new Evaluate(input, currentConstant); if (input.ToLower() == "exit" || input.ToLower() == "quit") { break; } else if (input.IndexOf("=")> -1) { //set variable Parse addConstant = new Parse(input, currentConstant); addConstant.setOperatorIndex(); currentConstant.addConst(addConstant.StringFirst(), addConstant.secondNum()); // = saved 'x' as '3' Console.WriteLine("= saved '" + addConstant.StringFirst() + "' as '" + addConstant.secondNum() + "'"); } else { int answer = expression.doMath(); Console.WriteLine(" = {0}", answer); count++; } } }
public void ParseOnlyAllowsSimpleExpressions() { Parse twoPlusThree = new Parse("2 - 5 + 3"); twoPlusThree.setOperatorIndex(); twoPlusThree.firstNum(); twoPlusThree.secondNum(); }
public void ParseOnlyAllowsNumbersSecond() { Parse twoPlusThree = new Parse("2 + b"); twoPlusThree.setOperatorIndex(); twoPlusThree.firstNum(); twoPlusThree.secondNum(); }
public void ParseCanFindSecondNum() { Parse twoPlusThree = new Parse("2 + 3"); twoPlusThree.setOperatorIndex(); twoPlusThree.firstNum(); Assert.AreEqual(3, twoPlusThree.secondNum()); }
public void ParseAllowsConstantsFirst() { Constant newConstant = new Constant(); Parse aplus3 = new Parse("a + 3", newConstant); aplus3.addConst("a", 5); aplus3.setOperatorIndex(); Assert.AreEqual(5, aplus3.firstNum()); }
public void ParseCanFindOperation() { Parse twoPlusThree = new Parse("2 + 3"); twoPlusThree.setOperatorIndex(); Assert.AreEqual("+", twoPlusThree.mathOperation()); }