Résultat du TP en C sur Forth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lexer.c 718B

123456789101112131415161718192021222324252627282930313233
  1. #include "lexer.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int numberOfDelimiters(char* string) {
  5. int count = 0;
  6. for (int i = 0; i < (int)strlen(string); ++i) {
  7. if (string[i] == ' ') {
  8. ++count;
  9. }
  10. }
  11. return count;
  12. }
  13. struct Programm* lexer(char* chaine) {
  14. char *token, *str;
  15. str = strdup(chaine);
  16. int i = 0;
  17. int arraysize = numberOfDelimiters(str) + 1;
  18. char** programme = (char**)malloc(sizeof(char*)*arraysize);
  19. while ((token = strsep(&str, " "))) {
  20. programme[i] = token;
  21. ++i;
  22. }
  23. struct Programm* res = (struct Programm*) malloc(sizeof(struct Programm));
  24. res->tokens = programme;
  25. res->taille = i;
  26. return res;
  27. }