From 60d19eea05486fcc4b2cef56e46771c34738b199 Mon Sep 17 00:00:00 2001 From: Xawirses Date: Tue, 19 Jan 2016 15:51:24 +0100 Subject: [PATCH] =?UTF-8?q?Add=20Analyse=20lexycale=20pour=20:=20=20=20=20?= =?UTF-8?q?=20-=20OP=20&=20Symbole=20simple=20=20=20=20=20-=20Constante=20?= =?UTF-8?q?num=C3=A9rique=20=20=20=20=20-=20Blanc=20retour=20=C3=A0=20la?= =?UTF-8?q?=20ligne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/analyseur_lexical.c | 70 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/src/analyseur_lexical.c b/src/analyseur_lexical.c index 1914256..7e34cae 100644 --- a/src/analyseur_lexical.c +++ b/src/analyseur_lexical.c @@ -11,15 +11,30 @@ #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))) - + extern FILE *yyin; +char tableSymbole[] = { + ';', ',', '(', ')', '[', ']', '{', '}', // Code + '+', '-', '*', '/', // Arithmetique + '<', '=', // Comparaison + '&','|', '!' , // Logique + '\0' +}; + +int codeSymbole[] = { + POINT_VIRGULE, VIRGULE, PARENTHESE_OUVRANTE, PARENTHESE_FERMANTE, CROCHET_OUVRANT, CROCHET_FERMANT, ACCOLADE_OUVRANTE, ACCOLADE_FERMANTE, + PLUS, MOINS, FOIS, DIVISE, + INFERIEUR, EGAL, + ET, OU, NON +}; + char *tableMotsClefs[] = { - "si", + "si", "alors", "sinon", "tantque", "faire", "entier", "retour", "lire", "ecrire", '\0' }; int codeMotClefs[] = { - SI, + SI, ALORS, SINON, TANTQUE, FAIRE, ENTIER, RETOUR, LIRE, ECRIRE }; char yytext[YYTEXT_MAX]; @@ -85,7 +100,54 @@ int yylex(void) char c; int i; yytext[yyleng = 0] = '\0'; - // COMPLÉTER + + if (mangeEspaces() == -1) + return FIN; + + c = lireCar(); + + // Nombre + if( isdigit( c ) ) + { + while( isdigit( lireCar() ) ); + delireCar(); + + affiche_element( "nombre", yytext, 1 ); + return NOMBRE; + } + + //id_var + if( c == '$' ) { + int compteur = 1; // 1 pour $ + + while( is_alphanum( lireCar() )){ + compteur++; + } + delireCar(); + + if(compteur > 99) { + erreur("Nom variable > 99 character"); + return -1; + } + + affiche_element( "id_variable", yytext, 1 ); + return ID_VAR; + } + + // Symbole simple + for( int i = 0; tableSymbole[i] != '\0'; ++i ) { + if( c == tableSymbole[i] ) { + char tmp[1]; + tmp[0] = c; + affiche_element( "symbole", tmp, 1 ); + return codeSymbole[i]; + } + } + + + + + return -1; } /*******************************************************************************