recup fichier bosser chez soi

This commit is contained in:
Olougouna Axel 2022-12-06 20:07:39 +01:00
parent 41b3703245
commit 32829d36a3
7 changed files with 207 additions and 10 deletions

BIN
forth Executable file

Binary file not shown.

BIN
main Executable file

Binary file not shown.

21
main.c
View file

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

139
pile.c
View file

@ -12,28 +12,74 @@ void Init_Pile(struct Pile *new)
//return new;
}
void Empiler(struct Pile * P, int i)
struct Nombre Typenum(string C)
{
struct Nombre k;
//enum Numtype type;
//union Test i;
k.typ = Entier;
for(int i=0; i<strlen(C); i++)
{
if( C[i] == '.')
{
k.typ=Reel;
}
}
if(k.typ == Entier)
{
k.nombr.ValEntier = atoi(C);
}
else if(k.typ == Reel)
{
k.nombr.ValReel = atof(C);
}
}
void Empiler(struct Pile * P, struct Nombre i)
{
struct Cell * cel= malloc(sizeof(struct Cell));
cel->Ent = i;
if (i.typ == Entier)
cel->Ent.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;
if (P->nbElements != 0)
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)
@ -42,7 +88,7 @@ void Affichage(struct Cell * C)
}
else
{
printf("%d \n", C->Ent);
printf("%d \n", C->Ent.ValEntier);
Affichage(C->Suiv);
}
}
@ -72,4 +118,85 @@ Programme* lexer(char* chaine) {
retour->tokens = 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 <tail; i++)
{
element = (etat->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);
}

20
pile.h
View file

@ -1,12 +1,20 @@
#ifndef PILE_H
#define PILE_H
union Test {
int ValEntier;
float ValReel;
};
enum NumType {Entier, Reel};
struct Cell;
struct Nombre{
union Test nombr;
enum NumType typ;
};
struct Cell{
int Ent;
struct Nombre Ent;
struct Cell * Suiv;
};
@ -20,6 +28,12 @@ typedef struct Programme {
int taille;
} Programme;
typedef struct Etat{
struct Pile * Donnee;
Programme * Prog;
} Etat;
struct Nombre Typenum(string C);
void Init_Pile(struct Pile * new);
void Empiler(struct Pile * P, int i);
struct Cell * Depiler(struct Pile * P);
@ -28,4 +42,6 @@ void Affichage(struct Cell * C);
int numberOfDelimiters(char* string);
Programme* lexer(char* chaine);
void Executer(Etat * etat);
#endif

24
symbole.c Normal file
View file

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include "pile.h"
#include "symbole.h"
void DROP(struct Pile *P)
{
struct Cell * tmp;
if(P->nbElements != 0)
{
tmp = P->Pil;
P->Pil = P->Pil->Suiv;
free(tmp);
}
}
void DUP(struct Pile * P)
{
struct Cell * double;
double = malloc(sizeof(struct))
}

13
symbole.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef SYMBOLE_H
#define SYMBOLE_H
struct List{
char token;
void ( * Commande)(Etat *);
struct List * Lsuiv;
}
#endif