Exemplo n.º 1
0
        public override Expression VisitRelational_expression(Relational_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.LessThan(expression, current);
                }
                else if (op == ">")
                {
                    expression = Expression.GreaterThan(expression, current);
                }
                else if (op == "<=")
                {
                    expression = Expression.LessThanOrEqual(expression, current);
                }
                else if (op == ">=")
                {
                    expression = Expression.GreaterThanOrEqual(expression, current);
                }
                else
                {
                    throw new CompilationException($"Unsupported operation. Operation={op}", context);
                }
            }
            return(expression);
        }
Exemplo n.º 2
0
	public Relational_expressionContext relational_expression() {
		Relational_expressionContext _localctx = new Relational_expressionContext(_ctx, State);
		EnterRule(_localctx, 226, RULE_relational_expression);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 1243; shift_expression();
			State = 1248;
			_errHandler.Sync(this);
			_la = _input.La(1);
			while (((((_la - 81)) & ~0x3f) == 0 && ((1L << (_la - 81)) & ((1L << (GT - 81)) | (1L << (LT - 81)) | (1L << (LE - 81)) | (1L << (GE - 81)))) != 0)) {
				{
				{
				State = 1244;
				_la = _input.La(1);
				if ( !(((((_la - 81)) & ~0x3f) == 0 && ((1L << (_la - 81)) & ((1L << (GT - 81)) | (1L << (LT - 81)) | (1L << (LE - 81)) | (1L << (GE - 81)))) != 0)) ) {
				_errHandler.RecoverInline(this);
				}
				Consume();
				State = 1245; shift_expression();
				}
				}
				State = 1250;
				_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;
	}