コード例 #1
0
ファイル: Repl.cs プロジェクト: CHNB128/GCL
        static eValue ParseAST(eValue ast, Env env)
        {
            if (ast is eSymbol)
            {
                return(env.get((eSymbol)ast));
            }
            else if (ast is eList)
            {
                eList oldList = (eList)ast;
                eList newList = ast.list_Q() ? new eList() : (eList) new eVector();

                foreach (eValue mv in oldList.getValue())
                {
                    newList.conj_BANG(Eval(mv, env));
                }

                return(newList);
            }
            else if (ast is eHashMap)
            {
                var hashMap = new Dictionary <string, eValue>();

                foreach (var entry in ((eHashMap)ast).getValue())
                {
                    hashMap.Add(entry.Key, Eval((eValue)entry.Value, env));
                }

                return(new eHashMap(hashMap));
            }
            else
            {
                return(ast);
            }
        }
コード例 #2
0
ファイル: Repl.cs プロジェクト: CHNB128/GCL
        public void Loop(string[] args)
        {
            eList _argv = new eList();

            for (int i = 1; i < args.Length; i++)
            {
                _argv.conj_BANG(new eString(args[i]));
            }

            this.enviroment.set(new eSymbol("*ARGV*"), _argv);

            while (true)
            {
                string line;

                try
                {
                    line = ReadLine.Read("user> ");
                    if (line == null)
                    {
                        break;
                    }
                    if (line == "")
                    {
                        continue;
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("IOException: " + e.Message);
                    break;
                }

                try
                {
                    Console.WriteLine(this.Print(this.EvalString(line)));
                }
                catch (Evil.Types.eContinue)
                {
                    continue;
                }
                catch (Evil.Types.eException e)
                {
                    Console.WriteLine($"Error: {printer._pr_str (e.getValue (), false)}");
                    continue;
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error: {e.Message}");
                    Console.WriteLine(e.StackTrace);
                    continue;
                }
            }
        }
コード例 #3
0
ファイル: Lexer.cs プロジェクト: CHNB128/GCL
        private static eValue ReadList(Reader reader, eList list, char start, char end)
        {
            string token = reader.next();

            if (token[0] != start)
            {
                throw new ParseError("expected '" + start + "'");
            }

            while ((token = reader.peek()) != null && token[0] != end)
            {
                list.conj_BANG(ReadForm(reader));
            }

            if (token == null)
            {
                throw new ParseError("expected '" + end + "', got EOF");
            }

            reader.next();

            return(list);
        }