Example #1
0
        public void Resolve_NotExists()
        {
            NativeLibrary library = new NativeLibrary("math_msvc14.dll");

            OperatorCallbacks.OperatorFunction result = library.Resolve <OperatorCallbacks.OperatorFunction>("_not_exists_");

            Assert.IsNull(result);
        }
Example #2
0
        public void Resolve_Pow()
        {
            NativeLibrary library = new NativeLibrary("math_msvc14.dll");

            OperatorCallbacks.OperatorFunction pow = library.Resolve <OperatorCallbacks.OperatorFunction>("operator_pow");
            double result = pow(2, 3);

            Assert.AreEqual(Math.Pow(2, 3), result);
        }
Example #3
0
        /// <summary>
        /// Parses operator
        /// </summary>
        /// <param name="input">Input character</param>
        /// <param name="precedingItem">Preceding item type</param>
        /// <param name="postfixStack">Postfix stack</param>
        /// <param name="operatorsStack">Operators stack</param>
        /// <returns>Returns true if successful; false, otherwise</returns>
        private bool ParseOperator(char input, ref PrecedingItem precedingItem, Stack <PostfixItem> postfixStack, Stack <PostfixItem> operatorsStack)
        {
            string name = char.ToString(input);

            OperatorCallbacks.OperatorFunction function = ResolveOperator(name);
            if (function != null)
            {
                if (precedingItem == PrecedingItem.Operator || precedingItem == PrecedingItem.OperatorUnary ||
                    precedingItem == PrecedingItem.ParenthesesStart)
                {
                    return(false);
                }

                while (operatorsStack.Count > 0)
                {
                    PostfixItem current = operatorsStack.Peek();

                    if (current is InternalCommandBlock)
                    {
                        break;
                    }

                    Operator op;
                    if ((op = current as Operator) != null && IsHigherPrecedence(op.Name, name))
                    {
                        break;
                    }

                    OperatorUnary opu;
                    if ((opu = current as OperatorUnary) != null && IsHigherPrecedence(opu.Name, name))
                    {
                        break;
                    }

                    operatorsStack.Pop();
                    postfixStack.Push(current);
                }

                operatorsStack.Push(new Operator {
                    Name     = name,
                    Function = function
                });

                precedingItem = PrecedingItem.Operator;
                return(true);
            }

            return(false);
        }