コード例 #1
0
ファイル: MyVisitor.cs プロジェクト: ofmendez/Danfab
    //######################
    // SWITCH's
    //######################

    public override object VisitSwitch_regular(FaParser.Switch_regularContext context)
    {
        int    nCases = context.dataType().Length;
        string id     = context.ID().GetText();
        bool   thrown = false;

        if (Exist(id) is MyVariable)           //TODO : agregar array
        {
            object value = ((MyVariable)Exist(id)).value;
            for (int i = 0; i < nCases; i++)
            {
                object caseValue = VisitDataType(context.dataType(i));
                if (caseValue.GetType() == value.GetType() && caseValue == value)
                {
                    Visit(context.body_regular(i));
                    thrown = true;
                    break;
                }
            }
            if (context.body_regular().Length > nCases && !thrown)
            {
                Visit(context.body_regular(context.body_regular().Length - 1));
            }
        }
        return(null);
    }
コード例 #2
0
ファイル: FaBaseVisitor.cs プロジェクト: ofmendez/Danfab
 /// <summary>
 /// Visit a parse tree produced by <see cref="FaParser.switch_regular"/>.
 /// <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 VisitSwitch_regular([NotNull] FaParser.Switch_regularContext context)
 {
     return(VisitChildren(context));
 }