123456789101112131415161718192021222324252627282930313233 |
- #include "lexer.h"
-
- #include <stdlib.h>
- #include <string.h>
-
-
- int numberOfDelimiters(char* string) {
- int count = 0;
- for (int i = 0; i < (int)strlen(string); ++i) {
- if (string[i] == ' ') {
- ++count;
- }
- }
- return count;
- }
-
- struct Programm* 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;
- }
-
- struct Programm* res = (struct Programm*) malloc(sizeof(struct Programm));
- res->tokens = programme;
- res->taille = i;
- return res;
- }
|