public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 14, RULE_expr); try { State = 74; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 4, Context)) { case 1: EnterOuterAlt(_localctx, 1); { State = 72; term(); } break; case 2: EnterOuterAlt(_localctx, 2); { State = 73; opExpression(); } break; } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public override ExprNode VisitExpr([NotNull] ExprContext context) { var exprs = context.expr()?.Select(VisitExpr).ToArray(); var qMark = context.QuestionMark(); // ternary if (qMark != null) { return(new TernaryExprNode(exprs[0], exprs[1], exprs[2], GetLocation(context))); } var op = context.@operator()?.GetText(); if (op == null) { return(VisitTerm(context.term())); } // operator-variant var children = context.children; if (exprs.Length == 1) { var isPrefix = children[0] is OperatorContext; return(new UnaryOperatorNode(op, exprs[0], isPrefix, GetLocation(context))); } return(new BinaryOperatorNode(op, exprs[0], exprs[1], GetLocation(context))); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(_ctx, State); EnterRule(_localctx, 6, RULE_expr); try { EnterOuterAlt(_localctx, 1); { State = 65; _errHandler.Sync(this); switch (Interpreter.AdaptivePredict(_input, 1, _ctx)) { case 1: { State = 46; checarEtiq(); State = 47; checarInstru(); State = 48; checarOp(); State = 49; Match(ENTER); } break; case 2: { State = 51; checarEtiq(); State = 52; checarRsub(); State = 53; Match(ENTER); } break; case 3: { State = 55; checarEtiq(); State = 56; checarDirec(); State = 57; checarOp(); State = 58; Match(ENTER); } break; case 4: { State = 60; checarEtiq(); State = 61; checarByte(); State = 62; checarOpbyte(); State = 63; Match(ENTER); } break; } i++; } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
private bool expr_sempred(ExprContext _localctx, int predIndex) { switch (predIndex) { case 0: return(Precpred(Context, 3)); } return(true); }
private bool expr_sempred(ExprContext _localctx, int predIndex) { switch (predIndex) { case 0: return Precpred(Context, 11); case 1: return Precpred(Context, 10); case 2: return Precpred(Context, 9); case 3: return Precpred(Context, 18); } return true; }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 4, RULE_expr); int _la; try { EnterOuterAlt(_localctx, 1); { State = 26; multExpression(); State = 33; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la == ADD || _la == SUB) { { State = 31; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case ADD: { State = 27; Match(ADD); State = 28; multExpression(); } break; case SUB: { State = 29; Match(SUB); State = 30; multExpression(); } break; default: throw new NoViableAltException(this); } } State = 35; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(_ctx, State); EnterRule(_localctx, 4, RULE_expr); int _la; try { _localctx = new ADDSUBContext(_localctx); EnterOuterAlt(_localctx, 1); { State = 14; term(); State = 19; _errHandler.Sync(this); _la = _input.La(1); while (_la == ADD || _la == SUB) { { { State = 15; ((ADDSUBContext)_localctx).op = _input.Lt(1); _la = _input.La(1); if (!(_la == ADD || _la == SUB)) { ((ADDSUBContext)_localctx).op = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 16; term(); } } State = 21; _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); }
private bool expr_sempred(ExprContext _localctx, int predIndex) { switch (predIndex) { case 0: return(Precpred(_ctx, 6)); case 1: return(Precpred(_ctx, 5)); case 2: return(Precpred(_ctx, 1)); } return(true); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 4, RULE_expr); try { State = 76; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case LABEL: _localctx = new LabelExprContext(_localctx); EnterOuterAlt(_localctx, 1); { State = 73; Match(LABEL); } break; case INT: _localctx = new IntExprContext(_localctx); EnterOuterAlt(_localctx, 2); { State = 74; Match(INT); } break; case ID: _localctx = new IdExprContext(_localctx); EnterOuterAlt(_localctx, 3); { State = 75; Match(ID); } break; default: throw new NoViableAltException(this); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
object Visit(ExprContext expcontext) { switch (expcontext) { case AssignContext context: return(Visit(context)); case IdContext context: return(Visit(context)); case IfContext context: return(Visit(context)); case ComparerContext context: return(Visit(context)); case NotContext context: return(Visit(context)); case BlockContext context: return(Visit(context)); case MuldivContext context: return(Visit(context)); case AddsubContext context: return(Visit(context)); case IntContext context: return(Visit(context)); case BooleanContext context: return(Visit(context)); case StringContext context: return(context.GetText()); case ParensContext context: return(Visit(context)); case null: return(null); default: throw new Exception("Error en la declaracion."); } }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 2, RULE_expr); try { State = 23; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case FUNC: EnterOuterAlt(_localctx, 1); { State = 20; function(); } break; case VAR: EnterOuterAlt(_localctx, 2); { State = 21; variable(); } break; case OTHER: EnterOuterAlt(_localctx, 3); { State = 22; text(); } break; default: throw new NoViableAltException(this); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
private bool expr_sempred(ExprContext _localctx, int predIndex) { switch (predIndex) { case 0: return(Precpred(Context, 6)); case 1: return(Precpred(Context, 5)); case 2: return(Precpred(Context, 4)); case 3: return(Precpred(Context, 3)); case 4: return(Precpred(Context, 2)); case 5: return(Precpred(Context, 1)); } return(true); }
public static QsiExpressionNode VisitExpr(ExprContext expr) { while (expr is Expr_parensContext parens) { expr = parens.expr(); } return(expr switch { Predicate1Context context => VisitPredicate1(context), Predicate2Context context => VisitPredicate2(context), Like_predicateContext context => VisitLikePredicate(context), In_predicate_subqueryContext context => VisitInPredicateSubquery(context), In_predicateContext context => VisitInPredicate(context), Exists_predicateContext context => VisitExistsPredicate(context), Compound_predicate1Context context => VisitCompoundPredicate1(context), Compound_predicate2Context context => VisitCompoundPredicate2(context), Comparison_predicate1Context context => VisitComparisonPredicate1(context), Comparison_predicate2Context context => VisitComparisonPredicate2(context), Comparison_predicate3Context context => VisitComparisonPredicate3(context), Comparison_predicate4Context context => VisitComparisonPredicate4(context), Comparison_predicate5Context context => VisitComparisonPredicate5(context), Comparison_predicate6Context context => VisitComparisonPredicate6(context), Comparison_predicate7Context context => VisitComparisonPredicate7(context), Comparison_predicate8Context context => VisitComparisonPredicate8(context), Comparison_predicate9Context context => VisitComparisonPredicate9(context), Bool_test_exprContext context => VisitBoolTestExpr(context), Between_predicateContext context => VisitBetweenPredicate(context), Slot_ref_Context context => VisitSlotRef(context.slot_ref()), Sign_chain_exprContext context => VisitSignChainExpr(context), Literal_Context context => VisitLiteral(context.literal()), Function_call_expr_Context context => VisitFunctionCallExpr(context.function_call_expr()), Cast_expr_Context context => VisitCastExpr(context.cast_expr()), Case_expr_Context context => VisitCaseExpr(context.case_expr()), Analytic_expr_Context context => VisitAnalyticExpr(context.analytic_expr()), Timestamp_arithmetic_expr1Context context => VisitTimestampArithmeticExpr1(context), Timestamp_arithmetic_expr2Context context => VisitTimestampArithmeticExpr2(context), Timestamp_arithmetic_expr3Context context => VisitTimestampArithmeticExpr3(context), Arithmetic_exprContext context => VisitArithmeticExpr(context), Arithmetic_expr_factorialContext context => VisitArithmeticExprFactorial(context), Arithmetic_expr_bitnotContext context => VisitArithmeticExprBitnot(context), Subquery_Context context => VisitSubquery(context.subquery()), _ => throw TreeHelper.NotSupportedTree(expr) });
private bool expr_sempred(ExprContext _localctx, int predIndex) { switch (predIndex) { case 0: return(Precpred(Context, 11)); case 1: return(Precpred(Context, 10)); case 2: return(Precpred(Context, 9)); case 3: return(Precpred(Context, 8)); case 4: return(Precpred(Context, 7)); case 5: return(Precpred(Context, 6)); case 6: return(Precpred(Context, 12)); } return(true); }
COOL_TYPE GetType(ExprContext econtext) { switch (econtext) { case ParensContext context: return(GetType(context.midexp)); case MuldivContext context: return(COOL_TYPE.INTEGER); case AddsubContext context: return(COOL_TYPE.INTEGER); case IntContext context: return(COOL_TYPE.INTEGER); case StringContext context: return(COOL_TYPE.STRING); case BooleanContext context: return(COOL_TYPE.BOOL); case NotContext context: return(GetType(context.cond)); case ComparerContext context: if (context.op.Type != EQU) { return(COOL_TYPE.INTEGER); } else { return(GetType(context.left)); } default: break; } throw new NotImplementedException(); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 2, RULE_expr); int _la; try { EnterOuterAlt(_localctx, 1); { State = 9; Match(LPAR); State = 10; Match(NAME); State = 14; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LPAR) | (1L << FALSY) | (1L << NAME) | (1L << STRING) | (1L << INT) | (1L << FLOATING))) != 0)) { { { State = 11; args(); } } State = 16; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } State = 17; Match(RPAR); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 12, RULE_expr); try { EnterOuterAlt(_localctx, 1); { State = 58; factor(); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 16, RULE_expr); try { State = 84; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case NUM: EnterOuterAlt(_localctx, 1); { State = 82; Match(NUM); } break; case ID: EnterOuterAlt(_localctx, 2); { State = 83; array_access(); } break; default: throw new NoViableAltException(this); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 0, RULE_expr); int _la; try { EnterOuterAlt(_localctx, 1); { State = 14; term(); State = 20; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la == OR || _la == AND) { { { State = 15; op(); State = 16; term(); } } State = 22; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public OpExprContext(ExprContext context) { CopyFrom(context); }
public BreakStatementContext(ExprContext context) { CopyFrom(context); }
public ComplexLiteralContext(ExprContext context) { CopyFrom(context); }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = _ctx; int _parentState = State; ExprContext _localctx = new ExprContext(_ctx, _parentState); ExprContext _prevctx = _localctx; int _startState = 2; EnterRecursionRule(_localctx, 2, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 15; _errHandler.Sync(this); switch (_input.La(1)) { case INT: { _localctx = new IntContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 10; Match(INT); } break; case T__0: { _localctx = new ParensContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 11; Match(T__0); State = 12; expr(0); State = 13; Match(T__1); } break; default: throw new NoViableAltException(this); } _ctx.stop = _input.Lt(-1); State = 25; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 3, _ctx); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber) { if (_alt == 1) { if (_parseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 23; _errHandler.Sync(this); switch (Interpreter.AdaptivePredict(_input, 2, _ctx)) { case 1: { _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState)); ((MulDivContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 17; if (!(Precpred(_ctx, 4))) { throw new FailedPredicateException(this, "Precpred(_ctx, 4)"); } State = 18; ((MulDivContext)_localctx).op = _input.Lt(1); _la = _input.La(1); if (!(_la == MUL || _la == DIV)) { ((MulDivContext)_localctx).op = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 19; ((MulDivContext)_localctx).right = expr(5); } break; case 2: { _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState)); ((AddSubContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 20; if (!(Precpred(_ctx, 3))) { throw new FailedPredicateException(this, "Precpred(_ctx, 3)"); } State = 21; ((AddSubContext)_localctx).op = _input.Lt(1); _la = _input.La(1); if (!(_la == ADD || _la == SUB)) { ((AddSubContext)_localctx).op = _errHandler.RecoverInline(this); } else { if (_input.La(1) == TokenConstants.Eof) { matchedEOF = true; } _errHandler.ReportMatch(this); Consume(); } State = 22; ((AddSubContext)_localctx).right = expr(4); } break; } } } State = 27; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 3, _ctx); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
public IntContext(ExprContext context) { CopyFrom(context); }
public MulDivContext(ExprContext context) { CopyFrom(context); }
private void PushEvalStack(BoundExpression result, ExprContext context) { Debug.Assert(result != null || context == ExprContext.None); _evalStack.Add((result, context)); }
public override BoundNode VisitCall(BoundCall node) { var receiver = node.ReceiverOpt; // matches or a bit stronger than EmitReceiverRef // if there are any doubts that receiver is a ref type, // assume we will need an address (that will prevent scheduling of receiver). if (!node.Method.IsStatic) { var receiverType = receiver.Type; ExprContext context; if (receiverType.IsReferenceType) { if (receiverType.IsTypeParameter()) { // type param receiver that we statically know is a reference will be boxed context = ExprContext.Box; } else { // reference receivers will be used as values context = ExprContext.Value; } } else { // everything else will get an address taken context = ExprContext.Address; } receiver = VisitExpression(receiver, context); } else { // TODO: for some reason receiver could be not null even if method is static... // it seems wrong, ignore for now. this.counter += 1; receiver = null; } MethodSymbol method = node.Method; var rewrittenArguments = VisitArguments(node.Arguments, method.Parameters); return node.Update(receiver, method, rewrittenArguments); }
public UserOpContext(ExprContext context) { CopyFrom(context); }
public NamespaceContext(ExprContext context) { CopyFrom(context); }
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; }
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); { { _localctx = new AtomExprContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 7; ((AtomExprContext)_localctx).atom = Match(NUMBER); } Context.Stop = TokenStream.LT(-1); State = 17; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 15; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 0, Context)) { case 1: { _localctx = new OpExprContext(new ExprContext(_parentctx, _parentState)); ((OpExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 9; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 10; ((OpExprContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == T__0 || _la == T__1)) { ((OpExprContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 11; ((OpExprContext)_localctx).right = expr(4); } break; case 2: { _localctx = new OpExprContext(new ExprContext(_parentctx, _parentState)); ((OpExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 12; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 13; ((OpExprContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == T__2 || _la == T__3)) { ((OpExprContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 14; ((OpExprContext)_localctx).right = expr(3); } break; } } } State = 19; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
public ExprContext expr() { ExprContext _localctx = new ExprContext(_ctx, State); EnterRule(_localctx, 2, RULE_expr); try { State = 46; switch ( Interpreter.AdaptivePredict(_input,0,_ctx) ) { case 1: EnterOuterAlt(_localctx, 1); { State = 36; _localctx.first = orExpr(0); State = 37; Match(T__21); State = 38; _localctx.middle = expr(); State = 39; Match(T__15); State = 40; _localctx.right = expr(); _localctx.retValue = new TernaryExpression(_localctx.first.retValue, _localctx.middle.retValue, _localctx.right.retValue); } break; case 2: EnterOuterAlt(_localctx, 2); { State = 43; _localctx._orExpr = orExpr(0); _localctx.retValue = _localctx._orExpr.retValue; } break; } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
private BoundExpression VisitExpression(BoundExpression node, ExprContext context) { BoundExpression result; _recursionDepth++; if (_recursionDepth > 1) { StackGuard.EnsureSufficientExecutionStack(_recursionDepth); result = VisitExpressionCore(node, context); } else { result = VisitExpressionCoreWithStackGuard(node, context); } _recursionDepth--; return result; }
public ExprContext expr() { ExprContext _localctx = new ExprContext(Context, State); EnterRule(_localctx, 112, RULE_expr); int _la; try { EnterOuterAlt(_localctx, 1); { State = 748; xor_expr(); State = 753; ErrorHandler.Sync(this); _la = TokenStream.La(1); while (_la==OR_OP) { { { State = 749; Match(OR_OP); State = 750; xor_expr(); } } State = 755; ErrorHandler.Sync(this); _la = TokenStream.La(1); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
public NegationContext(ExprContext context) { CopyFrom(context); }
public SignContext(ExprContext context) { CopyFrom(context); }
public AddSubContext(ExprContext context) { CopyFrom(context); }
public BoundExpression VisitExpression(BoundExpression node, ExprContext context) { var prevContext = _context; int prevStack = StackDepth(); _context = context; // Do not recurse into constant expressions. Their children do not push any values. var result = node.ConstantValue == null ? node = (BoundExpression)base.Visit(node) : node; _context = prevContext; _counter += 1; switch (context) { case ExprContext.Sideeffects: SetStackDepth(prevStack); break; case ExprContext.AssignmentTarget: break; case ExprContext.Value: case ExprContext.Address: case ExprContext.Box: SetStackDepth(prevStack); PushEvalStack(node, context); break; default: throw ExceptionUtilities.UnexpectedValue(context); } return result; }
public ParensContext(ExprContext context) { CopyFrom(context); }
public BoundNode VisitStatement(BoundNode node) { Debug.Assert(node == null || EvalStackIsEmpty()); var origStack = StackDepth(); var prevContext = _context; var result = base.Visit(node); // prevent cross-statement local optimizations // when emitting debug-friendly code. if (_debugFriendly) { EnsureOnlyEvalStack(); } _context = prevContext; SetStackDepth(origStack); _counter += 1; return result; }
public FunctionCallContext(ExprContext context) { CopyFrom(context); }
public IfStatementContext(ExprContext context) { CopyFrom(context); }
public FalseLiteralContext(ExprContext context) { CopyFrom(context); }
// here we have a case of indirect assignment: *t1 = expr; // normally we would need to push t1 and that will cause spilling of t2 // // TODO: an interesting case arises in unused x[i]++ and ++x[i] : // we have trees that look like: // // t1 = &(x[0]) // t2 = *t1 // *t1 = t2 + 1 // // t1 = &(x[0]) // t2 = *t1 + 1 // *t1 = t2 // // in these cases, we could keep t2 on stack (dev10 does). // we are dealing with exactly 2 locals and access them in strict order // t1, t2, t1, t2 and we are not using t2 after that. // We may consider detecting exactly these cases and pretend that we do not need // to push either t1 or t2 in this case. // private bool LhsUsesStackWhenAssignedTo(BoundNode node, ExprContext context) { Debug.Assert(context == ExprContext.AssignmentTarget); switch (node.Kind) { case BoundKind.Parameter: case BoundKind.Local: return false; case BoundKind.FieldAccess: return !((BoundFieldAccess)node).FieldSymbol.IsStatic; case BoundKind.Sequence: return LhsUsesStackWhenAssignedTo(((BoundSequence)node).Value, context); } return true; }
public virtual void CopyFrom(ExprContext context) { base.CopyFrom(context); }
public IndexContext(ExprContext context) { CopyFrom(context); }
public AtomExprContext(ExprContext context) { CopyFrom(context); }
public LabelExprContext(ExprContext context) { CopyFrom(context); }
public override BoundNode VisitBinaryOperator(BoundBinaryOperator node) { BoundExpression child = node.Left; if (child.Kind != BoundKind.BinaryOperator || child.ConstantValue != null) { return VisitBinaryOperatorSimple(node); } // Do not blow the stack due to a deep recursion on the left. var stack = ArrayBuilder<BoundBinaryOperator>.GetInstance(); stack.Push(node); BoundBinaryOperator binary = (BoundBinaryOperator)child; while (true) { stack.Push(binary); child = binary.Left; if (child.Kind != BoundKind.BinaryOperator || child.ConstantValue != null) { break; } binary = (BoundBinaryOperator)child; } var prevContext = _context; int prevStack = StackDepth(); var left = (BoundExpression)this.Visit(child); while (true) { binary = stack.Pop(); var isLogical = (binary.OperatorKind & BinaryOperatorKind.Logical) != 0; object cookie = null; if (isLogical) { cookie = GetStackStateCookie(); // implicit branch here SetStackDepth(prevStack); // right is evaluated with original stack } var right = (BoundExpression)this.Visit(binary.Right); if (isLogical) { EnsureStackState(cookie); // implicit label here } var type = this.VisitType(binary.Type); left = binary.Update(binary.OperatorKind, left, right, binary.ConstantValueOpt, binary.MethodOpt, binary.ResultKind, type); if (stack.Count == 0) { break; } _context = prevContext; _counter += 1; SetStackDepth(prevStack); PushEvalStack(binary, ExprContext.Value); } Debug.Assert((object)binary == node); stack.Free(); return left; }
public TrueLiteralContext(ExprContext context) { CopyFrom(context); }
private BoundExpression VisitExpressionCoreWithStackGuard(BoundExpression node, ExprContext context) { Debug.Assert(_recursionDepth == 1); try { var result = VisitExpressionCore(node, context); Debug.Assert(_recursionDepth == 1); return result; } catch (Exception ex) when (StackGuard.IsInsufficientExecutionStackException(ex)) { throw new CancelledByStackGuardException(ex, node); } }
public InfLiteralContext(ExprContext context) { CopyFrom(context); }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 0; EnterRecursionRule(_localctx, 0, RULE_expr, _p); try { int _alt; EnterOuterAlt(_localctx, 1); { State = 17; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case OpenParen: { State = 9; Match(OpenParen); State = 10; expr(0); State = 11; Match(CloseParen); } break; case VARIABLE: case NUMBER: case STRING: { State = 13; operand(); State = 14; @operator(); State = 15; operand(); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 25; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { { _localctx = new ExprContext(_parentctx, _parentState); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 19; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 20; booleanOperator(); State = 21; expr(4); } } } State = 27; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 1, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
public NAContext(ExprContext context) { CopyFrom(context); }
public BoundNode VisitStatement(BoundNode node) { Debug.Assert(node == null || EvalStackIsEmpty()); var origStack = StackDepth(); var prevContext = _context; var result = base.Visit(node); _context = prevContext; SetStackDepth(origStack); _counter += 1; return result; }
/// <summary> /// Recursively rewrites the node or simply replaces it with a dup node /// if we have just seen exactly same node. /// </summary> private BoundExpression ReuseOrVisit(BoundExpression node, ExprContext context) { if (context == ExprContext.AssignmentTarget || context == ExprContext.Sideeffects) { return BaseVisitExpression(node); } // it must be most recent expression // it can be a ref when we want a value, but cannot be the other way // TODO: we could reuse boxed values, but we would need to make the Dup to know it was boxed if (_counter == _lastExpressionCnt + 1 && _lastExprContext != ExprContext.Box && (_lastExprContext == context || _lastExprContext != ExprContext.Value) && CanDup(_lastExpression, node)) { _lastExpressionCnt = _counter; // when duping something not created in a Value context, we are actually duping a reference. // record that so that codegen could know if it is a value or a reference. RefKind dupRefKind = _lastExprContext == ExprContext.Value ? RefKind.None : RefKind.Ref; // change the context to the most recently used. // Why? If we obtained a value from a duped reference, we now have a value on the stack. _lastExprContext = context; return new BoundDup(node.Syntax, dupRefKind, node.Type); } else { BoundExpression result = BaseVisitExpression(node); _lastExpressionCnt = _counter; _lastExprContext = context; _lastExpression = result; return result; } }
private void PushEvalStack(BoundExpression result, ExprContext context) { _evalStack.Add(ValueTuple.Create(result, context)); }
public BoundExpression VisitExpression(BoundExpression node, ExprContext context) { var prevContext = _context; int prevStack = _evalStack; _context = context; var result = ReuseOrVisit(node, context); _counter += 1; switch (context) { case ExprContext.Sideeffects: _evalStack = prevStack; break; case ExprContext.Value: case ExprContext.Address: case ExprContext.Box: _evalStack = prevStack + 1; break; case ExprContext.AssignmentTarget: _evalStack = prevStack; if (LhsUsesStackWhenAssignedTo(node, context)) { _evalStack = prevStack + 1; } break; default: throw ExceptionUtilities.UnexpectedValue(context); } _context = prevContext; return result; }
public override BoundNode VisitArrayAccess(BoundArrayAccess node) { // regardless of purpose, array access visits its children as values // TODO: do we need to save/restore old context here? var oldContext = _context; _context = ExprContext.Value; var result = base.VisitArrayAccess(node); _context = oldContext; return result; }
public BoundNode VisitStatement(BoundNode node) { var prevContext = _context; int prevStack = _evalStack; var result = base.Visit(node); ClearLastExpression(); _counter += 1; _evalStack = prevStack; _context = prevContext; return result; }