Ejemplo n.º 1
0
 public AstMethodDecl(AstType at, AstId i, AstFormalList afl, 
 AstVarDeclList avl, AstStmtList asl)
 {
     t=at; mid=i; fl=afl; vl=avl; sl=asl;
 }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
 // VarDeclList ---
 public IrStmtList visit(AstVarDeclList n)
 {
     IrStmtList sl = new IrStmtList();
     IrStmt s;
     for (int i = 0; i < n.Count(); i++)
     {
         s = n[i].accept(this);
         if (s != null)
             sl.add(s);
     }
     if (sl.size() > 0)
         return sl;
     else
         return null;
 }
Ejemplo n.º 4
0
 public void visit(AstVarDeclList n) 
 {
     for (int i = 0; i < n.size(); i++)
         n.elementAt(i).accept(this);
 }
Ejemplo n.º 5
0
 public AstClassDecl(AstId ci, AstId pi, AstVarDeclList avl, AstMethodDeclList aml)
 {
     cid = ci; pid = pi; vl = avl; ml = aml;
 }
Ejemplo n.º 6
0
 public void visit(AstVarDeclList n)
 {
     for (int i = 0; i < n.Count(); i++)
         n[i].accept(this);
 }
Ejemplo n.º 7
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 );
        }
Ejemplo n.º 8
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 );
        }
Ejemplo n.º 9
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 );
        }
Ejemplo n.º 10
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 );
        }