Exemplo n.º 1
0
        private void runBtn_Click(object sender, EventArgs e)
        {
            consoleText.Clear();
            Lexer       lexer   = new Lexer(new StringReader(codeText.Text));
            RavParser   parser  = new RavParser();
            EvalVisitor visitor = new EvalVisitor();

            visitor.DebugOption = false;
            IEnvironment env = new Natives().Enviroment(new NestedEnv());

            try {
                while (lexer.Peek(0) != Token.EOF)
                {
                    ASTree ast = parser.Parse(lexer);
                    //System.Console.WriteLine("  >>> " + ast.GetType().ToString() + " " + ast.ToString());
                    //consoleText.AppendText("> " + ast.ToString() + "\n");
                    ast.Accept(visitor, env);
                    consoleText.AppendText("> " + visitor.Result.ToString() + "\n");
                }
            }
            catch (ParseException ex) {
                consoleText.AppendText("> " + ex.Message + "\n");
            }

            /*
             * for (Token tok = lexer.Read(); tok != Token.EOF; tok = lexer.Read()) {
             *  consoleText.AppendText("> " + tok.Text + "\n");
             * }
             */
        }
Exemplo n.º 2
0
 public void Run()
 {
     try {
         while (lexer.Peek(0) != Token.EOF)
         {
             ASTree ast = parser.Parse(lexer);
             ast.Accept(visitor, env);
             if (visitor.Result is ErrorValue)
             {
                 errStream.WriteLine("Error > " + visitor.Result.ToString());
             }
             else
             {
                 errStream.WriteLine("> " + visitor.Result.ToString());
             }
         }
     }
     catch (ParseException ex) {
         errStream.WriteLine("Error > " + ex.Message);
     }
 }