public override void EnterUnaryExpr([NotNull] UnaryExprContext context)
        {
            Logger.Write("Unary operators are not handled properly.", LogType.Warning);

            this.Result.Insert(new OperatorExpression(Result, context.prefix.Text, context));
            context.expression().EnterRule(this);
            this.Result.Insert(new ConstIntExpression(Parent, context, 0));
        }
Exemple #2
0
    private ExprContext expr(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int         _parentState     = State;
        ExprContext _localctx        = new ExprContext(Context, _parentState);
        ExprContext _prevctx         = _localctx;
        int         _startState      = 2;

        EnterRecursionRule(_localctx, 2, RULE_expr, _p);
        int _la;

        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 20;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case T__0:
                {
                    _localctx = new ParensExprContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 8; Match(T__0);
                    State = 9; expr(0);
                    State = 10; Match(T__1);
                }
                break;

                case OP_ADD:
                case OP_SUB:
                {
                    _localctx = new UnaryExprContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 12;
                    ((UnaryExprContext)_localctx).op = TokenStream.LT(1);
                    _la = TokenStream.LA(1);
                    if (!(_la == OP_ADD || _la == OP_SUB))
                    {
                        ((UnaryExprContext)_localctx).op = ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                    State = 13; expr(6);
                }
                break;

                case ID:
                {
                    _localctx = new FuncExprContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 14; ((FuncExprContext)_localctx).func = Match(ID);
                    State     = 15; Match(T__0);
                    State     = 16; expr(0);
                    State     = 17; Match(T__1);
                }
                break;

                case NUM:
                {
                    _localctx = new NumberExprContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 19; ((NumberExprContext)_localctx).value = Match(NUM);
                }
                break;

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 33;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            State = 31;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 1, Context))
                            {
                            case 1:
                            {
                                _localctx = new InfixExprContext(new ExprContext(_parentctx, _parentState));
                                ((InfixExprContext)_localctx).left = _prevctx;
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 22;
                                if (!(Precpred(Context, 5)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 5)");
                                }
                                State = 23; ((InfixExprContext)_localctx).op = Match(OP_POW);
                                State = 24; ((InfixExprContext)_localctx).right = expr(5);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new InfixExprContext(new ExprContext(_parentctx, _parentState));
                                ((InfixExprContext)_localctx).left = _prevctx;
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 25;
                                if (!(Precpred(Context, 4)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                }
                                State = 26;
                                ((InfixExprContext)_localctx).op = TokenStream.LT(1);
                                _la = TokenStream.LA(1);
                                if (!(_la == OP_MUL || _la == OP_DIV))
                                {
                                    ((InfixExprContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 27; ((InfixExprContext)_localctx).right = expr(5);
                            }
                            break;

                            case 3:
                            {
                                _localctx = new InfixExprContext(new ExprContext(_parentctx, _parentState));
                                ((InfixExprContext)_localctx).left = _prevctx;
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 28;
                                if (!(Precpred(Context, 3)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                }
                                State = 29;
                                ((InfixExprContext)_localctx).op = TokenStream.LT(1);
                                _la = TokenStream.LA(1);
                                if (!(_la == OP_ADD || _la == OP_SUB))
                                {
                                    ((InfixExprContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 30; ((InfixExprContext)_localctx).right = expr(4);
                            }
                            break;
                            }
                        }
                    }
                    State = 35;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
Exemple #3
0
	public UnaryExprContext unaryExpr() {
		UnaryExprContext _localctx = new UnaryExprContext(_ctx, State);
		EnterRule(_localctx, 24, RULE_unaryExpr);
		int _la;
		try {
			State = 243;
			switch (_input.La(1)) {
			case T__7:
			case T__1:
				EnterOuterAlt(_localctx, 1);
				{
				State = 228;
				_la = _input.La(1);
				if ( !(_la==T__7 || _la==T__1) ) {
				_errHandler.RecoverInline(this);
				}
				Consume();
				State = 229; _localctx._primaryExpr = primaryExpr();
				 _localctx.retValue =  new UnaryExpression(UnaryExpressionType.Not, _localctx._primaryExpr.retValue);
				}
				break;
			case T__10:
				EnterOuterAlt(_localctx, 2);
				{
				State = 232; Match(T__10);
				State = 233; _localctx._primaryExpr = primaryExpr();
				 _localctx.retValue =  new UnaryExpression(UnaryExpressionType.BitwiseNot, _localctx._primaryExpr.retValue);
				}
				break;
			case T__0:
				EnterOuterAlt(_localctx, 3);
				{
				State = 236; Match(T__0);
				State = 237; _localctx._primaryExpr = primaryExpr();
				 _localctx.retValue =  new UnaryExpression(UnaryExpressionType.Negate, _localctx._primaryExpr.retValue);
				}
				break;
			case T__18:
			case TRUE:
			case FALSE:
			case NAME:
			case INTEGER:
			case DATETIME:
			case VAR:
			case FLOAT:
			case STRING:
				EnterOuterAlt(_localctx, 4);
				{
				State = 240; _localctx._primaryExpr = primaryExpr();
				 _localctx.retValue =  _localctx._primaryExpr.retValue;
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}