ne compile pas mais on sait jamais

This commit is contained in:
Axel O 2022-12-06 21:37:58 +01:00
vanhempi 32829d36a3
commit d6ce6585f1
5 muutettua tiedostoa jossa 36 lisäystä ja 16 poistoa

BIN
forth

Binary file not shown.

BIN
main

Binary file not shown.

13
main.c
Näytä tiedosto

@ -8,12 +8,12 @@ int main(int argc, char * argv[])
{ {
/*struct Pile P; /*struct Pile P;
Init_Pile(&P); Init_Pile(&P);
Empiler(&P, 4); Empiler(&P, '4');
Empiler(&P, 5); Empiler(&P, '5');
struct Cell * res = Depiler(&P); struct Cell * res = Depiler(&P);
//Supprimer(&P); //Supprimer(&P);
Affichage(P.Pil); Affichage(P.Pil);
printf("%d \n", res->Ent); Affiche_Nombre(res->Ent);*/
Programme * P; Programme * P;
P = lexer(argv[1]); P = lexer(argv[1]);
@ -21,13 +21,14 @@ int main(int argc, char * argv[])
for(int i=0; i<P->taille; i++) for(int i=0; i<P->taille; i++)
{ {
printf("TOKEN : %s \n", P->tokens[i]); printf("TOKEN : %s \n", P->tokens[i]);
}*/ }
/*for(int i=0; i<E->Prog->taille; i++) /*for(int i=0; i<E->Prog->taille; i++)
{ {
printf("TOKEN : %s \n", E->Prog->tokens[i]); printf("TOKEN : %s \n", E->Prog->tokens[i]);
}*/ }*/
Etat * E; /*Etat * E;
E= malloc(sizeof(Etat)); E= malloc(sizeof(Etat));
E->Donnee = malloc(sizeof(struct Pile)); E->Donnee = malloc(sizeof(struct Pile));
Init_Pile(E->Donnee); Init_Pile(E->Donnee);
@ -35,5 +36,5 @@ int main(int argc, char * argv[])
E->Prog = lexer(argv[1]); E->Prog = lexer(argv[1]);
Executer(E); Executer(E);*/
} }

32
pile.c
Näytä tiedosto

@ -12,7 +12,7 @@ void Init_Pile(struct Pile *new)
//return new; //return new;
} }
struct Nombre Typenum(string C) struct Nombre Typenum(char * C)
{ {
struct Nombre k; struct Nombre k;
//enum Numtype type; //enum Numtype type;
@ -35,14 +35,19 @@ struct Nombre Typenum(string C)
k.nombr.ValReel = atof(C); k.nombr.ValReel = atof(C);
} }
return k;
} }
void Empiler(struct Pile * P, struct Nombre i)
void Empiler(struct Pile * P, char * nb)
{ {
struct Cell * cel= malloc(sizeof(struct Cell)); struct Cell * cel= malloc(sizeof(struct Cell));
struct Nombre i = Typenum(nb);
if (i.typ == Entier) if (i.typ == Entier)
cel->Ent.ValEntier = i; cel->Ent.nombr.ValEntier = i.nombr.ValEntier;
else if (i.typ == Reel) else if (i.typ == Reel)
cel->Ent.ValReel = i; cel->Ent.nombr.ValReel = i.nombr.ValReel;
cel->Suiv = P->Pil; cel->Suiv = P->Pil;
P->Pil = cel; P->Pil = cel;
P->nbElements +=1; P->nbElements +=1;
@ -80,6 +85,19 @@ void Supprimer(struct Pile *P){
} }
} }
void Affiche_Nombre(struct Nombre nb)
{
if(nb.typ == Entier)
{
printf("%d \n", nb.nombr.ValEntier);
}
else if(nb.typ == Reel)
{
printf("%f \n", nb.nombr.ValReel);
}
}
void Affichage(struct Cell * C) void Affichage(struct Cell * C)
{ {
if(C == NULL) if(C == NULL)
@ -88,7 +106,7 @@ void Affichage(struct Cell * C)
} }
else else
{ {
printf("%d \n", C->Ent.ValEntier); Affiche_Nombre(C->Ent);
Affichage(C->Suiv); Affichage(C->Suiv);
} }
} }
@ -120,7 +138,7 @@ Programme* lexer(char* chaine) {
return retour; return retour;
} }
void Executer(Etat * etat){ /*void Executer(Etat * etat){
//struct Pile P = etat->Donnee; //struct Pile P = etat->Donnee;
//Programme Program = etat->Prog; //Programme Program = etat->Prog;
struct Cell *C1, *C2; struct Cell *C1, *C2;
@ -199,4 +217,4 @@ void Executer(Etat * etat){
} }
printf("SORTIE : %d \n", etat->Donnee->Pil->Ent.ValEntier); printf("SORTIE : %d \n", etat->Donnee->Pil->Ent.ValEntier);
} }*/

7
pile.h
Näytä tiedosto

@ -33,14 +33,15 @@ typedef struct Etat{
Programme * Prog; Programme * Prog;
} Etat; } Etat;
struct Nombre Typenum(string C); struct Nombre Typenum(char * C);
void Init_Pile(struct Pile * new); void Init_Pile(struct Pile * new);
void Empiler(struct Pile * P, int i); void Empiler(struct Pile * P, char * nb);
struct Cell * Depiler(struct Pile * P); struct Cell * Depiler(struct Pile * P);
void Affiche_Nombre(struct Nombre nb);
void Affichage(struct Cell * C); void Affichage(struct Cell * C);
int numberOfDelimiters(char* string); int numberOfDelimiters(char* string);
Programme* lexer(char* chaine); Programme* lexer(char * chaine);
void Executer(Etat * etat); void Executer(Etat * etat);