Пример #1
0
        public static plt_node symbol_node(plt_node n)
        {
            plt_symbol ret = new plt_symbol();

            ret.point_to = n;
            return(ret);
        }
Пример #2
0
        public static plt_node make_exp(ref string exp)
        {
            plt_node ret = make_node(ref exp);

            // do with (
            if (ReferenceEquals(ret, left_brackets))
            {
                plt_list r = new plt_list();
                while (true)
                {
                    if (exp.Length <= 0)
                    {
                        break;
                    }
                    ret = make_exp(ref exp);
                    if (ReferenceEquals(ret, right_brackets))
                    {
                        break;
                    }
                    r.add(ret);
                }
                return(r);
            }
            //do with '
            if (ReferenceEquals(ret, plt_lambda.quote))
            {
                plt_list r = new plt_list();
                r.add(plt_lambda.quote);
                r.add(make_exp(ref exp));
                return(r);
            }

            //do nothing
            return(ret);
        }
Пример #3
0
        public static plt_node quote_node(plt_node n)
        {
            plt_list ret = new plt_list();

            ret.add(plt_lambda.quote);
            ret.add(n);
            return(ret);
        }
Пример #4
0
 public void set_member(int index, plt_node value)
 {
     if (index < _member.Count)
     {
         _member[index] = value;
     }
     else
     {
         _member.Add(value);
     }
 }
Пример #5
0
 public void set_member(string name, plt_node value)
 {
     if (name_map.ContainsKey(name))
     {
         _member[name_map[name]] = value;
     }
     else
     {
         name_map.Add(name, _member.Count);
         _member.Add(value);
     }
 }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            plt_list static_env = new plt_list();

            static_env.add("+", new plt_lambda_add());

            string   input = parsing.format_string(@"((lambda (a) (+ a 1)) 10)");
            plt_node ret   = parsing.make_exp(ref input);

            parsing.set_all_symbol_env(ret as plt_list, static_env);
            ret = plt_node.eval_node(ret);

            textBox1.Text = ret.ToString();
        }
Пример #7
0
        public override void mix_env(plt_list arg)
        {
            if (arg_name == null)
            {
                return;
            }
            plt_list env = new plt_list();

            for (int i = 0; i < arg_name._member.Count; i++)
            {
                string   name  = ((plt_symbol)arg_name.get_member(i)).name;
                plt_node value = arg.get_member(i + 1);
                env.set_member(name, value);
            }
            update_all_symbol(exp as plt_list, env);
        }
Пример #8
0
        public static plt_node eval_node(plt_node input)
        {
            plt_tail ret;

            do
            {
                if (input != null)
                {
                    ret = input.eval();
                }
                else
                {
                    ret = plt_tail.nil;
                }

                if (ret.is_tail)
                {
                    input = ret.value;
                }
            } while (ret.is_tail);

            return(ret.value);
        }
Пример #9
0
 public void add(string name, plt_node value)
 {
     name_map.Add(name, _member.Count);
     _member.Add(value);
 }
Пример #10
0
 public plt_tail(plt_node _value, bool _is_tail)
 {
     this.value = _value;
     this.is_tail = _is_tail;
 }
Пример #11
0
 public plt_tail()
 {
     value = null; is_tail = false;
 }
Пример #12
0
        public static plt_node eval_node(plt_node input)
        {
            plt_tail ret;
            do
            {
                if (input != null){
                    ret = input.eval();
                }
                else {
                    ret = plt_tail.nil;
                }

                if (ret.is_tail)
                {
                    input = ret.value;
                }
            } while (ret.is_tail);

            return ret.value;
        }
Пример #13
0
 public void set_member(string name, plt_node value)
 {
     if (name_map.ContainsKey(name))
     {
         _member[ name_map[name]]=value;
     }
     else
     {
         name_map.Add(name, _member.Count);
         _member.Add(value);
     }
 }
Пример #14
0
 public void set_member(int index, plt_node value)
 {
     if (index < _member.Count)
     {
         _member[index] = value;
     }
     else
     {
         _member.Add(value);
     }
 }
Пример #15
0
 public static plt_node quote_node(plt_node n)
 {
     plt_list ret = new plt_list();
     ret.add(plt_lambda.quote);
     ret.add(n);
     return ret;
 }
Пример #16
0
 public void add(string name, plt_node value)
 {
     name_map.Add(name, _member.Count);
     _member.Add(value);
 }
Пример #17
0
 public void add(plt_node value)
 {
     _member.Add(value);
 }
Пример #18
0
 public plt_tail()
 {
     value = null; is_tail = false;
 }
Пример #19
0
        public override plt_tail eval()
        {
            if (_member.Count == 0)
            {
                return(plt_tail.nil);
            }
            plt_node afirst = plt_node.eval_node(_member[0]);

            if (afirst == null)
            {
                return(plt_tail.nil);
            }


            {//特殊的函数
                //特殊情况-不解释参数
                if (ReferenceEquals(afirst, plt_lambda.quote))
                {
                    if (_member.Count < 2)
                    {
                        return(plt_tail.nil);
                    }
                    return(new plt_tail(_member[1], false));
                }
                if (ReferenceEquals(afirst, plt_lambda.make_lambda))
                {
                    plt_list_lambda ret = new plt_list_lambda();
                    ret.arg_name = _member[1] as plt_list;
                    ret.exp      = _member[2];
                    return(new plt_tail(ret, false));
                }
                if (ReferenceEquals(afirst, plt_lambda.cond))
                {
                    for (int i = 1; i + 1 < _member.Count; i += 2)
                    {
                        plt_node _if = plt_node.eval_node(_member[i]);
                        if (_if != null)
                        {
                            return(new plt_tail(_member[i + 1], true));
                        }
                    }
                }
                //宏 不解释参数
                plt_lambda lismacro = afirst as plt_lambda;
                if (lismacro != null && lismacro.ismacro)
                {
                    lismacro.mix_env(this);
                    return(lismacro.eval());
                }
            }
            plt_list args_eval = new plt_list();

            args_eval.add(afirst);
            for (int i = 1; i < _member.Count; i++)
            {
                args_eval.add(plt_node.eval_node(_member[i]));
            }
            plt_lambda func = afirst as plt_lambda;

            if (func != null)
            {
                func.mix_env(args_eval);
            }
            return(afirst.eval());
        }
Пример #20
0
 public void add( plt_node value)
 {
     _member.Add(value);
 }
Пример #21
0
 public static plt_node symbol_node(plt_node n)
 {
     plt_symbol ret = new plt_symbol();
     ret.point_to = n;
     return ret;
 }
Пример #22
0
 public plt_tail(plt_node _value, bool _is_tail)
 {
     this.value   = _value;
     this.is_tail = _is_tail;
 }