Beispiel #1
0
        /* throws ParseException */
        /* final */
        public static AstVarDeclList astVarDeclList()
        {
            AstVarDecl v;
            AstVarDeclList vl = new AstVarDeclList();
            bool done = false;

            jj_consume_token(AstRegExpId.kw56);
            jj_consume_token(AstRegExpId.kwVarDeclList);

            // label_2:
            while (!done)
            {
                switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk)
                {
                    case AstRegExpId.kw56:

                        break;

                    default:

                        jj_la1[1] = jj_gen;
                        done = true;
                        break;
                }

                if (!done)
                {
                    v = astVarDecl();
                    vl.Add(v);
                }
            }

            jj_consume_token(AstParserConstants.AstRegExpId.kw57);
            {if (true) return vl;}
            throw new Error("Missing return statement in function");
        }
Beispiel #2
0
        /* throws ParseException */
        // --------------------------------------------------------------------------
        // ClassDecl  -> "class" <ID> ["extends" <ID>] "{" {VarDecl} {MethodDecl} "}"
        // --------------------------------------------------------------------------
        /* final */
        public static AstClassDecl ClassDecl()
        {
            AstId cid;                                     // Name of this class
            AstId pid = null;                              // Name of the super class (if it exists)
            AstMethodDecl m;                               // Reference to a class level method
            AstMethodDeclList ml = new AstMethodDeclList();   // List of class methods
            AstVarDecl v;                                  // Reference to a class level variable
            AstVarDeclList vl = new AstVarDeclList();
            bool done;

            jj_consume_token(MpRegExpId.CLASS);
            cid = Id();

            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.EXTENDS:
                    jj_consume_token(MpRegExpId.EXTENDS);
                    pid = Id();
                    break;
                default:
                    jj_la1[3] = jj_gen;
                    break;
            }

            jj_consume_token(MpRegExpId.LBRACE);

            /* label_4: */
            done = false;
            while (!done)
            {
                switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                {
                    case MpRegExpId.BOOLEAN:
                        break;
                    case MpRegExpId.INT:
                        break;
                    case MpRegExpId.ID:
                        break;

                    default:
                        jj_la1[4] = jj_gen;
                        done = true;
                        break /* label_4 */;
                }
                if (!done)
                {
                    v = VarDecl();
                    vl.Add(v);
                }
            }

            /* label_5: */
            done = false;
            while (!done)
            {
                switch ((jj_ntk==MpRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk)
                {
                    case MpRegExpId.PUBLIC:
                        break;
                    default:
                        jj_la1[5] = jj_gen;
                        done = true;
                        break /* label_5 */;
                }
                if (!done)
                {
                    m = MethodDecl();
                    ml.Add(m);
                }
            }
            jj_consume_token(MpRegExpId.RBRACE);
            return new AstClassDecl( cid, pid, vl, ml );
        }
Beispiel #3
0
        /* throws ParseException */
        /// <summary>
        /// MainMethod  -> "public" "static" "void" "main" "(" "String" "[" "]" <ID> ")" "{" {VarDecl} {Statement} "}"
        /// </summary>
        /// <returns></returns>
        /* final */
        public static AstMethodDecl MainMethod()
        {
            DemiTasse.ast.AstType t = null;
            AstId id = new AstId( "main" );
            AstFormalList fl = null;
            AstVarDecl v;
            AstVarDeclList vl = new AstVarDeclList();
            AstStmt s;
            AstStmtList sl = new AstStmtList();
            bool done;

            jj_consume_token(MpRegExpId.PUBLIC);
            jj_consume_token(MpRegExpId.STATIC);
            jj_consume_token(MpRegExpId.VOID);
            jj_consume_token(MpRegExpId.MAIN);
            jj_consume_token(MpRegExpId.LPAREN);
            jj_consume_token(MpRegExpId.STRING);
            jj_consume_token(MpRegExpId.LBRACKET);
            jj_consume_token(MpRegExpId.RBRACKET);
            jj_consume_token(MpRegExpId.ID);
            jj_consume_token(MpRegExpId.RPAREN);
            jj_consume_token(MpRegExpId.LBRACE);

            /* label_6: */
            while (jj_2_1(2))
            {
                v = VarDecl();
                vl.Add(v);
            }

            /* label_7: */
            done = false;
            while (!done)
            {
                switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                {
                    case MpRegExpId.IF:
                        break;
                    case MpRegExpId.RETURN:
                        break;
                    case MpRegExpId.SYSTEM_OUT_PRINTLN:
                        break;
                    case MpRegExpId.THIS:
                        break;
                    case MpRegExpId.WHILE:
                        break;
                    case MpRegExpId.ID:
                        break;
                    case MpRegExpId.LBRACE:
                        break;
                    default:
                        jj_la1[6] = jj_gen;
                        done = true;
                        break /* label_7 */;
                }
                if(!done)
                {
                    s = Statement();
                    sl.Add(s);
                }
            }
            jj_consume_token(MpRegExpId.RBRACE);
            return new AstMethodDecl( t, id, fl, vl, sl );
        }
