コード例 #1
0
        public override int VisitIf_stmt(BRAQParser.If_stmtContext context)
        {
            //evaluate condition
            context.cond.Accept(this);
            Label false_branch = il.DefineLabel();
            Label after_blocks = il.DefineLabel();

            il.Emit(OpCodes.Brfalse_S, false_branch);

            context.then_branch.Accept(this);

            il.Emit(OpCodes.Br_S, after_blocks);

            il.MarkLabel(false_branch);

            if (context.else_branch != null)
            {
                context.else_branch.Accept(this);
            }
            else
            {
                il.Emit(OpCodes.Nop);
            }
            il.MarkLabel(after_blocks);


            return(0);
        }
コード例 #2
0
        public override Type VisitIf_stmt(BRAQParser.If_stmtContext context)
        {
            if (context.cond.Accept(this) != typeof(bool))
            {
                string msg =
                    $"expected boolean type but got {type_dict[context.cond]} in if condition [Line {context.cond.Start.Line}]";
                Console.WriteLine(msg);

                throw new TypeMismatchError(msg);
            }

            context.then_branch.Accept(this);
            context.else_branch?.Accept(this);

            return(null);
        }
コード例 #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="BRAQParser.if_stmt"/>.
 /// <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_stmt([NotNull] BRAQParser.If_stmtContext context)
 {
     return(VisitChildren(context));
 }
コード例 #4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="BRAQParser.if_stmt"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitIf_stmt([NotNull] BRAQParser.If_stmtContext context)
 {
 }