Example #1
0
        //This creates a single number token for a contiguous string of numbers or a token for each individual + or * character this can easily be extended to add division and subtraction
        private void createTokenList()
        {
            equation = new LinkedList <Token>();
            Token  currentToken = new Token();
            string input        = "";

            for (int i = 0; i < inputText.Length; i++)
            {
                switch (inputText[i])
                {
                case '+':
                case '*':
                case '/':
                case '-':

                    input += inputText[i];
                    currentToken.addToTokenString(input);
                    equation.AddLast(currentToken);

                    input        = "";
                    currentToken = new Token();
                    break;

                default:
                    while (char.IsNumber(inputText[i]))
                    {
                        input += inputText[i++];

                        if (i >= inputText.Length)
                        {
                            break;
                        }
                    }

                    currentToken.addToTokenString(input);
                    equation.AddLast(currentToken);

                    input        = "";
                    currentToken = new Token();
                    i--;
                    break;
                }
            }
        }