Object VisitUndeclAST(undeclAST var, object arg) { int numaux = ((Integer)arg).intValue(); printtab(numaux); System.out.println(c.getClass().getName()); if(c.- !=null) c.-.visit(this,new Integer(numaux+1)); else{printtab(numaux+1); Console.WriteLine(“NULL”);} return null; }
public declAST parseMethodDecl() { declAST varD=null; declsAST varD2=null; declsAST varD3 = null; Symbol temp = currentToken; typeAST type=null; if (currentToken.sym == sym.ID || currentToken.sym == sym.VOID) { if (currentToken.sym == sym.ID) { type = parseType(); } if (currentToken.sym == sym.VOID) { accept(sym.VOID, "void"); } temp = currentToken; accept(sym.ID, "ident"); accept(sym.P_ABI, "("); formParsAST formP=null; if (currentToken.sym == sym.ID) { formP=parseFormPars(); } else accept(sym.P_CER, ")"); Boolean ind = false; while (currentToken.sym == sym.ID) { if (ind == false) { varD = parseVarDecl(); varD2 = new undeclAST(varD); varD3 = varD2; ind = true; } else { varD = parseVarDecl(); varD2 = new undeclAST(varD); varD3 = varD2; varD2 = new varsdeclAST(varD2,varD3); } } blockAST parseB=parseBlock(); if(type==null && formP==null) { if (ind == true) { return new methodVoidSinFormDeclsAST(temp); } else { return new methodTipoSinFormParsAST(temp, varD2); // return voidSinFormParsAST(temp, varD, parseB); } } if (type == null && varD == null) { return new methodTipoSinVarDeclAST(temp,formP); // return voidSinVarDeclAST(temp,formP,parseB); } if (type == null && varD != null && formP != null) { if (ind == true) return new methodVoidConFormDeclsAST(varD2, formP, temp); // return voidConForm_DeclsAST(temp, varD2, formP, parseB); else //return voidConForm_DeclsAST(temp, varD, formP, parseB); return new methodVoidSinVarDeclAST(formP, temp); } if (type == null && varD == null && formP == null) { return new methodVoidSinFormDeclsAST(temp); } } return null; }
//METODOS PRIVADOS DE PARSING PARA CADA NO TERMINAL: public programAST parseProgram() { declAST conD,conD2; declAST varD,varD2; declAST claD, claD2; declAST metD, metD2; declsAST result=null; declsAST temp=null; Boolean ind = false; Boolean var = false; Boolean var2 = false; Symbol symtemp; if (currentToken.sym == sym.CLASS) { accept(sym.CLASS, "class"); symtemp = currentToken; accept(sym.ID, "ident"); while (currentToken.sym == sym.CONST || currentToken.sym == sym.ID || currentToken.sym == sym.CLASS) { var=true; switch (currentToken.sym) { case sym.CONST: { if (ind == false) { conD = parseConstDecl(); result=new undeclAST(conD); ind = true; } else { conD2 = parseConstDecl(); temp = new undeclAST(conD2); result = new varsdeclAST(result, temp); } break; } case sym.ID: { if (ind == false) { varD = parseVarDecl(); result = new undeclAST(varD); ind = true; } else { varD2 = parseVarDecl(); temp = new undeclAST(varD2); result = new varsdeclAST(result, temp); } break; } case sym.CLASS: { if (ind == false) { claD = parseClassDecl(); result = new undeclAST(claD); ind = true; } else { claD2 = parseClassDecl(); temp = new undeclAST(claD2); result = new varsdeclAST(result, temp); } break; } // return result; } } accept(sym.COR_A, "{"); while (currentToken.sym == sym.ID || currentToken.sym == sym.VOID) { var2=true; if (ind == false) { metD = parseMethodDecl(); result = new undeclAST(metD); ind = true; } else { metD2 = parseMethodDecl(); temp = new undeclAST(metD2); result = new varsdeclAST(result, temp); } } accept(sym.COR_C, "}"); if (var==false && var2==false) { return new programSinNadaAST(symtemp); } if (var==true && var2==false) { return new programSinMetAST(symtemp,result); } if (var=false && var2==true) { return new programSinDeclAST(symtemp,result); } if (var==true && var2==true) { return new programConTodoAST(symtemp,result); } } else error(currentToken, "CLASS"); return null; }
public declAST parseClassDecl() { declsAST temp=null; declsAST result=null; declAST varD; accept(sym.CLASS, "CLASS"); Symbol temptoken = currentToken; accept(sym.ID); accept(sym.COR_A, "{"); if (currentToken.sym == sym.COR_C) { accept(sym.COR_C, "}"); return new classSinVarDeclAST(temptoken); } else { Boolean ind=false; while (currentToken.sym == sym.ID) { if(ind==false) { varD = parseVarDecl(); result = new undeclAST(varD); } else { varD = parseVarDecl(); temp = new undeclAST(varD); result = new varsdeclAST(temp,result); } //revisar } accept(sym.COR_C, "}"); } return new classConVarDeclAST(result,temptoken); }