public override Expression VisitMultiplicative_expression(Multiplicative_expressionContext context)
        {
            var expression = Visit(context.children[0]);

            for (int i = 1; i < context.children.Count - 1; i += 2)
            {
                var current = Visit(context.children[i + 1]);
                var op      = context.children[i].GetText();
                if (op == "*")
                {
                    expression = Expression.Multiply(expression, current);
                }
                else if (op == "/")
                {
                    expression = Expression.Divide(expression, current);
                }
                else if (op == "%")
                {
                    expression = Expression.Modulo(expression, current);
                }
                else
                {
                    throw new CompilationException($"Unsupported operation. Operation={op}", context);
                }
            }
            return(expression);
        }
Exemple #2
0
	public Multiplicative_expressionContext multiplicative_expression() {
		Multiplicative_expressionContext _localctx = new Multiplicative_expressionContext(_ctx, State);
		EnterRule(_localctx, 232, RULE_multiplicative_expression);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 1267; cast_expression();
			State = 1272;
			_errHandler.Sync(this);
			_la = _input.La(1);
			while (((((_la - 97)) & ~0x3f) == 0 && ((1L << (_la - 97)) & ((1L << (MUL - 97)) | (1L << (DIV - 97)) | (1L << (MOD - 97)))) != 0)) {
				{
				{
				State = 1268;
				_la = _input.La(1);
				if ( !(((((_la - 97)) & ~0x3f) == 0 && ((1L << (_la - 97)) & ((1L << (MUL - 97)) | (1L << (DIV - 97)) | (1L << (MOD - 97)))) != 0)) ) {
				_errHandler.RecoverInline(this);
				}
				Consume();
				State = 1269; cast_expression();
				}
				}
				State = 1274;
				_errHandler.Sync(this);
				_la = _input.La(1);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}