Ajout test mot_clef, reparation des fonction de test

This commit is contained in:
2016-01-22 10:20:48 +01:00
parent 60d19eea05
commit e288ca49b4
3 changed files with 44 additions and 18 deletions

3
.gitignore vendored
View File

@@ -30,3 +30,6 @@
# Debug files
*.dSYM/
test_yylex
compilateur-l

View File

@@ -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

View File

@@ -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;
}