recup fichier bosser chez soi
這個提交存在於:
父節點
41b3703245
當前提交
32829d36a3
共有 7 個檔案被更改,包括 207 行新增 和 10 行删除
二進制
forth
可執行檔
二進制
forth
可執行檔
未顯示二進位檔案。
二進制
main
可執行檔
二進制
main
可執行檔
未顯示二進位檔案。
21
main.c
21
main.c
|
@ -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);
|
||||
}
|
137
pile.c
137
pile.c
|
@ -12,19 +12,55 @@ 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;
|
||||
|
@ -34,6 +70,16 @@ struct Cell * Depiler(struct Pile * P)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -73,3 +119,84 @@ Programme* lexer(char* chaine) {
|
|||
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
20
pile.h
|
@ -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
一般檔案
24
symbole.c
一般檔案
|
@ -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
一般檔案
13
symbole.h
一般檔案
|
@ -0,0 +1,13 @@
|
|||
#ifndef SYMBOLE_H
|
||||
#define SYMBOLE_H
|
||||
|
||||
|
||||
struct List{
|
||||
char token;
|
||||
void ( * Commande)(Etat *);
|
||||
struct List * Lsuiv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
載入中…
新增問題並參考