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."); } } }
public void PushComplexOperatorFirstSignature(Operation operation) { PartialSignature signature = new PartialSignature(); signature.OperationName = operation.Name; signature.SignaturePartNumber = 1; // pushOperationAccordingToAssociationAndPriority(operation, new OperationsStackItem(OperationStackItemKind.PartialSignature, signature)); }
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)); } }
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."); } } }
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)); } }