public override void EnterInt([NotNull] IntContext context) { base.EnterInt(context); Log("EnterInt"); if (phase == Phase.Building) { symbolTableCreator.EnterInt(context); } else { symbolTableTraverser.EnterInt(context); semanticErrorChecker.EnterInt(context); } }
int Visit(IntContext context) { return(int.Parse(context.GetText())); }
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 override ASTN VisitInt([NotNull] IntContext context) => new IntNode(context, context.GetText());
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 = 15; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case INT: { _localctx = new IntContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 10; Match(INT); } break; case T__0: { _localctx = new ParensContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 11; Match(T__0); State = 12; expr(0); State = 13; Match(T__1); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 25; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 3, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 23; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 2, Context)) { case 1: { _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 17; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 18; ((MulDivContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == MUL || _la == DIV)) { ((MulDivContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 19; expr(5); } break; case 2: { _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 20; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 21; ((AddSubContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == ADD || _la == SUB)) { ((AddSubContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 22; expr(4); } break; } } } State = 27; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 3, 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 = _ctx; int _parentState = State; ExprContext _localctx = new ExprContext(_ctx, _parentState); ExprContext _prevctx = _localctx; int _startState = 4; EnterRecursionRule(_localctx, 4, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 29; switch (_input.La(1)) { case INT: { _localctx = new IntContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 23; Match(INT); } break; case ID: { _localctx = new IdContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 24; Match(ID); } break; case 2: { _localctx = new ParensContext(_localctx); _ctx = _localctx; _prevctx = _localctx; State = 25; Match(2); State = 26; expr(0); State = 27; Match(1); } break; default: throw new NoViableAltException(this); } _ctx.stop = _input.Lt(-1); State = 39; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 4, _ctx); while (_alt != 2 && _alt != ATN.InvalidAltNumber) { if (_alt == 1) { if (_parseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 37; switch (Interpreter.AdaptivePredict(_input, 3, _ctx)) { case 1: { _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 31; if (!(Precpred(_ctx, 5))) { throw new FailedPredicateException(this, "Precpred(_ctx, 5)"); } State = 32; _la = _input.La(1); if (!(_la == MUL || _la == DIV)) { _errHandler.RecoverInline(this); } Consume(); State = 33; expr(6); } break; case 2: { _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 34; if (!(Precpred(_ctx, 4))) { throw new FailedPredicateException(this, "Precpred(_ctx, 4)"); } State = 35; _la = _input.La(1); if (!(_la == ADD || _la == SUB)) { _errHandler.RecoverInline(this); } Consume(); State = 36; expr(5); } break; } } } State = 41; _errHandler.Sync(this); _alt = Interpreter.AdaptivePredict(_input, 4, _ctx); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.ReportError(this, re); _errHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }
public AtomContext atom() { AtomContext _localctx = new AtomContext(Context, State); EnterRule(_localctx, 12, RULE_atom); try { State = 77; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case PI: _localctx = new ConstantPIContext(_localctx); EnterOuterAlt(_localctx, 1); { State = 68; Match(PI); } break; case E: _localctx = new ConstantEContext(_localctx); EnterOuterAlt(_localctx, 2); { State = 69; Match(E); } break; case DOUBLE: _localctx = new DoubleContext(_localctx); EnterOuterAlt(_localctx, 3); { State = 70; Match(DOUBLE); } break; case INT: _localctx = new IntContext(_localctx); EnterOuterAlt(_localctx, 4); { State = 71; Match(INT); } break; case ID: _localctx = new VariableContext(_localctx); EnterOuterAlt(_localctx, 5); { State = 72; Match(ID); } break; case LPAR: _localctx = new BracesContext(_localctx); EnterOuterAlt(_localctx, 6); { State = 73; Match(LPAR); State = 74; plusOrMinus(0); State = 75; Match(RPAR); } 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 override void EnterInt([NotNull] IntContext context) { this.Result.Insert(new ConstIntExpression(Result, context, int.Parse(context.GetText()))); }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 12; EnterRecursionRule(_localctx, 12, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 120; ErrorHandler.Sync(this); switch ( Interpreter.AdaptivePredict(TokenStream,6,Context) ) { case 1: { _localctx = new Call_methodContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 68; Match(ID); State = 69; Match(T__3); State = 70; args_call(); State = 71; Match(T__4); } break; case 2: { _localctx = new IfContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 73; Match(IF); State = 74; expr(0); State = 75; Match(THEN); State = 76; expr(0); State = 77; Match(ELSE); State = 78; expr(0); State = 79; Match(FI); } break; case 3: { _localctx = new WhileContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 81; Match(WHILE); State = 82; expr(0); State = 83; Match(LOOP); State = 84; expr(0); State = 85; Match(POOL); } break; case 4: { _localctx = new BodyContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 87; Match(T__1); State = 88; expr_list(); State = 89; Match(T__2); } break; case 5: { _localctx = new New_typeContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 91; Match(NEW); State = 92; Match(TYPE); } break; case 6: { _localctx = new IsvoidContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 93; Match(ISVOID); State = 94; expr(12); } break; case 7: { _localctx = new Unary_expContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 95; ((Unary_expContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if ( !(_la==T__16 || _la==NOT) ) { ((Unary_expContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 96; expr(8); } break; case 8: { _localctx = new ParentesisContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 97; Match(T__3); State = 98; expr(0); State = 99; Match(T__4); } break; case 9: { _localctx = new IntContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 101; Match(INTEGER); } break; case 10: { _localctx = new BoolContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 102; ((BoolContext)_localctx).cons = TokenStream.LT(1); _la = TokenStream.LA(1); if ( !(_la==TRUE || _la==FALSE) ) { ((BoolContext)_localctx).cons = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } } break; case 11: { _localctx = new StringContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 103; Match(STR); } break; case 12: { _localctx = new AssignContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 104; Match(ID); State = 105; Match(T__6); State = 106; expr(3); } break; case 13: { _localctx = new LetContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 107; Match(LET); State = 108; attr(); State = 113; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la==T__17) { { { State = 109; Match(T__17); State = 110; attr(); } } State = 115; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } State = 116; Match(IN); State = 117; expr(2); } break; case 14: { _localctx = new IdContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 119; Match(ID); } break; } Context.Stop = TokenStream.LT(-1); State = 144; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,9,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { if ( ParseListeners!=null ) TriggerExitRuleEvent(); _prevctx = _localctx; { State = 142; ErrorHandler.Sync(this); switch ( Interpreter.AdaptivePredict(TokenStream,8,Context) ) { case 1: { _localctx = new MultdivContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 122; if (!(Precpred(Context, 11))) throw new FailedPredicateException(this, "Precpred(Context, 11)"); State = 123; ((MultdivContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if ( !(_la==T__9 || _la==T__10) ) { ((MultdivContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 124; expr(12); } break; case 2: { _localctx = new SumarestaContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 125; if (!(Precpred(Context, 10))) throw new FailedPredicateException(this, "Precpred(Context, 10)"); State = 126; ((SumarestaContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if ( !(_la==T__11 || _la==T__12) ) { ((SumarestaContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 127; expr(11); } break; case 3: { _localctx = new CompContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 128; if (!(Precpred(Context, 9))) throw new FailedPredicateException(this, "Precpred(Context, 9)"); State = 129; ((CompContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__13) | (1L << T__14) | (1L << T__15))) != 0)) ) { ((CompContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 130; expr(10); } break; case 4: { _localctx = new DispatchContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 131; if (!(Precpred(Context, 18))) throw new FailedPredicateException(this, "Precpred(Context, 18)"); State = 134; ErrorHandler.Sync(this); _la = TokenStream.LA(1); if (_la==T__7) { { State = 132; Match(T__7); State = 133; Match(TYPE); } } State = 136; Match(T__8); State = 137; Match(ID); State = 138; Match(T__3); State = 139; args_call(); State = 140; Match(T__4); } break; } } } State = 146; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,9,Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return _localctx; }
public override void ExitInt([NotNull] IntContext context) { base.ExitInt(context); }