Пример #1
0
        public void Run()
        {
            ASTVisualizer visualizer = SheInfo.Visualize ? new ASTVisualizer() : null;

            using (var reader = new StreamReader(filePath))
            {
                Lexer             l   = new Lexer(reader);
                SheParser         sp  = new SheParser();
                NestedEnvironment env = new NestedEnvironment();
                Natives.AppendNatives(env);
                while (l.Peek(0) != Token.EOF)
                {
                    ASTree ast = sp.Parse(l);
                    // Console.WriteLine(ast);
                    Console.WriteLine(ast.Eval(env));
                    if (SheInfo.Visualize)
                    {
                        visualizer.Push(ast);
                    }
                }
            }
            if (SheInfo.Visualize)
            {
                visualizer.Visualize($"INTPRT_{SheInfo.StartTime:yyyy-MM-dd-HH-mm-ss}");
            }
        }
Пример #2
0
        public void Start()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(startMessage);
            ASTVisualizer visualizer = SheInfo.Visualize ? new ASTVisualizer() : null;

            while (true)
            {
                WriteSystemMessage(prompt);
                string input = ReadSource();
                if (input == null)
                {
                    break;
                }
                Lexer lexer = new Lexer(new StringReader(input));

                /*while (lexer.Peek(0) != Token.EOF)
                 * {
                 *  Console.WriteLine($"{lexer.Peek(0).GetType()}:{lexer.Read()}");
                 * }*/

                SheParser parser = new SheParser();
                ASTree    ast    = parser.Parse(lexer);

                if (SheInfo.Visualize)
                {
                    visualizer.Push(ast);
                }
                //Console.WriteLine(ast);
                Console.WriteLine(ast.Eval(replEnvironment));
                Console.WriteLine();
            }
            if (SheInfo.Visualize)
            {
                visualizer.Visualize($"REPL_{SheInfo.StartTime:yyyy-MM-dd-HH-mm-ss}");
            }
        }