public void Visit(IdExprContext parserRule, IObjectContext <IVar, IVar> context)
 {
     if (!context.IsDefineVar(parserRule.id.Text))
     {
         errorLogger.LogError($"({parserRule.id.Line},{parserRule.id.Column + 1}) - NameError : The variable '{parserRule.id.Text}' does not exist in the current context");
         parserRule.computedType = globalContext.Undefined;
     }
     else
     {
         parserRule.computedType = context.GetVar(parserRule.id.Text).Type;
     }
 }
        public IHolderCil Visit(IdExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil)
        {
            //Si no es una variable declarada dentro del metodo entonces es un atributo de la clase (self)

            if (!contextCil.variables.ContainsKey(parserRule.id.Text))
            {
                var value = new LocalCil($"_value{cilTree.LocalCils.Count}");
                cilTree.LocalCils.Add(value);
                cilTree.ThreeDirInses.Add(new GetAttrCil(value, cilTree.self, typeCil.GetAttributeCilsByCoolName(parserRule.id.Text)));
                return(value);
            }

            return(contextCil.variables[parserRule.id.Text]);
        }
コード例 #3
0
    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);
    }
コード例 #4
0
ファイル: QtParser.cs プロジェクト: mbid/qt
    public IdExprContext idExpr()
    {
        IdExprContext _localctx = new IdExprContext(Context, State);

        EnterRule(_localctx, 12, RULE_idExpr);
        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 92; _localctx.id = Match(ID);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }