示例#1
0
        public void negTest()
        {
            CNumber_Integer target   = new CNumber_Integer(0.0); // TODO: Passenden Wert initialisieren
            CNumber         expected = null;                     // TODO: Passenden Wert initialisieren
            CNumber         actual;

            actual = target.neg();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Überprüfen Sie die Richtigkeit dieser Testmethode.");
        }
 double GetNumberValue(CNumber numb)
 {
     if (numb is CReal)
     {
         return(((CReal)numb).Value);
     }
     else
     if (numb is CInteger)
     {
         return(((CInteger)numb).Value);
     }
     else
     {
         return(double.NaN);
     }
 }
示例#3
0
        /// <summary>
        /// Evaluates parenthesis in the equation and insures they are handled properly according to the Order of Operations.
        /// Because this is last in the chain, it also evaluates Variable and Function names.
        /// </summary>
        /// <returns>CValue object that holds an operation.</returns>
        private CValue Paren()
        {
            bool   isFunction = false;
            CValue value      = null;

            if (_currentToken == null)
            {
                throw new InvalidEquationException("Unexpected end of equation (are you missing an operator argument?).");
            }

            if (_currentToken.ToString() == "(")
            {
                NextToken();

                value = Or();

                if (string.Equals(_currentToken, ","))
                {
                    return(value);
                }
            }
            else
            {
                switch (_currentToken.TokenType)
                {
                case TokenType.Number:
                    value = new CNumber(_currentToken.ToString());
                    break;

                case TokenType.Letter:
                    if (string.Equals(_nextToken, "("))
                    {
                        if (!_functions.ContainsKey(_currentToken.ToString()))
                        {
                            throw new InvalidFunctionException(_currentToken.ToString());
                        }

                        CFunction function   = _functions[_currentToken.ToString()];
                        var       parameters = new List <CValue>();

                        do
                        {
                            NextToken();

                            try
                            {
                                value = Paren();
                            }
                            catch (InvalidEquationException)
                            {
                                throw new ArgumentCountException(parameters.Count);
                            }

                            parameters.Add(value);
                        }while (string.Equals(_currentToken, ","));

                        isFunction = true;

                        value = function.SetParameters(parameters);

                        if (string.Equals(_currentToken, ")") && parameters.Count > 1)
                        {
                            NextToken();
                        }
                    }
                    else
                    {
                        value = GetVariableByName(_currentToken.ToString());
                    }

                    break;
                }
            }

            if (!isFunction)
            {
                NextToken();
            }

            return(value);
        }
示例#4
0
 private static void Write(CNumber obj)
 {
     Console.Write("num:{0}", obj.ToString());
 }
示例#5
0
 private static void ExtractText(CNumber obj, StringBuilder target) { /* nothing */ }
        /// <summary>
        /// Paren() : This method evaluates Parenthesis in the equation and
        ///		insures they are handled properly according to the Order of Operations. Because this is last in the chain,
        ///		it also evaluates Variable and Function names.
        /// </summary>
        /// <returns>CValue object that holds an operation.</returns>
        private CValue Paren()
        {
            bool bFunc = false;
            CValue oValue = null;

            if (m_currentToken.ToString() == "(")
            {
                PositionNextToken();

                oValue = Relational();

                if (m_currentToken.ToString() == ",")
                    return oValue;

                if (m_currentToken.ToString() != ")")
                    throw new ApplicationException("Unmatched parenthesis in equation.");

            }
            else
            {
                switch (m_currentToken.TokenType)
                {
                    case Parser.CharType.CT_NUMBER:
                        oValue = new CNumber(m_currentToken.ToString());
                        break;

                    case Parser.CharType.CT_LETTER:
                        {
                            if (m_nextToken.ToString() == "(")
                            {
                                int iIdx = m_slFunctions.IndexOfKey(m_currentToken.ToString());

                                if (iIdx < 0)
                                    throw new ApplicationException("Function not found - " + m_currentToken.ToString());

                                CFunction oFunc = (CFunction)m_slFunctions.GetByIndex(iIdx);

                                ArrayList alValues = new ArrayList();

                                PositionNextToken();

                                do
                                {
                                    PositionNextToken();
                                    oValue = AddSub();

                                    alValues.Add(oValue);
                                } while (m_currentToken.ToString() != ")" && m_currentToken!="");

                                bFunc = true;

                                oValue = oFunc.CreateInstance(alValues);

                                PositionNextToken();

                            }
                            else
                                oValue = GetVariableByName(m_currentToken.ToString());

                            break;
                        }
                }

            }

            if( !bFunc )
                PositionNextToken();

            return oValue;
        }
