Пример #1
0
 private static object MakeQuoteConstant(object expr, Sympl symplRuntime)
 {
     if (expr is SymplListExpr)
     {
         SymplListExpr listexpr = (SymplListExpr)expr;
         int           len      = listexpr.Elements.Length;
         var           exprs    = new object[len];
         for (int i = 0; i < len; i++)
         {
             exprs[i] = MakeQuoteConstant(listexpr.Elements[i], symplRuntime);
         }
         return(Cons._List(exprs));
     }
     else if (expr is IdOrKeywordToken)
     {
         return(symplRuntime.MakeSymbol(((IdOrKeywordToken)expr).Name));
     }
     else if (expr is LiteralToken)
     {
         return(((LiteralToken)expr).Value);
     }
     else
     {
         throw new InvalidOperationException(
                   "Internal: quoted list has -- " + expr.ToString());
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            string dllPath = typeof(object).Assembly.Location;
            Assembly asm = Assembly.LoadFile(dllPath);

            string filename = @"..\..\Src\Languages\sympl\examples\test.sympl";
            var s = new Sympl(new Assembly[] { asm });
            var feo = s.ExecuteFile(filename);

            Console.WriteLine("ExecuteExpr ... ");
            s.ExecuteExpr("(print 5)", feo);

            if (args.Length > 0 && args[0] == "norepl") return;

            string input = null;
            string exprstr = "";
            Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Enter expressions.  Enter blank line to abort input.");
            Console.WriteLine("Enter 'exit (the symbol) to exit.");
            Console.WriteLine();
            string prompt = ">>> ";
            while (true) {
                Console.Write(prompt);
                input = Console.ReadLine();
                if (input == "") {
                    exprstr = "";
                    prompt = ">>> ";
                    continue;
                } else {
                    exprstr = exprstr + " " + input;
                }
                // See if we have complete input.
                try {
                    var ast = new Parser().ParseExpr(new StringReader(exprstr));
                }
                catch (Exception) {
                    prompt = "... ";
                    continue;
                }
                // We do, so execute.
                try {
                    object res = s.ExecuteExpr(exprstr, feo);
                    exprstr = "";
                    prompt = ">>> ";
                    if (res == s.MakeSymbol("exit")) return;
                    Console.WriteLine(res);
                } catch (Exception e) {
                    exprstr = "";
                    prompt = ">>> ";
                    Console.Write("ERROR: ");
                    Console.WriteLine(e);
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            string   dllPath = typeof(object).Assembly.Location;
            Assembly asm     = Assembly.LoadFile(dllPath);

            string filename = @"..\..\Src\Languages\sympl\examples\test.sympl";
            var    s        = new Sympl(new Assembly[] { asm });
            var    feo      = s.ExecuteFile(filename);

            Console.WriteLine("ExecuteExpr ... ");
            s.ExecuteExpr("(print 5)", feo);

            if (args.Length > 0 && args[0] == "norepl")
            {
                return;
            }

            string input   = null;
            string exprstr = "";

            Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Enter expressions.  Enter blank line to abort input.");
            Console.WriteLine("Enter 'exit (the symbol) to exit.");
            Console.WriteLine();
            string prompt = ">>> ";

            while (true)
            {
                Console.Write(prompt);
                input = Console.ReadLine();
                if (input == "")
                {
                    exprstr = "";
                    prompt  = ">>> ";
                    continue;
                }
                else
                {
                    exprstr = exprstr + " " + input;
                }
                // See if we have complete input.
                try {
                    var ast = new Parser().ParseExpr(new StringReader(exprstr));
                }
                catch (Exception) {
                    prompt = "... ";
                    continue;
                }
                // We do, so execute.
                try {
                    object res = s.ExecuteExpr(exprstr, feo);
                    exprstr = "";
                    prompt  = ">>> ";
                    if (res == s.MakeSymbol("exit"))
                    {
                        return;
                    }
                    Console.WriteLine(res);
                } catch (Exception e) {
                    exprstr = "";
                    prompt  = ">>> ";
                    Console.Write("ERROR: ");
                    Console.WriteLine(e);
                }
            }
        }
Пример #4
0
 private static object MakeQuoteConstant(object expr, Sympl symplRuntime) {
     if (expr is SymplListExpr) {
         SymplListExpr listexpr = (SymplListExpr)expr;
         int len = listexpr.Elements.Length;
         var exprs = new object[len];
         for (int i = 0; i < len; i++) {
             exprs[i] = MakeQuoteConstant(listexpr.Elements[i], symplRuntime);
         }
         return Cons._List(exprs);
     } else if (expr is IdOrKeywordToken) {
         return symplRuntime.MakeSymbol(((IdOrKeywordToken)expr).Name);
     } else if (expr is LiteralToken) {
         return ((LiteralToken)expr).Value;
     } else {
         throw new InvalidOperationException(
             "Internal: quoted list has -- " + expr.ToString());
     }
 }