From e288ca49b46ec0b349ac950e2fea3c271946db67 Mon Sep 17 00:00:00 2001 From: Xawirses Date: Fri, 22 Jan 2016 10:20:48 +0100 Subject: [PATCH] Ajout test mot_clef, reparation des fonction de test --- .gitignore | 3 +++ Makefile | 16 +++++---------- src/analyseur_lexical.c | 43 ++++++++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index bbf313b..3cc293c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ # Debug files *.dSYM/ + +test_yylex +compilateur-l \ No newline at end of file diff --git a/Makefile b/Makefile index 1ff004f..8cec32a 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LDFLAGS= SRC=$(wildcard src/*.c) OBJ=$(SRC:.c=.o) -EXEC=compilateur-l +EXEC=test_yylex all: $(EXEC) @@ -17,9 +17,6 @@ $(EXEC): $(OBJ) %.o: %.c $(CC) -o $@ -c $< $(CCFLAGS) -test_yylex: test_yylex.c $(OBJ) - $(CC) $(CCFLAGS) -o test_yylex test_yylex.c $(OBJ) - analyseur_lexical.o: analyseur_lexical.c $(CC) $(CCFLAGS) -c $^ @@ -33,13 +30,10 @@ mrproper: clean @echo "Remove $(EXEC) file" rm -rf $(EXEC) -doxygen: - @echo "Generate Doxygen documentation" - rm -rf documentation/* - doxygen config_doxygen.conf - rebuild: @echo " --- Cleaning --- " make mrproper - @echo " \n\n--- Building --- " - make all + @echo + @echo + @echo " --- Building --- " + make all \ No newline at end of file diff --git a/src/analyseur_lexical.c b/src/analyseur_lexical.c index 7e34cae..f83cc61 100644 --- a/src/analyseur_lexical.c +++ b/src/analyseur_lexical.c @@ -11,6 +11,7 @@ #define is_min(c)(('a' <= (c)) && ((c) <= 'z')) #define is_alpha(c)(is_maj(c) || is_min(c) || (c) == '_' || (c) == '$') #define is_alphanum(c)(is_num((c)) || is_alpha((c))) +#define is_space(c)((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '#' ) extern FILE *yyin; @@ -107,9 +108,9 @@ int yylex(void) c = lireCar(); // Nombre - if( isdigit( c ) ) + if( is_num( c ) ) { - while( isdigit( lireCar() ) ); + while( is_num( lireCar() ) ); delireCar(); affiche_element( "nombre", yytext, 1 ); @@ -118,15 +119,15 @@ int yylex(void) //id_var if( c == '$' ) { - int compteur = 1; // 1 pour $ + i = 1; // 1 pour $ while( is_alphanum( lireCar() )){ - compteur++; + i++; } delireCar(); - if(compteur > 99) { - erreur("Nom variable > 99 character"); + if(i > 99) { + erreur("Nom variable > 99 characters"); return -1; } @@ -134,6 +135,25 @@ int yylex(void) return ID_VAR; } + //id_fct + if( is_alpha( c ) ) { + int i = 1; // 1 pour $ + + while( is_alphanum(lireCar())) { + i++; + } + + delireCar(); + + if(i > 99) { + erreur("Nom fonction > 99 characters"); + return -1; + } + + affiche_element( "id_fonction", yytext, 1 ); + return ID_FCT; + } + // Symbole simple for( int i = 0; tableSymbole[i] != '\0'; ++i ) { if( c == tableSymbole[i] ) { @@ -144,8 +164,17 @@ int yylex(void) } } - + // Mot clefs + while( !is_space( lireCar() ) ); + delireCar(); + for( int i = 0; tableMotsClefs[i] != '\0'; ++i ) + { + if( strcmp( tableMotsClefs[i], yytext ) == 0 ) { + affiche_element( "mot-clef", yytext, 1 ); + return codeMotClefs[i]; + } + } return -1; }