tp3_C/pile.c
2022-12-01 23:42:05 +01:00

75 rindas
No EOL
1,4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "pile.h"
void Init_Pile(struct Pile *new)
{
//struct Pile new;
new->Pil=NULL;
new->nbElements=0;
//return new;
}
void Empiler(struct Pile * P, int i)
{
struct Cell * cel= malloc(sizeof(struct Cell));
cel->Ent = i;
cel->Suiv = P->Pil;
P->Pil = cel;
P->nbElements +=1;
}
struct Cell * Depiler(struct Pile * P)
{
struct Cell * res;
if (P->nbElements != 0)
{
res = P->Pil;
P->Pil= P->Pil->Suiv;
}
return res;
}
void Affichage(struct Cell * C)
{
if(C == NULL)
{
//printf("Rien a afficher");
}
else
{
printf("%d \n", C->Ent);
Affichage(C->Suiv);
}
}
int numberOfDelimiters(char* string) {
int count = 0;
for (int i=0;i<strlen(string);i++) {
if (string[i] == ' ')
{count++;}
}
return count;
}
Programme* lexer(char* chaine) {
char *token,*str;
str = strdup(chaine);
int i=0;
int arraysize = (numberOfDelimiters(str)+1);
char** programme = (char**)malloc(sizeof(char*)*arraysize);
while ( (token = strsep(&str, " ")) ) {
programme[i] = token;
i++;
}
Programme *retour = (Programme*)malloc(sizeof(Programme));
retour->tokens = programme;
retour->taille = i;
return retour;
}