예제 #1
0
        public override Expression VisitAssignment(AssignmentContext context)
        {
            var unaryExpression = Visit(context.unary_expression());
            var expression      = Visit(context.expression());
            var op = context.assignment_operator().GetText();

            if (op == "=")
            {
                return(Expression.Assign(unaryExpression, expression));
            }
            if (op == "+=")
            {
                return(Expression.AddAssign(unaryExpression, expression));
            }
            if (op == "-=")
            {
                return(Expression.SubtractAssign(unaryExpression, expression));
            }
            if (op == "*=")
            {
                return(Expression.MultiplyAssign(unaryExpression, expression));
            }
            if (op == "/=")
            {
                return(Expression.DivideAssign(unaryExpression, expression));
            }
            if (op == "%=")
            {
                return(Expression.ModuloAssign(unaryExpression, expression));
            }
            if (op == "&=")
            {
                return(Expression.AndAssign(unaryExpression, expression));
            }
            if (op == "|=")
            {
                return(Expression.OrAssign(unaryExpression, expression));
            }
            if (op == "^=")
            {
                return(Expression.ExclusiveOrAssign(unaryExpression, expression));
            }
            if (op == "<<=")
            {
                return(Expression.LeftShiftAssign(unaryExpression, expression));
            }
            if (op == ">>=")
            {
                return(Expression.RightShiftAssign(unaryExpression, expression));
            }

            throw new CompilationException($"Unsupported operation. Operation={op}", context);
        }