Exemplo n.º 1
0
    public LineContext line()
    {
        LineContext _localctx = new LineContext(Context, State);

        EnterRule(_localctx, 12, RULE_line);
        try {
            State = 58;
            ErrorHandler.Sync(this);
            switch (TokenStream.LA(1))
            {
            case T__2:
            case T__6:
            case ID:
            case WORD:
                _localctx = new UnlabeledLineContext(_localctx);
                EnterOuterAlt(_localctx, 1);
                {
                    State = 53; instruction();
                }
                break;

            case T__3:
                _localctx = new LabeledLineContext(_localctx);
                EnterOuterAlt(_localctx, 2);
                {
                    State = 54; Match(T__3);
                    State = 55; ((LabeledLineContext)_localctx).label = Match(ID);
                    State = 56; Match(T__4);
                    State = 57; instruction();
                }
                break;

            default:
                throw new NoViableAltException(this);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Exemplo n.º 2
0
        public override void ExitLabeledLine([NotNull] LabeledLineContext context)
        {
            base.ExitLabeledLine(context);

            var symbol = context.ID().Symbol;

            CheckValidLabel(symbol, isIdentifyingLine: true);

            var text = symbol.Text;

            if (_usedLabels.Contains(text))
            {
                var message = new Message(
                    SeverityEnum.Error,
                    $"Labels' must identify only one instruction.",
                    symbol.Line,
                    symbol.Column);
                _messages.Add(message);
            }
            else
            {
                _usedLabels.Add(text);
            }
        }