Example #1
0
            public OperationsStackItem(OperationStackItemKind kind, object value)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                //
                this.kind = kind;
                switch (kind)
                {
                case OperationStackItemKind.Delimiter: {
                    delimiter = (DelimiterKind)value;
                    break;
                }

                case OperationStackItemKind.Operation: {
                    operationName = (string)value;
                    break;
                }

                case OperationStackItemKind.PartialSignature: {
                    partialSignature = (PartialSignature)value;
                    break;
                }

                default: {
                    throw new InvalidOperationException("Unexpected item kind.");
                }
                }
            }
Example #2
0
            public void PushComplexOperatorFirstSignature(Operation operation)
            {
                PartialSignature signature = new PartialSignature();

                signature.OperationName       = operation.Name;
                signature.SignaturePartNumber = 1;
                //
                pushOperationAccordingToAssociationAndPriority(operation,
                                                               new OperationsStackItem(OperationStackItemKind.PartialSignature, signature));
            }
Example #3
0
            public void PushComplexOperatorNonFirstSignature(Operation operation, int partNumber)
            {
                int j = stack.Count - 1;

                while (j >= 0)
                {
                    if ((stack[j].Kind == OperationStackItemKind.PartialSignature) && (stack[j].PartialSignature.OperationName == operation.Name) && (stack[j].PartialSignature.SignaturePartNumber == partNumber - 1))
                    {
                        break;
                    }

                    switch (stack[j].Kind)
                    {
                    case OperationStackItemKind.Operation:
                    {
                        res.Add(new CompiledExpressionItem(CompiledExpressionItemKind.Operation, stack[j].OperationName));
                        stack.RemoveAt(j);
                        break;
                    }

                    default:
                    {
                        throw new MathProcessorException("Unexpected item in stack.");
                    }
                    }
                    j--;
                }
                if (j < 0)
                {
                    throw new CompilerSyntaxException("Braces syntax error.");
                }
                PartialSignature signature = new PartialSignature();

                signature.OperationName       = operation.Name;
                signature.SignaturePartNumber = partNumber;

                stack.Add(new OperationsStackItem(OperationStackItemKind.PartialSignature, signature));

                if (partNumber == operation.Signature.Length)
                {
                    for (int ii = 0; ii < partNumber; ii++)
                    {
                        stack.RemoveAt(stack.Count - 1);
                    }
                    stack.Add(new OperationsStackItem(OperationStackItemKind.Operation, operation.Name));
                }
            }
Example #4
0
 public OperationsStackItem(OperationStackItemKind kind, object value) {
     if (value == null)
         throw new ArgumentNullException("value");
     //
     this.kind = kind;
     switch (kind) {
         case OperationStackItemKind.Delimiter: {
             delimiter = (DelimiterKind) value;
             break;
         }
         case OperationStackItemKind.Operation: {
             operationName = (string) value;
             break;
         }
         case OperationStackItemKind.PartialSignature: {
             partialSignature = (PartialSignature) value;
             break;
         }
         default: {
             throw new InvalidOperationException("Unexpected item kind.");
         }
     }
 }
Example #5
0
 public void PushComplexOperatorNonFirstSignature(Operation operation, int partNumber) {
     int j = stack.Count - 1;
     while (j >= 0) {
         if ((stack[j].Kind == OperationStackItemKind.PartialSignature) && (stack[j].PartialSignature.OperationName == operation.Name) && (stack[j].PartialSignature.SignaturePartNumber == partNumber - 1)) {
             break;
         }
         //
         switch (stack[j].Kind) {
             case OperationStackItemKind.Operation: {
                 res.Add(new CompiledExpressionItem(CompiledExpressionItemKind.Operation, stack[j].OperationName));
                 stack.RemoveAt(j);
                 break;
             }
             default: {
                 throw new MathProcessorException("Unexpected item in stack.");
             }
         }
         j--;
     }
     if (j < 0)
         throw new CompilerSyntaxException("Braces syntax error.");
     PartialSignature signature = new PartialSignature();
     signature.OperationName = operation.Name;
     signature.SignaturePartNumber = partNumber;
     //
     stack.Add(new OperationsStackItem(OperationStackItemKind.PartialSignature, signature));
     //
     if (partNumber == operation.Signature.Length) {
         for (int ii = 0; ii < partNumber; ii++) {
             stack.RemoveAt(stack.Count - 1);
         }
         stack.Add(new OperationsStackItem(OperationStackItemKind.Operation, operation.Name));
     }
 }
Example #6
0
 public void PushComplexOperatorFirstSignature(Operation operation) {
     PartialSignature signature = new PartialSignature();
     signature.OperationName = operation.Name;
     signature.SignaturePartNumber = 1;
     //
     pushOperationAccordingToAssociationAndPriority(operation,
                                                    new OperationsStackItem(OperationStackItemKind.PartialSignature, signature));
 }