Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void Etat28::transition(Automate* a, Symbole* s)
{
#ifdef MAP
	std::cout << "Etat28" << std::endl;
#endif
    switch(*s){
		case Symbole::OPERATEUR_MUL:
			a->pushSymbole(s);
			//~ a->pushEtat(new Etat29());
			a->pushEtat(Etat29::getInstance());
			a->decaler();
			break;

		case Symbole::POINT_VIR:
		case Symbole::PARENTHESE_FER:
		case Symbole::OPERATEUR_ADD:
			{
				Symbole* symbole = a->topSymbole();
				symbole->setType(Symbole::EXPRESSION);
				a->popEtat();
				a->etatCourant()->transition(a, symbole);
			}
			break;
		default:
			throw ExceptionSymbole(s, ExceptionSymbole::symbole_non_attendu);
			break;
	}
}
Ejemplo n.º 3
0
void Etat24::transition(Automate* a, Symbole* ) //réduction règle 17
{
#ifdef MAP
	std::cout << "Etat24" << std::endl;
#endif
	
	Symbole* terme = a->topSymbole();
	terme->setType(Symbole::TERME);
	a->popEtat();
	a->etatCourant()->transition(a, terme);
}
Ejemplo n.º 4
0
Symbole* Lexer::getSymbole()
{
    if(getSymbole(next).compare("const")==0)
    {
        //cout << "CONST" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(CONST);
        return toReturn;
    }
    else if(getSymbole(next).compare("var")==0)
    {
        //cout << "VAR" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(VAR);
        return toReturn;
    }
    else if(getSymbole(next).compare("ecrire") == 0)
    {
        //cout << "ECRIRE" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(ECRIRE);
        return toReturn;
    }
    else if (getSymbole(next).compare("lire") == 0)
    {
        //cout << "LIRE" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(LIRE);
        return toReturn;
    }
    else if (getSymbole(next).compare(";") == 0)
    {
        //cout << "PVG" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(PVG);
        return toReturn;
    }
    else if (getSymbole(next).compare(",") == 0)
    {
        //cout << "VG" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(VG);
        return toReturn;
    }
    else if (getSymbole(next).compare("=") == 0)
    {
        //cout << "EG" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(EG);
        return toReturn;
    }
    else if (getSymbole(next).compare("(") == 0)
    {
        //cout << "PARG" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(PARG);
        return toReturn;
    }
    else if (getSymbole(next).compare(")") == 0)
    {
        //cout << "PARD" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(PARD);
        return toReturn;
    }
    else if (getSymbole(next).compare(":=") == 0)
    {
        //cout << "AF" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(AF);
        return toReturn;
    }
    else if (getSymbole(next).compare("+") == 0)
    {
        //cout << "PLUS" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(PLUS);
        return toReturn;
    }
    else if (getSymbole(next).compare("-") == 0)
    {
        //cout << "MOINS" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(MOINS);
        return toReturn;
    }
    else if (getSymbole(next).compare("*") == 0)
    {
        //cout << "MULT" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(MULT);
        return toReturn;
    }
    else if (getSymbole(next).compare("/") == 0)
    {
        //cout << "DIV" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(DIV);
        return toReturn;
    }
    else if (testRegex(getSymbole(next), NB))
    {
        //cout << "NB" << endl;
        Nombre* toReturn = new Nombre(stoi(getSymbole(next)));
        toReturn->setType(NB);
        return toReturn;
    }
    else if(testRegex(getSymbole(next), ID))
    {
        //cout << "ID" << endl;
        Variable* toReturn = new Variable();
        toReturn->setID(getSymbole(next));
        toReturn->setType(ID);
        return toReturn;
    }
    else if (getSymbole(next).compare("$") == 0)
    {
        //cout << "DOL" << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(DOL);
        return toReturn;
    }
    else
    {
        cerr << "Erreur lexicale caractere "<< getSymbole(next) << endl;
        Symbole* toReturn = new Symbole();
        toReturn->setType(ERR);
        return toReturn;
    }
    //next++;
    return NULL;
}