예제 #1
0
        public override object VisitSelectionStatement([NotNull] CMinusParser.SelectionStatementContext context)
        {
            this.labelGenerator.IncrementIfCount();

            string endLabel = this.labelGenerator.GenerateIfLabel();

            this.Visit(context.logicalOrExpression());

            if (context.elseStatement != null)
            {
                string elseLabel = this.labelGenerator.GenerateElseLabel();

                this.writer.WriteConditionalJump(elseLabel);
                this.Visit(context.ifStatement);
                this.writer.WriteUnconditionalJump(endLabel);

                this.writer.WriteLabel(elseLabel);
                this.Visit(context.elseStatement);
            }
            else
            {
                this.writer.WriteConditionalJump(endLabel);
                this.Visit(context.ifStatement);
            }

            this.writer.WriteLabel(endLabel);

            return(null);
        }
예제 #2
0
        public override object VisitSelectionStatement([NotNull] CMinusParser.SelectionStatementContext context)
        {
            int selectionEndLabel = this.labelGenerator.GenerateLabel();
            int elseBodyLabel     = this.labelGenerator.GenerateLabel();

            this.Visit(context.logicalOrExpression());

            if (context.elseStatement != null)
            {
                this.writer.WriteJumpIfFalse(elseBodyLabel);
                this.Visit(context.ifStatement);
                this.writer.WriteUnconditionalJump(selectionEndLabel);

                this.writer.WriteLabel(elseBodyLabel);
                this.Visit(context.elseStatement);
            }
            else
            {
                this.writer.WriteJumpIfFalse(selectionEndLabel);
                this.Visit(context.ifStatement);
            }

            this.writer.WriteLabel(selectionEndLabel);

            return(null);
        }
        public override object VisitSelectionStatement([NotNull] CMinusParser.SelectionStatementContext context)
        {
            this.Visit(context.logicalOrExpression());

            this.internalScope++;
            this.symbolTable.EnterScope();

            this.Visit(context.ifStatement);

            this.symbolTable.ExitScope();
            this.internalScope--;

            if (context.elseStatement != null)
            {
                this.internalScope++;
                this.symbolTable.EnterScope();

                this.Visit(context.elseStatement);

                this.symbolTable.ExitScope();
                this.internalScope--;
            }

            return(null);
        }