Пример #1
0
        public WhileStatement ParseWhileStatement(WhileStatementContext node)
        {
            WhileStatement statement = new WhileStatement();

            foreach (var child in node.children)
            {
                if (child is ProcedureSqlStatementContext procedure)
                {
                    statement.Statements.AddRange(this.ParseProcedureStatement(procedure));
                }
                else if (child is PredicateExpressionContext exp)
                {
                    statement.Condition = new TokenInfo(exp)
                    {
                        Type = TokenType.Condition
                    };
                }
                else if (child is LogicalExpressionContext logic)
                {
                    statement.Condition = new TokenInfo(logic)
                    {
                        Type = TokenType.Condition
                    };
                }
            }

            return(statement);
        }
Пример #2
0
        public override WhileStatementNode VisitWhileStatement([NotNull] WhileStatementContext context)
        {
            var expr = VisitExpr(context.expr());

            var block     = context.block().Invoke(VisitBlock);
            var statement = context.statement().Invoke(VisitStatement);

            return(new WhileStatementNode(expr, block, statement, GetLocation(context)));
        }
Пример #3
0
        public override object VisitWhileStatement([NotNull] WhileStatementContext context)
        {
            var type = TypeVisitor.GetType(context.expression(), scope, errors);

            if (!type.InheritsFrom(TypeSystem.Instance["Boolean"]))
            {
                errors.Add(new Error(context, $"Expression type must be {TypeSystem.Instance["Boolean"]}"));
            }

            return(base.VisitWhileStatement(context));
        }
Пример #4
0
        public override void EnterWhileStatement([NotNull] WhileStatementContext context)
        {
            WhileStatement whileStatement = new WhileStatement(Parent, context);

            ExpressionListener expressionListener = new ExpressionListener(whileStatement);

            context.parExpression().expression().EnterRule(expressionListener);
            whileStatement.Condition = expressionListener.GetResult();

            StatementListener statementListener = new StatementListener(whileStatement);

            context.statement().EnterRule(statementListener);
            whileStatement.Statements = statementListener.Result;

            Result.Add(whileStatement);
        }
Пример #5
0
 public override Expression VisitWhileStatement(WhileStatementContext context)
 {
     throw new CompilationException("Unsupported statement. StatementType=while loop", context);
 }
