Пример #1
0
        public static void Main(string[] args)
        {
            while (true)
            {
                Console.Write(">>> ");
                string expression = Console.ReadLine();

                try {
                    ShuntingYard  parser          = new ShuntingYard(Lexer.Tokenize(expression));
                    Queue <Token> postfixNotation = parser.PostfixTokens;
                    Evaluator     evaluator       = new Evaluator(postfixNotation);
                    Console.WriteLine(evaluator.Evaluate());
                } catch (Exception) {
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string input = "-28.464646 + -2 * +2";
            var    lexer = new Lexer();

            Console.WriteLine("Tokens:");
            var tokens = lexer.Tokenize(input);

            foreach (var token in tokens)
            {
                Console.WriteLine($"Type: {token.TokenType}; Value: {token.Value}");
            }

            var parser = new Parser();

            Console.WriteLine();
            Console.WriteLine($"Result: {parser.Parse(tokens):0.00000}");
        }