示例#1
0
        private void PutOperationToken(RusticOperation operation)
        {
            if (nextOperation != null)
            {
                if (operation.IsLeftUnary)
                {
                    PutLeftOperationToken(operation);
                    return;
                }
                else
                {
                    throw new Exception("Unexpected operator found");
                }
            }

            operation.priorityOffset = priorityOffset;
            if (operation.GetPriorityWithOffset() <= (int)RusticOperation.Priority.Ignored)
            {
                PutOperationOfEqualOrIgnoredPriority(operation);
            }
            else
            if ((operation.HasRightToLeftPrecedence() && currentStack.priority <= operation.GetPriorityWithOffset()) || currentStack.priority < operation.GetPriorityWithOffset()) // TO-DO: Alterar para inserir operadores RTL
            {
                PutOperationOfHigherPriority(operation);
            }
            else
            if (currentStack.priority > operation.GetPriorityWithOffset())
            {
                PutOperationOfLowerPriority(operation);
            }
            else
            {
                PutOperationOfEqualOrIgnoredPriority(operation);
            }
        }
示例#2
0
 private void PutCustomValueToken(RusticValueEvaluator value)
 {
     if (nextOperation == null)
     {
         throw new Exception($"Expecting operator, but received operand ({value.GetType().Name})");
     }
     nextOperation.parameter = value;
     currentStack.operations.Add(nextOperation);
     nextOperation = null;
 }
示例#3
0
        private void PutOperationOfLowerPriority(RusticOperation operation)
        {
            nextOperation = operation;
            while (currentStack.priority > operation.GetPriorityWithOffset())
            {
                currentStack = currentStack.parent;
            }

            if (currentStack.priority < operation.GetPriorityWithOffset())
            {
                PutOperationOfHigherPriority(operation);
            }
        }
示例#4
0
 private void ChangePriority(int addition)
 {
     priorityOffset += addition;
     if (addition > 0)
     {
         RusticStack newStack = new RusticStack(stacks.Count, currentStack, priorityOffset + RusticOperation.FirstPriority);
         nextOperation.parameter = new Evaluators.StackReference(newStack);
         currentStack.operations.Add(nextOperation);
         int index = stacks.IndexOf(currentStack);
         stacks.Insert(index + 1, newStack);
         currentStack  = newStack;
         nextOperation = new Operations.Set();
     }
 }
示例#5
0
        public RusticExprBuilder(RusticExpr expression, RusticContext context)
        {
            if (expression?.stacks.Count > 0)
            {
                throw new Exception("RusticExpr instance was already built and should not be built again. Did you intend to ResetExpression?");
            }

            this.expression = expression;
            this.context    = context;
            nextOperation   = new Operations.Set();
            priorityOffset  = 0;
            stacks?.Add(new RusticStack(0, null, 1));
            currentStack = stacks?[0];
        }
示例#6
0
        private void PutOperationOfHigherPriority(RusticOperation operation)
        {
            nextOperation = operation;
            RusticOperation      lastOperationFromStack = currentStack.operations[currentStack.operations.Count - 1];
            RusticValueEvaluator lastOperationValue     = lastOperationFromStack.parameter;
            RusticStack          newStack = new RusticStack(stacks.Count, currentStack, operation.GetPriorityWithOffset());

            lastOperationFromStack.parameter = new Evaluators.StackReference(newStack);
            RusticOperation newSetOperation = new Operations.Set();

            newSetOperation.parameter = lastOperationValue;
            newStack.operations.Add(newSetOperation);
            int index = stacks.IndexOf(currentStack);

            stacks.Insert(index + 1, newStack);
            currentStack = newStack;
        }
示例#7
0
        private void PutLeftOperationToken(RusticOperation operation)
        {
            if (currentStack.priority == operation.GetPriorityWithOffset())
            {
                currentStack.operations.Add(operation);
            }
            else
            {
                RusticStack newStack = new RusticStack(stacks.Count, currentStack, operation.GetPriorityWithOffset());
                newStack.operations.Add(operation);
                int index = stacks.IndexOf(currentStack);
                stacks.Insert(index + 1, newStack);

                PutCustomValueToken(new Evaluators.StackReference(newStack));
                currentStack  = newStack;
                nextOperation = new Operations.Set();
            }
        }
示例#8
0
        public void Prepare()
        {
            List <RusticOperation> moveLeftUnaryOperations = new List <RusticOperation>();

            foreach (RusticOperation operation in operations)
            {
                if (operation.IsLeftUnary)
                {
                    moveLeftUnaryOperations.Add(operation);
                }
            }

            for (int i = moveLeftUnaryOperations.Count - 1; i >= 0; i--)
            {
                RusticOperation operation = moveLeftUnaryOperations[i];
                operations.Remove(operation);
                operations.Add(operation);
            }

            PreviewResultType();
        }
示例#9
0
 public OperationCapture(string pattern, RusticOperation operation) : base(pattern, RusticTokenMode.Operation, (p, c) => Activator.CreateInstance(operation.GetType()))
 {
 }
示例#10
0
 private void PutOperationOfEqualOrIgnoredPriority(RusticOperation operation)
 {
     nextOperation = operation;
 }