Exemple #1
0
        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);
            }
        }
Exemple #2
0
 public static eValue macroexpand(eValue ast, Env env)
 {
     while (is_macro_call(ast, env))
     {
         eSymbol   a0  = (eSymbol)((eList)ast) [0];
         eFunction mac = (eFunction)env.get(a0);
         ast = mac.apply(((eList)ast).rest());
     }
     return(ast);
 }
Exemple #3
0
 public static bool is_macro_call(eValue ast, Env env)
 {
     if (ast is eList)
     {
         eValue a0 = ((eList)ast) [0];
         if (a0 is eSymbol &&
             env.find((eSymbol)a0) != null)
         {
             eValue mac = env.get((eSymbol)a0);
             if (mac is eFunction &&
                 ((eFunction)mac).isMacro())
             {
                 return(true);
             }
         }
     }
     return(false);
 }