bool E1::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case VAR: { automate.Decalage(s, new E4); return true; } case CONST: { automate.Decalage(s, new E5); return true; } case LIRE: case ECRIRE: case ID: case FIN: { automate.Reduction(new PartieInstructions, 0); return true; } case D: { automate.Decalage(s, new E3); return true; } case PI: { automate.Decalage(s, new E2); return true; } } return false; }
bool Etat23::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case pf : case add : case moins : case fois : case divise : case pv : //Reduction r20 : F -> num { Num* num= (Num*) automate.getNthSymbole(0); num->setF(); automate.popAndDeleteState(); automate.popSymbole(); automate.reduction(num); break; } default : break; } return false; }
bool E34::transition(Automate& automate, Symbole* symbole) throw(std::pair<int, string>) { switch (symbole->getType()) { case(VG) : automate.decalageTerminal(symbole, new E35); return true; case(PVG) : automate.decalageTerminal(symbole, new E39); return true; case(ID) : Symbole* symboleAnticipe = new Symbole(); symboleAnticipe->setType(VG); automate.decalageAnticipe(symboleAnticipe, new E35); std::pair<int, string> p = std::make_pair(0, "Erreur syntaxique symbole \",\" attendu"); throw(p); return true; } Symbole* symboleAnticipe = new Symbole(); symboleAnticipe->setType(PVG); automate.decalageAnticipe(symboleAnticipe, new E39); std::pair<int, string> p = std::make_pair(0, "Erreur syntaxique symbole \";\" attendu"); throw(p); return true; }
bool GeneratedState0::Transition (Automate & automate, Symbole *s) { // Generated code : switch ((int)*s) { case CONST: automate.Reduction(0); break; case ECRIRE: automate.Reduction(0); break; case IDENTIFIANT: automate.Reduction(0); break; case LIRE: automate.Reduction(0); break; case PDECL: automate.Decalage(s, new GeneratedState0p); break; case VAR: automate.Reduction(0); break; case PROGRAMME: automate.Consommer(); Programme* progSymbole; progSymbole = static_cast<Programme*>(s); automate.Accepter(progSymbole); break; default: automate.SetErreur(); break; } return false; }
bool Etat8::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case af : automate.decalage(s, new Etat17("17")); break; default : automate.recuperation(new Symbole(107), true); // on est sûr qu'il manque un := break; } return false; }
bool GeneratedState1122::Transition (Automate & automate, Symbole *s) { // Generated code : switch ((int)*s) { case OUVRE_PAR: automate.Consommer(); automate.Decalage(s, new GeneratedState114); break; case FACTEUR: automate.Decalage(s, new GeneratedState11221); break; case IDENTIFIANT: automate.Consommer(); automate.Decalage(s, new GeneratedState115); break; case VALEUR: automate.Consommer(); automate.Decalage(s, new GeneratedState116); break; default: automate.SetErreur(); break; } return false; }
bool GeneratedState1::Transition (Automate & automate, Symbole *s) { // Generated code : switch ((int)*s) { case FIN: automate.Reduction(2); break; case ECRIRE: automate.Consommer(); automate.Decalage(s, new GeneratedState11); break; case IDENTIFIANT: automate.Consommer(); automate.Decalage(s, new GeneratedState13); break; case LIRE: automate.Consommer(); automate.Decalage(s, new GeneratedState12); break; default: automate.SetErreur(); break; } return false; }
bool GeneratedState12p::Transition (Automate & automate, Symbole *s) { // Generated code : switch ((int)*s) { case POINT_VIRGULE: automate.Consommer(); automate.Decalage(s, new GeneratedState12s); break; default: automate.SetErreur(); break; } return false; }
bool E29::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case FERMEPAR: { automate.Decalage(s, new E36); return true; } case OPA: { automate.Decalage(s, new E27); return true; } } return false; }
bool E28::transition(Automate& automate, Symbole* symbole) throw(std::pair<int, string>) { switch (symbole->getType()) { case(PLUS) : automate.decalageTerminal(symbole, new E14); return true; case(MOINS) : automate.decalageTerminal(symbole, new E14); return true; case(PVG) : automate.decalageTerminal(symbole, new E29); return true; } std::pair<int, string> p = std::make_pair(1, "Erreur de syntaxe (attendu : \"+\", \"-\" ou \";\")."); throw(p); return false; }
bool Etat20::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case fois : automate.decalage(s, new Etat33("33")); break; case divise : automate.decalage(s, new Etat34("34")); break; case pf : case add : case moins : case pv : { //TODO : r16 E → T Expression* expr = (Expression*)automate.getNthSymbole(0); expr->setE(); automate.popAndDeleteState(); automate.popSymbole(); automate.reduction(expr); break; } case OM : automate.decalage(s, new Etat32("32")); break; default: break; } return false; }
bool E4::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case ID: { automate.Decalage(s, new E12); return true; } case LID: { automate.Decalage(s, new E11); return true; } } return false; }
bool Etat42::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case num : automate.decalage(s, new Etat43("43")); break; default : break; } return false; }
bool Etat13::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case eg : automate.decalage(s, new Etat26("26")); break; default : break; } return false; }
bool E10::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case VAR: case CONST: case LIRE: case ECRIRE: case ID: case FIN: { //Symbole * point_virgule = delete automate.PopSymbole(); ListeDeclaration * d = (ListeDeclaration *) automate.PopSymbole(); PartieDeclarative * pd = (PartieDeclarative *) automate.PopSymbole(); if( ! pd->AjouterDeclarations(d) ) { // nettoyer les Declaration for(Declaration * decl : d->GetListeDeclarations()) { delete decl; } delete d; for(auto & decl : pd->GetDeclarations()) { delete decl.second; } delete pd; throw DOUBLE_DECLARATION; } else { delete d; automate.Reduction(pd, 3); return true; } } } return false; }
bool E32::transition(Automate& automate, Symbole *symbole) throw(std::pair<int, string>) { switch (symbole->getType()) { case(NB) : automate.decalageTerminal(symbole, new E33); return true; } std::pair<int, string> p = std::make_pair(1, "Erreur de syntaxe nombre attendu"); throw(p); return false; }
bool E26::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case VAL: { automate.Decalage(s, new E33); return true; } } return false; }
bool GeneratedState22::Transition (Automate & automate, Symbole *s) { // Generated code : switch ((int)*s) { case POINT_VIRGULE: automate.Reduction(1); break; case VIRGULE: automate.Reduction(1); break; case IDENTIFIANT : //récupération sur erreur automate.Reduction(1); break; default: automate.SetErreur(); break; } return false; }
bool Etat41::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { // R21 : F -> ( E ) case pf : case add : case moins : case fois : case divise : case pv : { int nbSymboles = 3; Expression* expr = (Expression*) automate.getNthSymbole(1); OpParenthese* opPar = new OpParenthese(expr); for (unsigned int i = 0; i < nbSymboles; ++i) { automate.popAndDeleteState(); } automate.popAndDeleteSymbole(); automate.popSymbole(); // on garde E automate.popAndDeleteSymbole(); automate.reduction(opPar); } break; default: break; } return false; }
bool E21::transition(Automate& automate, Symbole* symbole) throw(std::pair<int, string>) { switch (symbole->getType()) { case(ID) : automate.decalageTerminal(symbole, new E19); return true; case(NB) : automate.decalageTerminal(symbole, new E20); return true; case(PARG) : automate.decalageTerminal(symbole, new E21); return true; case(E) : automate.decalageNonTerminal(symbole, new E23); return true; case(T) : automate.decalageNonTerminal(symbole, new E22); return true; case(F) : automate.decalageNonTerminal(symbole, new E18); return true; } std::pair<int, string> p = std::make_pair(1, "Erreur de syntaxe (attendu : \"(\", nombre, id, ou expression)."); throw(p); return false; }
bool Etat24::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case E : automate.decalage(s, new Etat35("35")); break; case T : automate.decalage(s, new Etat20("20")); break; case F : automate.decalage(s, new Etat21("21")); break; case id : automate.decalage(s, new Etat22("22")); break; case num : automate.decalage(s, new Etat23("23")); break; case po: automate.decalage(s, new Etat24("24")); break; default : break; } return false; }
bool Etat16::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case id : case r : case w : case dollar : { // TODO r10 LI → LI I pv int nbSymboles = 3; Instruction* inst = (Instruction*) automate.getNthSymbole(1); BlocInstruction* blocInst = (BlocInstruction*) automate.getNthSymbole(2); blocInst->addInstruction(inst); // réduction manuelle ici for (unsigned int i = 0; i < nbSymboles; ++i) { automate.popAndDeleteState(); } automate.popAndDeleteSymbole(); automate.popSymbole(); // on garde I automate.popSymbole(); // on le pop sans le supprimer car il s'agit de blocDec automate.reduction(blocInst); // réduction manuelle break; } default : break; } return false; }
bool E6::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case POINT_VIRGULE: { automate.Decalage(s, new E15); return true; } } return false; }
bool E13::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case VIRGULE: { automate.Decalage(s, new E25); return true; } case POINT_VIRGULE: { ListeIdentifiantsValeurs * lidv = (ListeIdentifiantsValeurs *) automate.PopSymbole(); lidv->SetIdent(D); //Symbole * constante = delete automate.PopSymbole(); //réduire R4 automate.Reduction(lidv, 2); return true; } } return false; }
bool Etat30::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case id : case num : case po : //R22 : OA -> + { int nbSymboles = 1; oa* s = new oa("+"); automate.reduction(nbSymboles,s); break; } default : break; } return false; }
bool E2::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case LIRE: { automate.Decalage(s, new E7); return true; } case ECRIRE: { automate.Decalage(s, new E8); return true; } case ID: { automate.Decalage(s, new E9); return true; } case FIN: { PartieInstructions * pi = (PartieInstructions *) automate.PopSymbole(); PartieDeclarative * pd = (PartieDeclarative *) automate.PopSymbole(); Programme * prog = new Programme(pd->GetDeclarations(), pi->GetInstructions()); delete pi; delete pd; //réduire R0 automate.Reduction(prog, 2); return true; } case I: { automate.Decalage(s, new E6); return true; } } return false; }
bool E8::Transition ( Automate & automate, Symbole * s ) { switch(*s) { case OUVREPAR: { automate.Decalage(s, new E20); return true; } case ID: { automate.Decalage(s, new E21); return true; } case VAL: { automate.Decalage(s, new E22); return true; } case E: { automate.Decalage(s, new E17); return true; } case T: { automate.Decalage(s, new E18); return true; } case F: { automate.Decalage(s, new E19); return true; } } return false; }
bool Etat38::transition(Automate & automate, Symbole * s ){ int idSym = *s ; switch (idSym) { case v : case pv : { //Regle R8 : V → V v id int nbSymboles = 3; Identificateur* identif = (Identificateur*) automate.getNthSymbole(0); DeclarationVar* declaV = ((DeclarationVar*) automate.getNthSymbole(2)); declaV->addIdentificateur(identif); // check doublons bool ok = Identificateur::checkDouble((string)*identif); if (!ok) { return false; } // réduction manuelle ici for (unsigned int i = 0; i < nbSymboles; ++i) { automate.popAndDeleteState(); } automate.popSymbole(); // id automate.popAndDeleteSymbole(); automate.popSymbole(); // on le pop sans le supprimer car il s'agit de declaV automate.reduction(declaV); // réduction manuelle break; } default : break; } return false; }
bool E25::transition(Automate& automate, Symbole *symbole) { automate.reduction(R9); return true; }