#include #include #include #include #include "pile.h" void Init_Pile(struct Pile *new) { //struct Pile new; new->Pil=NULL; new->nbElements=0; //return new; } struct Nombre Typenum(string C) { struct Nombre k; //enum Numtype type; //union Test i; k.typ = Entier; for(int i=0; iEnt.ValEntier = i; else if (i.typ == Reel) cel->Ent.ValReel = i; cel->Suiv = P->Pil; P->Pil = cel; P->nbElements +=1; } /*void EmpilerR(struct Pile * P, float i) { struct Cell * cel= malloc(sizeof(struct Cell)); cel->Ent.ValReel = i; cel->Suiv = P->Pil; P->Pil = cel; P->nbElements +=1; }*/ struct Cell * Depiler(struct Pile * P) { struct Cell * res= NULL; if (P->Pil != NULL) { res = P->Pil; P->Pil= P->Pil->Suiv; } return res; } void Supprimer(struct Pile *P){ struct Cell * tmp; if(P->nbElements != 0) { tmp = P->Pil; P->Pil = P->Pil->Suiv; free(tmp); } } void Affichage(struct Cell * C) { if(C == NULL) { //printf("Rien a afficher"); } else { printf("%d \n", C->Ent.ValEntier); Affichage(C->Suiv); } } int numberOfDelimiters(char* string) { int count = 0; for (int i=0;itokens = programme; retour->taille = i; return retour; } void Executer(Etat * etat){ //struct Pile P = etat->Donnee; //Programme Program = etat->Prog; struct Cell *C1, *C2; int tail = etat->Prog->taille; int r=0; char * element; for(int i = 0;i Prog->tokens[i]); //printf("%s \n", element); if ( *element == '+') { C2 = Depiler(etat->Donnee); C1 = Depiler(etat->Donnee); if(C1 != NULL && C2 != NULL) { r= C1->Ent.ValEntier + C2->Ent.ValEntier; Empiler(etat->Donnee, r ); } else { printf("ERROR \n"); } } else if( *element == '/') { C2 = Depiler(etat->Donnee); C1 = Depiler(etat->Donnee); if(C1 != NULL && C2 != NULL) { r= C1->Ent.ValEntier / C2->Ent.ValEntier; Empiler(etat->Donnee, r ); } else { printf("ERROR \n"); } } else if( *element == '-') { C2 = Depiler(etat->Donnee); C1 = Depiler(etat->Donnee); if(C1 != NULL && C2 != NULL) { r= C1->Ent.ValEntier - C2->Ent.ValEntier; Empiler(etat->Donnee, r ); } else { printf("ERROR \n"); } } else if(*element == '*') { C2 = Depiler(etat->Donnee); C1 = Depiler(etat->Donnee); if(C1 != NULL && C2 != NULL) { r= C1->Ent.ValEntier * C2->Ent.ValEntier; Empiler(etat->Donnee, r ); } else { printf("ERROR \n"); } } else { Empiler(etat->Donnee, atoi(element)); } } printf("SORTIE : %d \n", etat->Donnee->Pil->Ent.ValEntier); }