public statementAST parseStat() { //Statement //case id designatorAST desig = null; exprAST expr = null; actParsAST actP = null; designatorStatementAumentoAST aum = null; designatorStatementDecrementoAST decr = null; Boolean actPBoo = false; //case if conditionAST condi = null; statementAST stat = null; statementAST stat2 = null; Boolean elseBoo = false; listStatementsAST tempStat, tempStat2, result; exprAST forexpr1 = null; conditionAST forexpr2 = null; exprAST forexpr3 = null; statementAST forstat = null; switch (currentToken.sym) { case sym.ID: { desig = parseDesignator(); switch (currentToken.sym) { case sym.IGUAL: { acceptIt(); expr = parseExpr(); break; } case sym.P_ABI: { acceptIt(); if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI) { actP = parseActPars(); actPBoo = true; } accept(sym.P_CER, ")"); break; } case sym.SUM_SUM: { aum = new designatorStatementAumentoAST(); acceptIt(); break; } case sym.IGU_IGU: { decr = new designatorStatementDecrementoAST(); acceptIt(); break; } accept(sym.PYCOMA, ";"); //Designator ( "=" Expr | "(" [ ActPars ] ")" | "++" | "--" ) ";" } if (expr != null) { return(new designatorStatementAsignacionAST(expr)); } else if (actP != null) { return(new designatorStatementUnActParsAST(actP)); //revisar } else if (actPBoo == true) { return(new designatorStatementUnActParsAST(actP)); //revisar } else if (actPBoo == false) //analizar posible fallo { return(new designatorStatementSinActParsAST()); } break; } case sym.IF: { accept(sym.IF, "if"); accept(sym.P_ABI, "("); condi = parseCondition(); accept(sym.P_CER, ")"); stat = parseStat(); //tempStat = new unStatementAST(stat); if (currentToken.sym == sym.ELSE) { elseBoo = true; stat2 = parseStat(); } if (elseBoo == true) { return(new ifStatementConELseAST(condi, stat, stat2)); } else { return(new ifStatementSinELseAST(condi, stat)); } break; } case sym.FOR: { accept(sym.FOR, "for"); accept(sym.P_ABI, "("); forexpr1 = parseExpr(); accept(sym.PYCOMA, ";"); if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI) { forexpr2 = parseCondition(); } accept(sym.PYCOMA, ";"); if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI) { forexpr3 = parseExpr(); } accept(sym.PYCOMA, ";"); forstat = parseStat(); if (forexpr2 != null && forexpr3 == null) { return(new forStatementConConditionAST(forexpr1, forexpr2, forstat)); } if (forexpr3 != null && forexpr2 == null) { return(new forStatementConFuntionAST(forexpr1, forexpr3, forstat)); } if (forexpr3 == null && forexpr2 == null) { return(new forStatementSoloDeclAST(forexpr1, forstat)); } if (forexpr3 != null && forexpr2 != null) { return(new forStatementConCondFuntAST(forexpr1, forexpr2, forexpr3, forstat)); } break; } case sym.WHILE: { accept(sym.WHILE, "WHILE"); accept(sym.P_ABI, "("); condi = parseCondition(); accept(sym.P_CER, ")"); stat = parseStat(); return(new whileStatementAST(condi, stat)); break; } case sym.BREAK: { accept(sym.PYCOMA); break; } case sym.RETURN: { Boolean ind = false; acceptIt(); if (currentToken.sym == sym.RES || currentToken.sym == sym.ID || currentToken.sym == sym.NUM || currentToken.sym == sym.CHARCONS || currentToken.sym == sym.TRUE || currentToken.sym == sym.FALSE || currentToken.sym == sym.NEW || currentToken.sym == sym.P_ABI) { expr = parseExpr(); ind = true; } accept(sym.PYCOMA, ";"); if (ind == true) { return(new returnStatementConExprAST(expr)); } else { return(new returnStatementSinExprAST()); } break; } case sym.READ: { acceptIt(); accept(sym.P_ABI, "("); desig = parseDesignator(); accept(sym.P_CER, ")"); accept(sym.PYCOMA, ";"); return(new readStatementAST(desig)); //revisar este return break; } case sym.WRITE: { accept(sym.P_ABI, "("); expr = parseExpr(); Symbol tempsimbol = null; if (currentToken.sym == sym.COMA) { accept(sym.COMA, ","); tempsimbol = currentToken; accept(sym.NUM, "number"); } accept(sym.P_CER, ")"); accept(sym.PYCOMA, ";"); if (tempsimbol != null) { return(new writeStatementConNumAST(tempsimbol, expr)); } else { return(new writeStatementSinNumAST(expr)); } // "write" "(" Expr [ "," number ] ")" ";" } case sym.COR_A: { parseBlock(); break; } case sym.PYCOMA: { acceptIt(); break; } } return(null); }
public factorAST parseFactor() { designatorAST desi = null; actParsAST actP = null; exprAST expr = null; switch (currentToken.sym) { case sym.ID: { desi = parseDesignator(); if (currentToken.sym == sym.P_ABI) { accept(sym.P_ABI, "("); if (currentToken.sym == sym.COMA) { actP = parseActPars(); } accept(sym.P_CER, ")"); } if (actP == null) { return(new factorDesignatorSinActParsAST(desi)); } else { return(new factorDesignatorConActParsAST(desi, actP)); } break; } case sym.NUM: { Symbol num = currentToken; accept(sym.NUM, "NUMERO"); return(new factorNumberAST(num)); } case sym.CHARCONS: { Symbol charc = currentToken; accept(sym.CHARCONS, "CHARCONS"); return(new factorCharConstAST(charc)); } case sym.TRUE: { Symbol temp = currentToken; accept(sym.TRUE, "TRUE"); return(new factorBoolAST(temp)); } case sym.FALSE: { Symbol temp = currentToken; accept(sym.FALSE, "FALSE"); return(new factorBoolAST(temp)); } case sym.NEW: { acceptIt(); Symbol temp = currentToken; accept(sym.ID, "ident"); if (currentToken.sym == sym.C_ABI) { acceptIt(); expr = parseExpr(); accept(sym.C_CER, "]"); } if (expr == null) { return(new factorNewSinExprAST(temp)); } else { return(new factorNewConExprAST(temp, expr)); } } case sym.P_ABI: { expr = parseExpr(); accept(sym.P_CER); return(new factorExprAST(expr)); } } return(null); }
public factorDesignatorConActParsAST(designatorAST d,actParsAST a) { this.designator = d; actPars = a; }