Exemple #1
0
        // TODO accept string
        public Complex(iObject real, iObject imag) : base(Class.COMPLEX)
        {
            if (NilClass.IsNil(real) || NilClass.IsNil(imag))
            {
                throw new TypeError("can't convert nil into Complex");
            }

            if (!real.IsA(Class.INTEGER) && !real.IsA(Class.FLOAT))
            {
                throw new TypeError($"can't convert {real.Class} into Complex");
            }

            if (!imag.IsA(Class.INTEGER) && !imag.IsA(Class.FLOAT))
            {
                throw new TypeError($"can't convert {imag.Class} into Complex");
            }

            Real = real;
            Imag = imag;
        }
        public iObject Visit(Ast <Token> ast)
        {
            if (ast.IsList)
            {
                iObject result = new NilClass();
                foreach (var child in ast.List)
                {
                    result = child.Accept(this);
                }

                return(result);
            }

            try
            {
                return(Actions[ast.Value.Type](ast));
            }
            catch (KeyNotFoundException e)
            {
                throw new ArgumentException($"Token type {ast.Value.Type} not registered.", "ast", e);
            }
        }