From: Jérôme Benoit Date: Thu, 9 Nov 2017 13:41:58 +0000 (+0100) Subject: Store all tokens found during the lexical analysis in an array. X-Git-Url: https://git.piment-noir.org/?p=TP_AL_C.git;a=commitdiff_plain;h=dcfcd9abe60fea374dde83d5488481e01ba9c3aa Store all tokens found during the lexical analysis in an array. Signed-off-by: Jérôme Benoit --- diff --git a/lexer/main.c b/lexer/main.c index 8122023..db41495 100644 --- a/lexer/main.c +++ b/lexer/main.c @@ -3,10 +3,13 @@ #include #include -FILE *source, *target = NULL; +#define TOKEN_MAX_LENGTH 50 +#define TOKEN_LIST_MAX 500 + +FILE *source = NULL, *target = NULL; char c; unsigned int i = 0; -char tokenValue[50]; +char tokenValue[TOKEN_MAX_LENGTH]; enum TokenType { MOTCLE, SECTION, @@ -16,6 +19,7 @@ enum TokenType { FIN } tokenType; const char* tokenTypestr[] = { "MOTCLE", "SECTION", "SSECTION", "NPARA", "MOT", "FIN" }; +const char* tokenList[TOKEN_LIST_MAX]; /* It looks silly to check for each characters but for debugging, it's just the way to go */ bool istAlpha() { @@ -87,7 +91,7 @@ init: } MC1: - // FIXME: Partial match need a rewind in the characters extraction from the file + // FIXME: Partial match need a rewind in the characters extraction from the file if (c == Titre[j] && j < strlen(Titre) - 1) { c = fgetc(source); tokenValue[i] = c; @@ -248,6 +252,8 @@ int main (int argc, char const *argv[]) { return -1; } + int tokenFound = 0; + do { c = fgetc(source); // lecture du caractere suivant du fichier source tokenValue[i] = c; @@ -262,6 +268,8 @@ int main (int argc, char const *argv[]) { } else { printf ("Token type found: %s\n", tokenTypestr[tokenType]); } + tokenFound++; + tokenList[tokenFound] = tokenTypestr[tokenType]; // reinit tokenValue i = 0; memset(tokenValue, 0, sizeof(tokenValue));