Exemplo n.º 1
0
        public Leaf(eOperatorType eOperator, eLeafType eLeaf, string rawPart)
        {
            this.eOperator = eOperator;
            this.eLeaf     = eLeaf;
            this.rawPart   = rawPart;

            Parse();
        }
Exemplo n.º 2
0
        public static void Main(string [] args)
        {
            string displayString = string.Empty;

            Console.WriteLine("Please enter two numbers:");
            double firstUserInput  = double.Parse(Console.ReadLine());
            double secondUserInput = double.Parse(Console.ReadLine());

            Console.WriteLine("Please choose an operation for the 2 numbers");
            Program operatorMenu = new Program();

            operatorMenu.PrintOperatorOptions();
            int           userOperation   = int.Parse(Console.ReadLine());
            eOperatorType operatorOptions = (eOperatorType)userOperation;

            switch (operatorOptions)
            {
            case eOperatorType.Mult:    //multiplying the two numbers
            {
                displayString = string.Format("{0}*{1}={2}\n", firstUserInput, secondUserInput, firstUserInput * secondUserInput);
                break;
            }

            case eOperatorType.Sub:    //substructing the two numbers
            {
                if (firstUserInput > secondUserInput)
                {
                    displayString = string.Format("{0}-{1}={2}\n", firstUserInput, secondUserInput, firstUserInput - secondUserInput);
                }
                else
                {
                    displayString = string.Format("{0}-{1}={2}\n", secondUserInput, firstUserInput, secondUserInput - firstUserInput);
                }

                break;
            }

            case eOperatorType.Add:    //adding two numbers
            {
                displayString = string.Format("{0}+{1}={2}\n", firstUserInput, secondUserInput, firstUserInput + secondUserInput);
                break;
            }

            case eOperatorType.Div:    //dividing the two numbers
            {
                displayString = string.Format("{0}/{1}={2}\n", firstUserInput, secondUserInput, firstUserInput / secondUserInput);
                break;
            }

            case eOperatorType.Or:    //implementing the or operation
            {
                displayString = string.Format("{0}|{1}={2}\n", firstUserInput, secondUserInput, (byte)firstUserInput | (byte)secondUserInput);
                break;
            }

            default:    //if was chosen an operator that not in the list
            {
                displayString = string.Format("You Can't use this operator\n");
                break;
            }
            }

            Console.WriteLine(displayString);
        }
Exemplo n.º 3
0
 public static string OperatorTypeToString(eOperatorType operatorType)
 {
     return(operatorTypeToString[operatorType]);
 }
Exemplo n.º 4
0
        private void SplitOperators()
        {
            double number = 0;

            if (double.TryParse(part, out number))
            {
                return;
            }

            int           iBracket      = 0;
            string        childPart     = "";
            eOperatorType childOperator = eOperatorType.MULTIPLY;

            for (int i = 0; i < part.Length; i++)
            {
                char c = part[i];
                switch (c)
                {
                case '(':
                case '[':
                    iBracket++;
                    childPart += c;
                    break;

                case ')':
                case ']':
                    iBracket--;
                    childPart += c;
                    break;

                case '.':
                    if (iBracket == 0)
                    {
                        children.Add(new Leaf(childOperator, eLeaf, childPart));
                        if (ErrorCheck(false, 1))
                        {
                            return;
                        }
                        childOperator = eOperatorType.MULTIPLY;
                        childPart     = "";
                    }
                    else
                    {
                        childPart += c;
                    }
                    break;

                case '/':
                    if (iBracket == 0)
                    {
                        children.Add(new Leaf(childOperator, eLeaf, childPart));
                        if (ErrorCheck(false, 1))
                        {
                            return;
                        }
                        childOperator = eOperatorType.DIVIDE;
                        childPart     = "";
                    }
                    else
                    {
                        childPart += c;
                    }
                    break;

                case '+':
                    if (iBracket == 0)
                    {
                        children.Add(new Leaf(childOperator, eLeaf, childPart));
                        if (ErrorCheck(false, 1))
                        {
                            return;
                        }
                        childOperator = eOperatorType.ADD;
                        childPart     = "";
                    }
                    else
                    {
                        childPart += c;
                    }
                    break;

                case '-':
                    if (iBracket == 0)
                    {
                        children.Add(new Leaf(childOperator, eLeaf, childPart));
                        if (ErrorCheck(false, 1))
                        {
                            return;
                        }
                        childOperator = eOperatorType.SUBTRACT;
                        childPart     = "";
                    }
                    else
                    {
                        childPart += c;
                    }
                    break;

                case ' ':
                    break;

                default:
                    childPart += c;
                    break;
                }
            }
            if (children.Count > 0)
            {
                children.Add(new Leaf(childOperator, eLeaf, childPart));
                if (ErrorCheck(false, 1))
                {
                    return;
                }
            }
        }
Exemplo n.º 5
0
 public BasicCondition(ValuedTableColumn valuedTableColumn, eOperatorType operatorType)
 {
     this.valuedTableColumn = valuedTableColumn;
     this.operatorType      = operatorType;
     this.expressionString  = buildExpressionString();
 }