public override object VisitAssignment([NotNull] AssignmentContext context) { // checking if 'Sylvre' is being declared and assigned to. Sylvre is a builtin library so disallowed if (context.variable_complex_reference_left().variable_reference().GetText() == "Sylvre") { _transpileErrors.Add(new SylvreTranspileError { CharPositionInLine = context.variable_complex_reference_left().Start.Column + 1, // Column number 1 behind, zero based index? Line = context.variable_complex_reference_left().Start.Line, Symbol = context.variable_complex_reference_left().Start.Text, Message = _sylvreAssignmentDisallowedMessage }); } VisitVariable_complex_reference_left(context.variable_complex_reference_left()); VisitAssignment_operator(context.assignment_operator()); if (context.conditional_expression() != null) { VisitConditional_expression(context.conditional_expression()); } else { VisitArray_assignment(context.array_assignment()); } return(null); }
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); }