Ejemplo n.º 1
0
        public SELambda(SExprAtomic ha, SExprComp c)
        {
            if (c.Atomics.Count < 2)
            {
                throw new VMException("missing lambda body", ha);
            }
            if (!(c.Atomics[0] is SExprComp))
            {
                throw new VMException("the first argument must be the declaration", ha);
            }

            arguments = SELambda.CompoundToArguments(c.Atomics.Pop() as SExprComp, ha);
            body      = SExpression.Cast(c.Atomics.Pop());
        }
Ejemplo n.º 2
0
        public SEDefun(SExprAtomic ha, SExprComp c)
        {
            if (c.Atomics.Count < 3)
            {
                throw new VMException("missing function body", ha);
            }
            if (!(c.Atomics[1] is SExprComp))
            {
                throw new VMException("the second argument must be the declaration", ha);
            }

            var n = c.Atomics.Pop();

            if (!(n is SExprAtomic) || (n as SExprAtomic).Token.TType != SToken.TokenType.ATOMIC)
            {
                throw new VMException("function name must be an atom", ha);
            }

            func      = (string)(n as SExprAtomic).Token.TValue;
            arguments = SELambda.CompoundToArguments(c.Atomics.Pop() as SExprComp, ha);

            var tmp = c.Atomics.Pop();

            if (tmp is SExprAtomic && (tmp as SExprAtomic).Token.TType == SToken.TokenType.STRING)
            {
                description = (string)(tmp as SExprAtomic).Token.TValue;
                if (c.Atomics.Count == 0)
                {
                    throw new VMException("missing function body", ha);
                }
                body = SExpression.Cast(c.Atomics.Pop());
            }
            else
            {
                body = SExpression.Cast(tmp);
            }
        }