Ajout test mot_clef, reparation des fonction de test
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -30,3 +30,6 @@
|
|||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
|
|
||||||
|
test_yylex
|
||||||
|
compilateur-l
|
||||||
16
Makefile
16
Makefile
@@ -7,7 +7,7 @@ LDFLAGS=
|
|||||||
SRC=$(wildcard src/*.c)
|
SRC=$(wildcard src/*.c)
|
||||||
OBJ=$(SRC:.c=.o)
|
OBJ=$(SRC:.c=.o)
|
||||||
|
|
||||||
EXEC=compilateur-l
|
EXEC=test_yylex
|
||||||
|
|
||||||
all: $(EXEC)
|
all: $(EXEC)
|
||||||
|
|
||||||
@@ -17,9 +17,6 @@ $(EXEC): $(OBJ)
|
|||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) -o $@ -c $< $(CCFLAGS)
|
$(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
|
analyseur_lexical.o: analyseur_lexical.c
|
||||||
$(CC) $(CCFLAGS) -c $^
|
$(CC) $(CCFLAGS) -c $^
|
||||||
|
|
||||||
@@ -33,13 +30,10 @@ mrproper: clean
|
|||||||
@echo "Remove $(EXEC) file"
|
@echo "Remove $(EXEC) file"
|
||||||
rm -rf $(EXEC)
|
rm -rf $(EXEC)
|
||||||
|
|
||||||
doxygen:
|
|
||||||
@echo "Generate Doxygen documentation"
|
|
||||||
rm -rf documentation/*
|
|
||||||
doxygen config_doxygen.conf
|
|
||||||
|
|
||||||
rebuild:
|
rebuild:
|
||||||
@echo " --- Cleaning --- "
|
@echo " --- Cleaning --- "
|
||||||
make mrproper
|
make mrproper
|
||||||
@echo " \n\n--- Building --- "
|
@echo
|
||||||
make all
|
@echo
|
||||||
|
@echo " --- Building --- "
|
||||||
|
make all
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#define is_min(c)(('a' <= (c)) && ((c) <= 'z'))
|
#define is_min(c)(('a' <= (c)) && ((c) <= 'z'))
|
||||||
#define is_alpha(c)(is_maj(c) || is_min(c) || (c) == '_' || (c) == '$')
|
#define is_alpha(c)(is_maj(c) || is_min(c) || (c) == '_' || (c) == '$')
|
||||||
#define is_alphanum(c)(is_num((c)) || is_alpha((c)))
|
#define is_alphanum(c)(is_num((c)) || is_alpha((c)))
|
||||||
|
#define is_space(c)((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '#' )
|
||||||
|
|
||||||
extern FILE *yyin;
|
extern FILE *yyin;
|
||||||
|
|
||||||
@@ -107,9 +108,9 @@ int yylex(void)
|
|||||||
c = lireCar();
|
c = lireCar();
|
||||||
|
|
||||||
// Nombre
|
// Nombre
|
||||||
if( isdigit( c ) )
|
if( is_num( c ) )
|
||||||
{
|
{
|
||||||
while( isdigit( lireCar() ) );
|
while( is_num( lireCar() ) );
|
||||||
delireCar();
|
delireCar();
|
||||||
|
|
||||||
affiche_element( "nombre", yytext, 1 );
|
affiche_element( "nombre", yytext, 1 );
|
||||||
@@ -118,15 +119,15 @@ int yylex(void)
|
|||||||
|
|
||||||
//id_var
|
//id_var
|
||||||
if( c == '$' ) {
|
if( c == '$' ) {
|
||||||
int compteur = 1; // 1 pour $
|
i = 1; // 1 pour $
|
||||||
|
|
||||||
while( is_alphanum( lireCar() )){
|
while( is_alphanum( lireCar() )){
|
||||||
compteur++;
|
i++;
|
||||||
}
|
}
|
||||||
delireCar();
|
delireCar();
|
||||||
|
|
||||||
if(compteur > 99) {
|
if(i > 99) {
|
||||||
erreur("Nom variable > 99 character");
|
erreur("Nom variable > 99 characters");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +135,25 @@ int yylex(void)
|
|||||||
return ID_VAR;
|
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
|
// Symbole simple
|
||||||
for( int i = 0; tableSymbole[i] != '\0'; ++i ) {
|
for( int i = 0; tableSymbole[i] != '\0'; ++i ) {
|
||||||
if( c == tableSymbole[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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user