Ajout Lexer

This commit is contained in:
EyeXion 2020-10-01 16:27:02 +02:00
parent 963c513703
commit 2f82b4098a
2 changed files with 45 additions and 0 deletions

View file

@ -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;
}

View file

@ -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;