Exemplo n.º 1
0
        private string getLastTokenValue(string updatedInput)
        {
            Tokenize inputTokenize = new Tokenize(updatedInput);

            Token[] tokens   = inputTokenize.getArrayOfTokens();
            Token   lastItem = tokens[tokens.Length - 1];

            return(lastItem.getTokenValue().ToString());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }