Exemplo n.º 1
0
        public float main_calculator(string ss)
        {
            TOkenizer      obj1   = new TOkenizer(ss);
            Stack <float>  nstack = new Stack <float>();
            Stack <string> ostack = new Stack <string>();

            while (obj1.is_finished())
            {
                Token _res = obj1.getToken();
                if (_res.Type == TokenType.enumeric)
                {
                    nstack.Push(float.Parse(_res.Value));
                }
                else
                {
                    if (ostack.Count() == 0)
                    {
                        ostack.Push(_res.Value);
                    }
                    else
                    {
                        string char_pop = ostack.Peek();
                        int    com_res  = compare_chars(_res.Value, char_pop);
                        if (com_res == 1)
                        {
                            ostack.Push(_res.Value);
                        }
                        else
                        {
                            char_pop = ostack.Pop();
                            while (compare_chars(_res.Value, char_pop) != 1 || ostack.Count() != 0)
                            {
                                number1 = nstack.Pop();
                                number2 = nstack.Pop();
                                nstack.Push(calcalator(char_pop));
                                if (ostack.Count() == 0)
                                {
                                    break;
                                }
                                char_pop = ostack.Pop();
                            }
                            ostack.Push(_res.Value);
                        }
                    }
                }
            }
            while (ostack.Count() != 0)
            {
                string char_pop = ostack.Pop();
                number1 = nstack.Pop();
                number2 = nstack.Pop();
                nstack.Push(calcalator(char_pop));
                result = calcalator(char_pop);
            }
            return(result);
        }
Exemplo n.º 2
0
        public void main_calculator(string ss)
        {
            TOkenizer obj1 = new TOkenizer(ss);

            while (obj1.is_finished())
            {
                Token _res = obj1.getToken();
                Console.WriteLine(_res.Value);
            }
        }