Пример #1
0
 protected static void AssertArgsMinimum(string name, string message, int expected, int given, LinkedList <Value> argv, Syntax expression)
 {
     if (given < expected)
     {
         throw SchemeError.ArityError(name, message, expected, given, argv, expression);
     }
 }
Пример #2
0
Файл: Cond.cs Проект: hww/VARP
        // (cond () ...)
        public static AST Expand(Syntax stx, Environment env)
        {
            var list = stx.AsLinkedList <Value>();    //< list of syntax objects
            var argc = GetArgsCount(list);

            var keyword = list[0].AsSyntax();
            LinkedList <Value> allcases = null;
            LinkedList <Value> elsecase = null;

            var curent = list.GetNodeAtIndex(1);

            while (curent != null)
            {
                var conditional_stx = curent.Value.AsSyntax();

                if (elsecase != null)
                {
                    throw SchemeError.SyntaxError("cond", "unexpected expression after condition's else clause", conditional_stx);
                }

                if (conditional_stx.IsExpression)
                {
                    // Get single conditional expression
                    var conditional_list = conditional_stx.AsLinkedList <Value>();

                    // Check arguments count, should be 2 for each condition
                    var size = conditional_list.Count;
                    if (size != 2)
                    {
                        throw SchemeError.ArityError("cond", "arity mismatch", 2, size, conditional_list, conditional_stx);
                    }

                    // Now get condition and it's expression
                    var var = conditional_list[0].AsSyntax();
                    var val = conditional_list[1].AsSyntax();

                    if (var.IsIdentifier && var.AsIdentifier() == Symbol.ELSE)
                    {
                        var ast = AstBuilder.ExpandInternal(val, env);
                        elsecase = ValueLinkedList.FromArguments(new Value(var), new Value(ast));
                    }
                    else
                    {
                        var cond_       = AstBuilder.ExpandInternal(var, env);
                        var then_       = AstBuilder.ExpandInternal(val, env);
                        var single_cond = ValueLinkedList.FromArguments(cond_, then_);
                        if (allcases == null)
                        {
                            allcases = new LinkedList <Value>();
                        }
                        allcases.AddLast(new Value(single_cond));
                    }
                }
                else
                {
                    throw SchemeError.SyntaxError("cond", "Expected condition's expression list", conditional_stx);
                }
                curent = curent.Next;
            }

            return(new AstCondition(stx, keyword, allcases, elsecase));
        }