示例#7
0
        public Environment()
        {
            Output    = new Output();
            EmptyArgs = new SArgs(this);
            True      = new LBoolean(this, true);
            False     = new LBoolean(this, false);
            Undefined = new LUndefined(this);
            Null      = new LNull(this);

            GlobalObject              = new BGlobal(this);
            GlobalEnvironment         = new SLexicalEnvironment(this, new SObjectEnvironmentRecord(this, GlobalObject, false), null);
            MathObject                = new BMath(this);
            JsonObject                = new BJson(this);
            ObjectConstructor         = new CObject(this);
            FunctionConstructor       = new CFunction(this);
            ArrayConstructor          = new CArray(this);
            StringConstructor         = new CString(this);
            BooleanConstructor        = new CBoolean(this);
            NumberConstructor         = new CNumber(this);
            DateConstructor           = new CDate(this);
            RegExpConstructor         = new CRegExp(this);
            ErrorConstructor          = new CError(this);
            EvalErrorConstructor      = new CEvalError(this);
            RangeErrorConstructor     = new CRangeError(this);
            ReferenceErrorConstructor = new CReferenceError(this);
            SyntaxErrorConstructor    = new CSyntaxError(this);
            TypeErrorConstructor      = new CTypeError(this);
            UriErrorConstructor       = new CUriError(this);
            ObjectPrototype           = new PObject(this);
            FunctionPrototype         = new PFunction(this);
            ArrayPrototype            = new PArray(this);
            StringPrototype           = new PString(this);
            BooleanPrototype          = new PBoolean(this);
            NumberPrototype           = new PNumber(this);
            DatePrototype             = new PDate(this);
            RegExpPrototype           = new PRegExp(this);
            ErrorPrototype            = new PError(this);
            EvalErrorPrototype        = new PEvalError(this);
            RangeErrorPrototype       = new PRangeError(this);
            ReferenceErrorPrototype   = new PReferenceError(this);
            SyntaxErrorPrototype      = new PSyntaxError(this);
            TypeErrorPrototype        = new PTypeError(this);
            UriErrorPrototype         = new PUriError(this);

            GlobalObject.Initialize();
            MathObject.Initialize();
            JsonObject.Initialize();
            ObjectConstructor.Initialize();
            FunctionConstructor.Initialize();
            ArrayConstructor.Initialize();
            StringConstructor.Initialize();
            BooleanConstructor.Initialize();
            NumberConstructor.Initialize();
            DateConstructor.Initialize();
            RegExpConstructor.Initialize();
            ErrorConstructor.Initialize();
            EvalErrorConstructor.Initialize();
            RangeErrorConstructor.Initialize();
            ReferenceErrorConstructor.Initialize();
            SyntaxErrorConstructor.Initialize();
            TypeErrorConstructor.Initialize();
            UriErrorConstructor.Initialize();
            ObjectPrototype.Initialize();
            FunctionPrototype.Initialize();
            ArrayPrototype.Initialize();
            StringPrototype.Initialize();
            BooleanPrototype.Initialize();
            NumberPrototype.Initialize();
            DatePrototype.Initialize();
            RegExpPrototype.Initialize();
            ErrorPrototype.Initialize();
            EvalErrorPrototype.Initialize();
            RangeErrorPrototype.Initialize();
            ReferenceErrorPrototype.Initialize();
            SyntaxErrorPrototype.Initialize();
            TypeErrorPrototype.Initialize();
            UriErrorPrototype.Initialize();
        }
示例#8
0
    /// <summary>
    /// Paren() : This method evaluates Parenthesis in the equation and
    ///		insures they are handled properly according to the Order of Operations. Because this is last in the chain,
    ///		it also evaluates Variable and Function names.
    /// </summary>
    /// <returns>CValue object that holds an operation.</returns>
    private CValue Paren()
    {
        bool   bFunc  = false;
        CValue oValue = null;

        if (m_currentToken.ToString() == "(")
        {
            PositionNextToken();


            oValue = Relational();

            if (m_currentToken.ToString() == ",")
            {
                return(oValue);
            }

            if (m_currentToken.ToString() != ")")
            {
                throw new ApplicationException("Unmatched parenthesis in equation.");
            }
        }
        else
        {
            switch (m_currentToken.TokenType)
            {
            case Parser.CharType.CT_NUMBER:
                oValue = new CNumber(m_currentToken.ToString());
                break;

            case Parser.CharType.CT_LETTER:
            {
                if (m_nextToken.ToString() == "(")
                {
                    int iIdx = m_slFunctions.IndexOfKey(m_currentToken.ToString());

                    if (iIdx < 0)
                    {
                        throw new ApplicationException("Function not found - " + m_currentToken.ToString());
                    }

                    CFunction oFunc = (CFunction)m_slFunctions.GetByIndex(iIdx);

                    ArrayList alValues = new ArrayList();

                    do
                    {
                        PositionNextToken();
                        oValue = Paren();

                        alValues.Add(oValue);
                    } while (m_currentToken.ToString() == ",");
                    if (m_currentToken.ToString() == ")")
                    {
                        PositionNextToken();
                    }


                    bFunc = true;


                    oValue = oFunc.CreateInstance(alValues);
                }
                else
                {
                    oValue = GetVariableByName(m_currentToken.ToString());
                }

                break;
            }
            }
        }

        if (!bFunc)
        {
            PositionNextToken();
        }

        return(oValue);
    }