Exemplo n.º 1
0
        // if statement
        // ifclause (elseifclause)* (elseclause)? <<endif>>
        public override int VisitIf_statement(YarnSpinnerParser.If_statementContext context)
        {
            // label to give us a jump point for when the if finishes
            string endOfIfStatementLabel = compiler.RegisterLabel("endif");

            // handle the if
            var ifClause = context.if_clause();

            generateClause(endOfIfStatementLabel, ifClause.statement(), ifClause.expression());

            // all elseifs
            foreach (var elseIfClause in context.else_if_clause())
            {
                generateClause(endOfIfStatementLabel, elseIfClause.statement(), elseIfClause.expression());
            }

            // the else, if there is one
            var elseClause = context.else_clause();

            if (elseClause != null)
            {
                generateClause(endOfIfStatementLabel, elseClause.statement(), null);
            }

            compiler.Emit(ByteCode.Label, endOfIfStatementLabel);

            return(0);
        }
Exemplo n.º 2
0
        // if statement ifclause (elseifclause)* (elseclause)? <<endif>>
        public override int VisitIf_statement(YarnSpinnerParser.If_statementContext context)
        {
            context.AddErrorNode(null);

            // label to give us a jump point for when the if finishes
            string endOfIfStatementLabel = this.compiler.RegisterLabel("endif");

            // handle the if
            var ifClause = context.if_clause();

            this.GenerateClause(endOfIfStatementLabel, ifClause, ifClause.statement(), ifClause.expression());

            // all elseifs
            foreach (var elseIfClause in context.else_if_clause())
            {
                this.GenerateClause(endOfIfStatementLabel, elseIfClause, elseIfClause.statement(), elseIfClause.expression());
            }

            // the else, if there is one
            var elseClause = context.else_clause();

            if (elseClause != null)
            {
                this.GenerateClause(endOfIfStatementLabel, elseClause, elseClause.statement(), null);
            }

            this.compiler.CurrentNode.Labels.Add(endOfIfStatementLabel, this.compiler.CurrentNode.Instructions.Count);

            return(0);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="YarnSpinnerParser.if_statement"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitIf_statement([NotNull] YarnSpinnerParser.If_statementContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="YarnSpinnerParser.if_statement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitIf_statement([NotNull] YarnSpinnerParser.If_statementContext context)
 {
 }