private string getLastTokenValue(string updatedInput) { Tokenize inputTokenize = new Tokenize(updatedInput); Token[] tokens = inputTokenize.getArrayOfTokens(); Token lastItem = tokens[tokens.Length - 1]; return(lastItem.getTokenValue().ToString()); }
public string getResult(string updatedInput) { Tokenize inputTokenize = new Tokenize(updatedInput); Token[] tokens = inputTokenize.getArrayOfTokens(); string answer; if (tokens.Length == 0 || InputValidation.countLeftBrackets(updatedInput) != InputValidation.countRightBrackets(updatedInput)) { answer = ""; } else { ShuntingYard sy = new ShuntingYard(tokens); CalculateExpression calculate = new CalculateExpression(sy.getArray()); answer = calculate.getAnswer().ToString(); } return(answer); }
public string changeTheSign(string updatedExpression) { if (String.IsNullOrEmpty(updatedExpression)) { updatedExpression = "(-"; } else { Tokenize inputTokenize = new Tokenize(updatedExpression); Token[] tokens = inputTokenize.getArrayOfTokens(); string lastDecimalToken = Regex.Match(updatedExpression, @"(\d+\.\d+)$").Value; if (!string.IsNullOrEmpty(lastDecimalToken)) { updatedExpression = checkSignOfDecimalToken(tokens, updatedExpression, lastDecimalToken.Length); } else { updatedExpression = checkSign(tokens, updatedExpression); } } expressionText = updatedExpression; return(expressionText); }