public IHolderCil Visit(NegExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var value = new LocalCil($"_value{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(value); var valueExpr = Visit(parserRule.expresion, cilTree, contextCil); valueExpr = GetValue(valueExpr, cilTree, CilAst.Int); cilTree.ThreeDirInses.Add(new NegCil(value, valueExpr)); return(CreateABasicTypeWhitVal(cilTree, CilAst.Int, value)); }
public void Visit(NegExprContext parserRule, IObjectContext <IVar, IVar> context) { Visit(parserRule.expresion, context); if (!globalContext.IfDefineType(parserRule.expresion.computedType.Name)) { parserRule.computedType = globalContext.Undefined; } else { //Lo dejo como un tipo idefinido //$"El operador 'not' no se puede aplicar a un tipo {parserRule.expresion.computedType.Name}, linea {parserRule.expresion.Start.Line} y columna {parserRule.expresion.Start.Column+1}" if (!parserRule.expresion.computedType.Equals(globalContext.Int)) { errorLogger.LogError($"({parserRule.expresion.Start.Line},{parserRule.expresion.Start.Column + 1}) - Type Error: Operator '~' cannot be applied to operand of type '{parserRule.expresion.computedType.Name}'"); parserRule.computedType = globalContext.Undefined; } else { parserRule.computedType = globalContext.Int; } } }
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 = 22; ErrorHandler.Sync(this); switch (TokenStream.LA(1)) { case T__0: { _localctx = new PurenExprContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 10; Match(T__0); State = 11; expr(0); State = 12; Match(T__1); } break; case OP_SUB: { _localctx = new NegExprContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 14; Match(OP_SUB); State = 15; expr(7); } break; case NUM: { _localctx = new NumExprContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 16; ((NumExprContext)_localctx).value = Match(NUM); } break; case ID: { _localctx = new FuncExprContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 17; ((FuncExprContext)_localctx).func = Match(ID); State = 18; Match(T__0); State = 19; ((FuncExprContext)_localctx).args = funcArgs(); State = 20; Match(T__1); } break; default: throw new NoViableAltException(this); } Context.Stop = TokenStream.LT(-1); State = 38; 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 = 36; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 1, Context)) { case 1: { _localctx = new P0ExprContext(new ExprContext(_parentctx, _parentState)); ((P0ExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 24; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 25; ((P0ExprContext)_localctx).op = Match(OP_POW); State = 26; ((P0ExprContext)_localctx).right = expr(4); } break; case 2: { _localctx = new P0ExprContext(new ExprContext(_parentctx, _parentState)); ((P0ExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 27; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 28; ((P0ExprContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == OP_MUL || _la == OP_DIV)) { ((P0ExprContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 29; ((P0ExprContext)_localctx).right = expr(4); } break; case 3: { _localctx = new P0ExprContext(new ExprContext(_parentctx, _parentState)); ((P0ExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 30; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 31; ((P0ExprContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!(_la == OP_ADD || _la == OP_SUB)) { ((P0ExprContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 32; ((P0ExprContext)_localctx).right = expr(3); } break; case 4: { _localctx = new P0ExprContext(new ExprContext(_parentctx, _parentState)); ((P0ExprContext)_localctx).left = _prevctx; PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 33; if (!(Precpred(Context, 1))) { throw new FailedPredicateException(this, "Precpred(Context, 1)"); } State = 34; ((P0ExprContext)_localctx).op = TokenStream.LT(1); _la = TokenStream.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << OP_EQ) | (1L << OP_LS) | (1L << OP_GR) | (1L << OP_NE) | (1L << OP_LE) | (1L << OP_GE))) != 0))) { ((P0ExprContext)_localctx).op = ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 35; ((P0ExprContext)_localctx).right = expr(2); } break; } } } State = 40; 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); }