Exemplo n.º 1
0
        public IGeneralOperator oneWaycreatingIOperator(AssemblyItem assemblyItem)
        {
            IGeneralOperator iopExtender = null;

            if (assemblyItem != null)
            {
                Assembly ass     = assemblyItem.assembly;
                string   assName = assemblyItem.assemblyFullName;
                iopExtender = (IGeneralOperator)ass.CreateInstance(assName);
            }
            return(iopExtender);
        }
Exemplo n.º 2
0
        public IGeneralOperator getIOperatorFromDllFilePath(string dllFilePath)
        {
            IGeneralOperator iopExtender  = null;
            AssemblyItem     assemblyItem = getIOpertorAssemblyInfo(dllFilePath);

            if (assemblyItem != null)
            {
                //while instatiation, _operator registers its value into CalcOperator.TypeObserver
                iopExtender = oneWaycreatingIOperator(assemblyItem);
            }
            return(iopExtender);
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     this.iOperator = null;
     this.Dispose();
 }
Exemplo n.º 4
0
        public Queue <string> getReversedPolishNotation()
        {
            //typesList is filled in CalculationController
            Dictionary <string, IGeneralOperator> operators = typeMan.typesList;


            //loop over input

            /**
             * Read a token.
             **/
            foreach (string s in inputToInfix)
            {
                //operands

                /**
                 * If the token is a number, then push it to the output queue.
                 **/
                //naively trusts that if it is not an operator, it is numeric
                if (!operators.ContainsKey(s))
                {
                    queue.Enqueue(s);//is number
                }
                else//is operator or parenthesis
                {
                    IGeneralOperator someOperator = operators[s];
                    if (someOperator.isParenthesis)
                    {
                        if (someOperator.value == "(")
                        {
                            stack.Push(someOperator.value);
                        }
                        else if (someOperator.value == ")")
                        {
                            IGeneralOperator fromStack = operators[stack.Pop()];
                            while (!fromStack.isParenthesis && fromStack.value != "(")
                            {
                                if (stack.Count() == 0)
                                {
                                    this.error = "There are mismatched parentheses.";
                                    break;
                                }
                                queue.Enqueue(fromStack.value);
                                fromStack = operators[stack.Pop()];
                            }
                        }
                    }
                    else //no parenthesis, but operator
                    {
                        if (stack.Count() != 0)
                        {
                            IOperator someOp1 = (IOperator)someOperator;
                            try
                            {
                                IOperator someOp2 = (IOperator)operators[stack.Peek()];
                                while (stack.Count() != 0 &&
                                       ((someOp1.precedence <= someOp2.precedence && someOp1.associativity == IOperator.Associativity.left) ||
                                        someOp1.precedence < someOp2.precedence && someOp1.associativity == IOperator.Associativity.right))
                                {
                                    queue.Enqueue(stack.Pop());
                                    someOp2 = (IOperator)operators[stack.Peek()];
                                }
                            }
                            catch { }
                            stack.Push(someOp1.value);
                        }
                        else
                        {
                            stack.Push(s);
                        }
                    }
                }
            }//END OF for

            /**
             * When there are no more tokens to read:
             * While there are still operator tokens in the stack:
             * If the operator token on the top of the stack is a parenthesis, then there are mismatched parentheses.
             * Pop the operator onto the output queue.
             **/
            if (stack.Count() != 0)
            {
                string chekcParenthesis = stack.Peek();
                if (chekcParenthesis == "(" || chekcParenthesis == ")")
                {
                    this.error += "Finally, there are mismatched parentheses.";
                }
                else
                {
                    //finally add remaining operators from stack to queue
                    while (stack.Count() > 0)
                    {
                        queue.Enqueue(stack.Pop());
                    }
                }
            }
            return(queue);
        }