Ajout Lexer
This commit is contained in:
parent
963c513703
commit
2f82b4098a
2 changed files with 45 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
||||||
|
#include "lexer.h"
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdio_ext.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Programme {
|
||||||
|
char **tokens;
|
||||||
|
int taille;
|
||||||
|
}Programme;
|
Loading…
Reference in a new issue