X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lexer%2Fmain.c;h=26ba1d5594ada06869ac350d6235bce78b048812;hb=91e467775142590b4ffd1063e61a1edf33679323;hp=3247e34c93d17bf8f2879b120b62a94941b7501e;hpb=d3eb30efdbdd46508f1034c1c1aed4bd5e23bbc5;p=TP_AL_C.git diff --git a/lexer/main.c b/lexer/main.c index 3247e34..26ba1d5 100644 --- a/lexer/main.c +++ b/lexer/main.c @@ -17,7 +17,7 @@ enum TokenType { } tokenType; const char* tokenTypestr[] = { "MOTCLE", "SECTION", "SSECTION", "NPARA", "MOT", "FIN" }; -/* This looks silly to check for each characters but for debugging, it's just the way to go */ +/* It looks silly to check for each characters but for debugging, it's just the way to go */ bool istAlpha() { if (c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' || c == 'g' || \ c == 'h' || c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || \ @@ -44,9 +44,9 @@ bool isSeparator() { } int scanner() { -const char* Titre = "Titre"; -const char* Auteur = "Auteur"; -unsigned int j = 0; + const char* Titre = "Titre"; + const char* Auteur = "Auteur"; + unsigned int j = 0; // The main loop get the next character init: @@ -56,6 +56,12 @@ init: i++; goto init; } + if (c == '\n') { + c = fgetc(source); + tokenValue[i] = c; + i++; + goto initLV1; + } if (c == '>') { c = fgetc(source); tokenValue[i] = c; @@ -74,12 +80,6 @@ init: i++; goto M1; } - if (c == '\n') { - c = fgetc(source); - tokenValue[i] = c; - i++; - goto initLV1; - } if (c == EOF) { goto FIN; } else { @@ -118,7 +118,6 @@ S1SS1: goto SECTION; } - SS2: if (isSeparator() || c == EOF) { goto SSECTION; @@ -144,12 +143,18 @@ M1: } initLV1: - if (c == '\n' || c == '\t') { + if (c == ' ' || c == '\t') { c = fgetc(source); tokenValue[i] = c; i++; goto initLV1; } + if (c == '\n') { + c = fgetc(source); + tokenValue[i] = c; + i++; + goto initLV1LV2; + } if (istAlpha()) { c = fgetc(source); tokenValue[i] = c; @@ -168,12 +173,6 @@ initLV1: i++; goto MC1; } - if (c == '\n') { - c = fgetc(source); - tokenValue[i] = c; - i++; - goto initLV1LV2; - } if (c == EOF) { goto FIN; } @@ -185,6 +184,9 @@ initLV1LV2: i++; goto initLV1LV2; } + if (istAlpha()) { + goto NPARA; + } if (c == '>') { c = fgetc(source); tokenValue[i] = c; @@ -197,9 +199,6 @@ initLV1LV2: i++; goto S1SS1; } - if (istAlpha()) { - goto NPARA; - } if (c == EOF) { goto FIN; } @@ -250,7 +249,6 @@ int main (int argc, char const *argv[]) { do { c = fgetc(source); // lecture du caractere suivant du fichier source - //fputc(c, target); // ecrire c dans le fichier target tokenValue[i] = c; i++; int scanrt = scanner(); @@ -263,10 +261,10 @@ int main (int argc, char const *argv[]) { } else { printf ("Token type found: %s\n", tokenTypestr[tokenType]); } - // reinit + // reinit tokenValue i = 0; memset(tokenValue, 0, sizeof(tokenValue)); - } while (c != EOF); // tant que la fin du fichier n'est pas atteinte + } while (c != EOF); // tant que la fin du fichier n'est pas atteinte if (source != NULL) fclose(source); // fermeture du fichier source if (target != NULL) fclose(target); // fermeture du fichier target