Пример #1
0
        private ExpressionNode ExpressionUnary()
        {
            var unaryExpression = new ExpressionUnaryNode();

            if (_parser.Utilities.CompareTokenType(TokenType.OpComplement) ||
                _parser.Utilities.CompareTokenType(TokenType.OpIncrement) ||
                _parser.Utilities.CompareTokenType(TokenType.OpDecrement) ||
                _parser.Utilities.CompareTokenType(TokenType.OpBitAnd) ||
                _parser.Utilities.CompareTokenType(TokenType.OpBitOr) ||
                _parser.Utilities.CompareTokenType(TokenType.OpNot) ||
                _parser.Utilities.CompareTokenType(TokenType.OpComplement) ||
                _parser.Utilities.CompareTokenType(TokenType.OpBitXor) ||
                _parser.Utilities.CompareTokenType(TokenType.OpMultiplication) ||
                _parser.Utilities.CompareTokenType(TokenType.OpSubstraction))
            {
                unaryExpression.UnaryOperator = UnaryOperators();
            }

            var factorExpression = Factor();

            unaryExpression.Factor = factorExpression;

            return(unaryExpression);
        }
Пример #2
0
        private bool GetValueForUnaries(ExpressionUnaryNode unaryNode)
        {
            if (unaryNode != null && unaryNode.Type == TokenType.OpAddAndAssignment)
            {
                var a = new AddAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }
            if (unaryNode != null && unaryNode.Type == TokenType.OpSusbtractAndAssignment)
            {
                var a = new SubstractAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpMultiplyAndAssignment)
            {
                var a = new MultiplicationAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpDivideAssignment)
            {
                var a = new DivisionAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpModulusAssignment)
            {
                var a = new ModuleAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpBitShiftLeftAndAssignment)
            {
                var a = new ShiftLeftAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpBitShiftRightAndAssignment)
            {
                var a = new ShiftRightAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }
            if (unaryNode != null && unaryNode.Type == TokenType.OpBitwiseAndAssignment)
            {
                var a = new BitwiseAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpBitwiseXorAndAssignment)
            {
                var a = new BitwiseXorAndAssignmentOperatorNode()
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }

            if (unaryNode != null && unaryNode.Type == TokenType.OpBitwiseInclusiveOrAndAssignment)
            {
                var a = new BitwiseInclusiveOrAndAssignmentOperatorNode
                {
                    LeftOperand = new IdentifierExpression {
                        Name = LeftValue.Value
                    },
                    RightOperand = RightValue
                };

                a.Interpret();
                return(true);
            }
            return(false);
        }