Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Env env = EnvOps.CreateStdLibEnv();

            while (true)
            {
                // Print the command prompt
                Console.Write(">");

                // Read a line of text
                string line = Console.In.ReadLine();

                // Our way out of this program.
                if ("quit".Equals(line) || "(quit)".Equals(line))
                {
                    return;
                }

                // Evaluate
                string result = HighLevel.Evaluate(line, TraceLevel.Error, env);

                if (result == null)
                {
                    result = "No tokens found while parsing.";
                }

                // Print the result
                Console.WriteLine(result);
            }
        }
Ejemplo n.º 2
0
        public static string Evaluate(string line, TraceLevel traceLevel = TraceLevel.Error, Env env = null, bool traceStdLib = false)
        {
            Node node = Parse(line);

            if (node == null)
            {
                return(null);
            }

            if (traceLevel == TraceLevel.Verbose)
            {
                Console.WriteLine("Parsed input:");
                Console.WriteLine(NodeOps.Serialize(node));
            }

            if (traceStdLib)
            {
                Evaluator.Logger.TraceLevel = traceLevel;
            }
            else
            {
                Evaluator.Logger.TraceLevel = TraceLevel.Error;
            }

            if (env == null)
            {
                env = EnvOps.CreateStdLibEnv();
            }

            Evaluator.Logger.TraceLevel = traceLevel;

            node = ExpandMacros(node, env);

            if (traceLevel == TraceLevel.Verbose)
            {
                Console.WriteLine("Expanded input:");
                Console.WriteLine(NodeOps.Serialize(node));
            }

            Node resultNode = Evaluator.Evaluate(node, env);

            if (traceLevel == TraceLevel.Verbose)
            {
                Console.WriteLine("Evaluated input:");
                Console.WriteLine(NodeOps.Serialize(resultNode));
            }

            string result = NodeOps.Serialize(resultNode);

            return(result);
        }
Ejemplo n.º 3
0
        public static Env CreateEnv()
        {
            Env env = EnvOps.CreateStdLibEnv();

            Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (string path in PATHS)
            {
                if (EnvOps.LoadAssemblyLibrary(assembly, ASSEMBLY_PREFIX + path, env))
                {
                    Console.WriteLine("Loaded: " + path);
                }
                else
                {
                    Console.WriteLine("Unable to load: " + path);
                }
            }

            return(env);
        }
Ejemplo n.º 4
0
 public void SetUp()
 {
     env = EnvOps.CreateStdLibEnv();
 }