Exemple #1
0
            public static void InterpretingInConsole(this SSScope scope)
            {
                var w      = new Stopwatch();
                var file   = new CodeFile();
                var syntax = new SyntaxAnalyzer();

                while (true)
                {
                    file.ReSet();
                    syntax.ReSet();
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(">>> ");
                        String code;
                        if ((code = Console.ReadLine()).NotEmpty())
                        {
                            file.SourceCode = code;
                            file.Parse();
                            if (file.ErrorList.NotEmpty())
                            {
                                file.PrintErrors(Console.Out);
                            }
                            syntax.Take(file.TokenList);
                            if (syntax.ErrorList.NotEmpty())
                            {
                                syntax.PrintErrors(Console.Out);
                            }

                            Console.ForegroundColor = ConsoleColor.Green;

                            w.Reset();
                            w.Start();
                            Console.WriteLine(">>> " + syntax.Expressions.First().Evaluate(scope));
                            w.Stop();
                            Console.WriteLine(w.ElapsedMilliseconds + "ms");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                        // ex.StackTrace.Split("at".ToCharArray()).Take(3).ForEach(a => scope.Output.WriteLine(a));
                    }
                }
            }