Beispiel #1
0
        public Evaluator(Interpreter interpreter)
        {
            this.interpreter = interpreter;
            this.GlobalEnv = interpreter.GlobalEnv;

            Stack = new Stack<StackFrame>();

            var ConsoleInput = new ScheminPort(Console.In);
            var ConsoleOutput = new ScheminPort(Console.Out);

            this.CurrentInputPort = ConsoleInput;
            this.CurrentOutputPort = ConsoleOutput;
        }
Beispiel #2
0
 static void InterpretFile(string filename)
 {
     Interpreter i = new Interpreter();
     string contents = File.ReadAllText(filename);
     Console.WriteLine(i.Interpret(contents));
 }
Beispiel #3
0
        static void ReplPrompt()
        {
            Interpreter i = new Interpreter();
            for (; ;)
            {
                bool completeInput = false;
                int openParens = 0;
                int closeParens = 0;

                List<Token> partialInput = new List<Token>();

                while (completeInput != true)
                {
                    if (openParens != closeParens)
                    {
                        Console.Write("schemin* ");
                    }
                    else
                    {
                        Console.Write("schemin> ");
                    }

                    string line = Console.ReadLine();

                    // bust out right here if the user wants to exit
                    if (line == ",exit")
                    {
                        return;
                    }

                    var lineTokens = i.tokenizer.Tokenize(line);

                    foreach (Token token in lineTokens)
                    {
                        partialInput.Add(token);
                        if (token.Type == TokenType.OpenParen)
                        {
                            openParens++;
                        }
                        else if (token.Type == TokenType.CloseParen)
                        {
                            closeParens++;
                        }
                    }

                    if (openParens == closeParens)
                    {
                        completeInput = true;
                        break;
                    }
                }

                if (partialInput.Count < 1)
                {
                    continue;
                }

                Console.WriteLine(i.Interpret(partialInput));
            }
        }