Exemple #1
0
        private static ExpressionBase ParseMathematic(PositionalTokenizer tokenizer, ExpressionBase left, MathematicOperation operation, int joinerLine, int joinerColumn)
        {
            OperationPriority priority;

            switch (operation)
            {
            case MathematicOperation.Add:
                if (left is StringConstantExpression)
                {
                    priority = OperationPriority.AppendString;
                    break;
                }
                priority = OperationPriority.AddSubtract;
                break;

            case MathematicOperation.Subtract:
                priority = OperationPriority.AddSubtract;
                break;

            case MathematicOperation.Multiply:
            case MathematicOperation.Divide:
            case MathematicOperation.Modulus:
                priority = OperationPriority.MulDivMod;
                break;

            case MathematicOperation.BitwiseAnd:
                priority = OperationPriority.BitwiseAnd;
                break;

            default:
                return(new ParseErrorExpression("Unknown operator: " + operation));
            }

            var right = ParseExpression(tokenizer, priority);

            switch (right.Type)
            {
            case ExpressionType.ParseError:
                return(right);

            case ExpressionType.Comparison:     // will be rebalanced
            case ExpressionType.Conditional:    // will be rebalanced
            case ExpressionType.FloatConstant:
            case ExpressionType.FunctionCall:
            case ExpressionType.IntegerConstant:
            case ExpressionType.Mathematic:
            case ExpressionType.StringConstant:
            case ExpressionType.Variable:
                break;

            default:
                var expressionTokenizer = tokenizer as ExpressionTokenizer;
                if (expressionTokenizer != null)
                {
                    expressionTokenizer.QueueExpression(right);
                }

                right = new KeywordExpression(MathematicExpression.GetOperatorCharacter(operation).ToString(), joinerLine, joinerColumn);
                return(ParseError(tokenizer, "Incompatible mathematical operation", right));
            }

            if (priority == OperationPriority.AddSubtract)
            {
                var mathematicRight = right as MathematicExpression;
            }

            return(new MathematicExpression(left, operation, right));
        }
Exemple #2
0
        private static ExpressionBase ParseMathematic(PositionalTokenizer tokenizer, ExpressionBase left, MathematicOperation operation, int joinerLine, int joinerColumn)
        {
            var right = ExpressionBase.Parse(tokenizer);

            switch (right.Type)
            {
            case ExpressionType.ParseError:
                return(right);

            case ExpressionType.Comparison:
            case ExpressionType.Conditional:
            case ExpressionType.Dictionary:
            case ExpressionType.FunctionCall:
            case ExpressionType.IntegerConstant:
            case ExpressionType.Mathematic:
            case ExpressionType.StringConstant:
            case ExpressionType.Variable:
                break;

            default:
                ParseError(tokenizer, "incompatible mathematical operation", new KeywordExpression(MathematicExpression.GetOperatorCharacter(operation).ToString(), joinerLine, joinerColumn));
                break;
            }

            return(new MathematicExpression(left, operation, right));
        }