recup fichier bosser chez soi
Šī revīzija ir iekļauta:
vecāks
41b3703245
revīzija
32829d36a3
7 mainīti faili ar 207 papildinājumiem un 10 dzēšanām
Binārs
forth
Izpildāmais fails
Binārs
forth
Izpildāmais fails
Bināro failu nav iespējams attēlot.
Binārs
main
Izpildāmais fails
Binārs
main
Izpildāmais fails
Bināro failu nav iespējams attēlot.
21
main.c
21
main.c
|
@ -10,7 +10,10 @@ int main(int argc, char * argv[])
|
||||||
Init_Pile(&P);
|
Init_Pile(&P);
|
||||||
Empiler(&P, 4);
|
Empiler(&P, 4);
|
||||||
Empiler(&P, 5);
|
Empiler(&P, 5);
|
||||||
Affichage(P.Pil);*/
|
struct Cell * res = Depiler(&P);
|
||||||
|
//Supprimer(&P);
|
||||||
|
Affichage(P.Pil);
|
||||||
|
printf("%d \n", res->Ent);
|
||||||
|
|
||||||
Programme * P;
|
Programme * P;
|
||||||
P = lexer(argv[1]);
|
P = lexer(argv[1]);
|
||||||
|
@ -18,5 +21,19 @@ 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++)
|
||||||
|
{
|
||||||
|
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
139
pile.c
|
@ -12,28 +12,74 @@ void Init_Pile(struct Pile *new)
|
||||||
//return 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));
|
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;
|
cel->Suiv = P->Pil;
|
||||||
P->Pil = cel;
|
P->Pil = cel;
|
||||||
P->nbElements +=1;
|
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 * Depiler(struct Pile * P)
|
||||||
{
|
{
|
||||||
struct Cell * res;
|
struct Cell * res= NULL;
|
||||||
if (P->nbElements != 0)
|
if (P->Pil != NULL)
|
||||||
{
|
{
|
||||||
res = P->Pil;
|
res = P->Pil;
|
||||||
P->Pil= P->Pil->Suiv;
|
P->Pil= P->Pil->Suiv;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
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)
|
void Affichage(struct Cell * C)
|
||||||
{
|
{
|
||||||
if(C == NULL)
|
if(C == NULL)
|
||||||
|
@ -42,7 +88,7 @@ void Affichage(struct Cell * C)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("%d \n", C->Ent);
|
printf("%d \n", C->Ent.ValEntier);
|
||||||
Affichage(C->Suiv);
|
Affichage(C->Suiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,4 +118,85 @@ Programme* lexer(char* chaine) {
|
||||||
retour->tokens = programme;
|
retour->tokens = programme;
|
||||||
retour->taille = i;
|
retour->taille = i;
|
||||||
return retour;
|
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
20
pile.h
|
@ -1,12 +1,20 @@
|
||||||
#ifndef PILE_H
|
#ifndef PILE_H
|
||||||
#define 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{
|
struct Cell{
|
||||||
int Ent;
|
struct Nombre Ent;
|
||||||
struct Cell * Suiv;
|
struct Cell * Suiv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +28,12 @@ typedef struct Programme {
|
||||||
int taille;
|
int taille;
|
||||||
} Programme;
|
} Programme;
|
||||||
|
|
||||||
|
typedef struct Etat{
|
||||||
|
struct Pile * Donnee;
|
||||||
|
Programme * Prog;
|
||||||
|
} Etat;
|
||||||
|
|
||||||
|
struct Nombre Typenum(string 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, int i);
|
||||||
struct Cell * Depiler(struct Pile * P);
|
struct Cell * Depiler(struct Pile * P);
|
||||||
|
@ -28,4 +42,6 @@ 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);
|
||||||
|
|
||||||
#endif
|
#endif
|
24
symbole.c
Parasts fails
24
symbole.c
Parasts fails
|
@ -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
Parasts fails
13
symbole.h
Parasts fails
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef SYMBOLE_H
|
||||||
|
#define SYMBOLE_H
|
||||||
|
|
||||||
|
|
||||||
|
struct List{
|
||||||
|
char token;
|
||||||
|
void ( * Commande)(Etat *);
|
||||||
|
struct List * Lsuiv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Notiek ielāde…
Atsaukties uz šo jaunā problēmā