Beispiel #4
0
        /* throws ParseException */
        // -----------------------------------------------------------------------------
        // "public" (Type | "void") <ID> "(" [Formals] ")" "{" {VarDecl} {Statement} "}"
        // -----------------------------------------------------------------------------
        /* final */
        public static AstMethodDecl MethodDecl()
        {
            DemiTasse.ast.AstType t = null;
            AstId id;
            AstFormalList fl = null;
            AstVarDecl v;
            AstVarDeclList vl = new AstVarDeclList();
            AstStmt s;
            AstStmtList sl = new AstStmtList();

            jj_consume_token(MpRegExpId.PUBLIC);
            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.VOID:
                    jj_consume_token(MpRegExpId.VOID);
                    break;
                case MpRegExpId.BOOLEAN:
                    t = Type();
                    break;
                case MpRegExpId.INT:
                    t = Type();
                    break;
                case MpRegExpId.ID:
                    t = Type();
                    break;
                default:
                    jj_la1[7] = jj_gen;
                    jj_consume_token(MpRegExpId.UNDEFINED);
                    throw new MiniParseException();
            }

            id = Id();
            jj_consume_token(MpRegExpId.LPAREN);

            switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case MpRegExpId.BOOLEAN:
                    fl = Formals();
                    break;
                case MpRegExpId.INT:
                    fl = Formals();
                    break;
                case MpRegExpId.ID:
                    fl = Formals();
                    break;
                default:
                    jj_la1[8] = jj_gen;
                    break;
            }

            jj_consume_token(MpRegExpId.RPAREN);
            jj_consume_token(MpRegExpId.LBRACE);

            /* label_8: */
            while (jj_2_2(2))
            {
                v = VarDecl();
                vl.Add(v);
            }

            /* label_9:*/
            bool done = false;
            while (!done)
            {
                switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                {
                    case MpRegExpId.IF:
                        break;
                    case MpRegExpId.RETURN:
                        break;
                    case MpRegExpId.SYSTEM_OUT_PRINTLN:
                        break;
                    case MpRegExpId.THIS:
                        break;
                    case MpRegExpId.WHILE:
                        break;
                    case MpRegExpId.ID:
                        break;
                    case MpRegExpId.LBRACE:
                        break;
                    default:
                        jj_la1[9] = jj_gen;
                        done = true;
                        break /* label_9 */;
                }
                if (!done)
                {
                    s = Statement();
                    sl.Add(s);
                }
            }

            jj_consume_token(MpRegExpId.RBRACE);
            return new AstMethodDecl( t, id, fl, vl, sl );
        }
Beispiel #5
0
        /* throws ParseException */
        // ----------------------------------------------------------
        // MainClass  -> "class" <ID> "{" MainMethod {MethodDecl} "}"
        // ----------------------------------------------------------
        /* final */
        public static AstClassDecl MainClass()
        {
            AstId cid;                                     // Name of this class
            AstId pid = null;                              // Name of the super class (if it exists)
            AstMethodDecl m;                               // Reference to a class level method
            AstMethodDeclList ml = new AstMethodDeclList();   // List of class methods
            AstVarDecl v;                                  // Reference to a class level variable
            AstVarDeclList vl = new AstVarDeclList();
            bool done = false;

            jj_consume_token(MpRegExpId.CLASS);
            cid = Id();
            jj_consume_token(MpRegExpId.LBRACE);

            /* label_2: */
            while (!done)
            {
                switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                {
                    case MpRegExpId.BOOLEAN:
                        break;
                    case MpRegExpId.INT:
                        break;
                    case MpRegExpId.ID:
                        break;
                    default:
                        jj_la1[1] = jj_gen;
                        done = true;
                        break /* label_2 */;
                }
                if (!done)
                {
                    v = VarDecl();
                    vl.Add(v);
                }
            }

            // Get a reference to the Main method and add it to the list of methods in this class
            m = MainMethod();
            ml.Add(m);

            done = false;
            /* label_3: */
            while (!done)
            {
                switch ((jj_ntk == MpRegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                {
                    case MpRegExpId.PUBLIC:
                        break;
                    default:
                        jj_la1[2] = jj_gen;
                        done = true;
                        break /* label_3 */;
                }
                if (!done)
                {
                    m = MethodDecl();
                    ml.Add(m);
                }
            }
            jj_consume_token(MpRegExpId.RBRACE);
            return new AstClassDecl( cid, pid, vl, ml );
        }