Пример #6
0
	private ExprContext expr(int _p) {
		ParserRuleContext _parentctx = Context;
		int _parentState = State;
		ExprContext _localctx = new ExprContext(Context, _parentState);
		ExprContext _prevctx = _localctx;
		int _startState = 4;
		EnterRecursionRule(_localctx, 4, RULE_expr, _p);
		int _la;
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			State = 129;
			switch ( Interpreter.AdaptivePredict(TokenStream,12,Context) ) {
			case 1:
				{
				_localctx = new SignContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;

				State = 35;
				_la = TokenStream.La(1);
				if ( !(_la==T__14 || _la==T__15) ) {
				ErrorHandler.RecoverInline(this);
				}
				else {
				    Consume();
				}
				State = 36; expr(35);
				}
				break;
			case 2:
				{
				_localctx = new NegationContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 37; Match(T__25);
				State = 38; expr(29);
				}
				break;
			case 3:
				{
				_localctx = new FormulaeContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 39; Match(T__30);
				State = 40; expr(26);
				}
				break;
			case 4:
				{
				_localctx = new FunctionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 41; Match(T__34);
				State = 42; Match(T__7);
				State = 44;
				_la = TokenStream.La(1);
				if (_la==T__53 || _la==ID) {
					{
					State = 43; formlist();
					}
				}

				State = 46; Match(T__8);
				State = 47; expr(23);
				}
				break;
			case 5:
				{
				_localctx = new RepeatStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 48; Match(T__42);
				State = 52;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
				while (_la==NL) {
					{
					{
					State = 49; Match(NL);
					}
					}
					State = 54;
					ErrorHandler.Sync(this);
					_la = TokenStream.La(1);
				}
				State = 55; expr(17);
				}
				break;
			case 6:
				{
				_localctx = new HelpContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 56; Match(T__43);
				State = 57; expr(16);
				}
				break;
			case 7:
				{
				_localctx = new CompoundContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 58; Match(T__35);
				State = 60;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 59; Match(NL);
					}
				}

				State = 62; exprlist();
				State = 63; Match(T__36);
				}
				break;
			case 8:
				{
				_localctx = new IfStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 65; Match(T__37);
				State = 66; Match(T__7);
				State = 67; expr(0);
				State = 68; Match(T__8);
				State = 70;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 69; Match(NL);
					}
				}

				State = 72; expr(0);
				}
				break;
			case 9:
				{
				_localctx = new IfElseStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 74; Match(T__37);
				State = 75; Match(T__7);
				State = 76; expr(0);
				State = 77; Match(T__8);
				State = 79;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 78; Match(NL);
					}
				}

				State = 81; expr(0);
				State = 83;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 82; Match(NL);
					}
				}

				State = 85; Match(T__38);
				State = 87;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 86; Match(NL);
					}
				}

				State = 89; expr(0);
				}
				break;
			case 10:
				{
				_localctx = new ForEachStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 91; Match(T__39);
				State = 92; Match(T__7);
				State = 93; Match(ID);
				State = 94; Match(T__40);
				State = 95; expr(0);
				State = 96; Match(T__8);
				State = 98;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 97; Match(NL);
					}
				}

				State = 100; expr(0);
				}
				break;
			case 11:
				{
				_localctx = new WhileStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 102; Match(T__41);
				State = 103; Match(T__7);
				State = 104; expr(0);
				State = 105; Match(T__8);
				State = 107;
				_la = TokenStream.La(1);
				if (_la==NL) {
					{
					State = 106; Match(NL);
					}
				}

				State = 109; expr(0);
				}
				break;
			case 12:
				{
				_localctx = new NextStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 111; Match(T__44);
				}
				break;
			case 13:
				{
				_localctx = new BreakStatementContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 112; Match(T__45);
				}
				break;
			case 14:
				{
				_localctx = new ParenthesizedContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 113; Match(T__7);
				State = 114; expr(0);
				State = 115; Match(T__8);
				}
				break;
			case 15:
				{
				_localctx = new IdentifierContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 117; Match(ID);
				}
				break;
			case 16:
				{
				_localctx = new StringLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 118; Match(STRING);
				}
				break;
			case 17:
				{
				_localctx = new HexLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 119; Match(HEX);
				}
				break;
			case 18:
				{
				_localctx = new IntLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 120; Match(INT);
				}
				break;
			case 19:
				{
				_localctx = new FloatLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 121; Match(FLOAT);
				}
				break;
			case 20:
				{
				_localctx = new ComplexLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 122; Match(COMPLEX);
				}
				break;
			case 21:
				{
				_localctx = new NullLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 123; Match(T__46);
				}
				break;
			case 22:
				{
				_localctx = new NAContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 124; Match(T__47);
				}
				break;
			case 23:
				{
				_localctx = new InfLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 125; Match(T__48);
				}
				break;
			case 24:
				{
				_localctx = new NanLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 126; Match(T__49);
				}
				break;
			case 25:
				{
				_localctx = new TrueLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 127; Match(T__50);
				}
				break;
			case 26:
				{
				_localctx = new FalseLiteralContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 128; Match(T__51);
				}
				break;
			}
			Context.Stop = TokenStream.Lt(-1);
			State = 185;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,14,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					if ( ParseListeners!=null )
						TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					State = 183;
					switch ( Interpreter.AdaptivePredict(TokenStream,13,Context) ) {
					case 1:
						{
						_localctx = new NamespaceContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 131;
						if (!(Precpred(Context, 38))) throw new FailedPredicateException(this, "Precpred(Context, 38)");
						State = 132;
						_la = TokenStream.La(1);
						if ( !(_la==T__9 || _la==T__10) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 133; expr(39);
						}
						break;
					case 2:
						{
						_localctx = new MemberAccessContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 134;
						if (!(Precpred(Context, 37))) throw new FailedPredicateException(this, "Precpred(Context, 37)");
						State = 135;
						_la = TokenStream.La(1);
						if ( !(_la==T__11 || _la==T__12) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 136; expr(38);
						}
						break;
					case 3:
						{
						_localctx = new PowerContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 137;
						if (!(Precpred(Context, 36))) throw new FailedPredicateException(this, "Precpred(Context, 36)");
						State = 138; Match(T__13);
						State = 139; expr(37);
						}
						break;
					case 4:
						{
						_localctx = new SequenceContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 140;
						if (!(Precpred(Context, 34))) throw new FailedPredicateException(this, "Precpred(Context, 34)");
						State = 141; Match(T__16);
						State = 142; expr(35);
						}
						break;
					case 5:
						{
						_localctx = new UserOpContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 143;
						if (!(Precpred(Context, 33))) throw new FailedPredicateException(this, "Precpred(Context, 33)");
						State = 144; Match(USER_OP);
						State = 145; expr(34);
						}
						break;
					case 6:
						{
						_localctx = new MultiplicationContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 146;
						if (!(Precpred(Context, 32))) throw new FailedPredicateException(this, "Precpred(Context, 32)");
						State = 147;
						_la = TokenStream.La(1);
						if ( !(_la==T__17 || _la==T__18) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 148; expr(33);
						}
						break;
					case 7:
						{
						_localctx = new AdditionContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 149;
						if (!(Precpred(Context, 31))) throw new FailedPredicateException(this, "Precpred(Context, 31)");
						State = 150;
						_la = TokenStream.La(1);
						if ( !(_la==T__14 || _la==T__15) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 151; expr(32);
						}
						break;
					case 8:
						{
						_localctx = new ComparisonContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 152;
						if (!(Precpred(Context, 30))) throw new FailedPredicateException(this, "Precpred(Context, 30)");
						State = 153;
						_la = TokenStream.La(1);
						if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__19) | (1L << T__20) | (1L << T__21) | (1L << T__22) | (1L << T__23) | (1L << T__24))) != 0)) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 154; expr(31);
						}
						break;
					case 9:
						{
						_localctx = new LogicalAndContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 155;
						if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)");
						State = 156;
						_la = TokenStream.La(1);
						if ( !(_la==T__26 || _la==T__27) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 157; expr(29);
						}
						break;
					case 10:
						{
						_localctx = new LogicalOrContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 158;
						if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)");
						State = 159;
						_la = TokenStream.La(1);
						if ( !(_la==T__28 || _la==T__29) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 160; expr(28);
						}
						break;
					case 11:
						{
						_localctx = new FormulaeContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 161;
						if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)");
						State = 162; Match(T__30);
						State = 163; expr(26);
						}
						break;
					case 12:
						{
						_localctx = new RightAssignmentContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 164;
						if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)");
						State = 165;
						_la = TokenStream.La(1);
						if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__31) | (1L << T__32) | (1L << T__33))) != 0)) ) {
						ErrorHandler.RecoverInline(this);
						}
						else {
						    Consume();
						}
						State = 166; expr(25);
						}
						break;
					case 13:
						{
						_localctx = new ListAccessContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 167;
						if (!(Precpred(Context, 41))) throw new FailedPredicateException(this, "Precpred(Context, 41)");
						State = 168; Match(T__4);
						State = 169; sublist();
						State = 170; Match(T__5);
						State = 171; Match(T__5);
						}
						break;
					case 14:
						{
						_localctx = new IndexContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 173;
						if (!(Precpred(Context, 40))) throw new FailedPredicateException(this, "Precpred(Context, 40)");
						State = 174; Match(T__6);
						State = 175; sublist();
						State = 176; Match(T__5);
						}
						break;
					case 15:
						{
						_localctx = new FunctionCallContext(new ExprContext(_parentctx, _parentState));
						PushNewRecursionContext(_localctx, _startState, RULE_expr);
						State = 178;
						if (!(Precpred(Context, 39))) throw new FailedPredicateException(this, "Precpred(Context, 39)");
						State = 179; Match(T__7);
						State = 180; sublist();
						State = 181; Match(T__8);
						}
						break;
					}
					} 
				}
				State = 187;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,14,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}