Préparation pour test intermediaire
- Analyseur lexical OK - Analyseur syntaxyque OK
This commit is contained in:
@@ -210,16 +210,6 @@ void nom_token( int token, char *nom, char *valeur ) {
|
||||
else if(token == FIN) strcpy(valeur, "FIN");
|
||||
else if(token == VIRGULE) strcpy(valeur, "VIRGULE");
|
||||
|
||||
else if(token == SI) strcpy(valeur, "SI");
|
||||
else if(token == ALORS) strcpy(valeur, "ALORS");
|
||||
else if(token == SINON) strcpy(valeur, "SINON");
|
||||
else if(token == TANTQUE) strcpy(valeur, "TANTQUE");
|
||||
else if(token == FAIRE) strcpy(valeur, "FAIRE");
|
||||
else if(token == ENTIER) strcpy(valeur, "ENTIER");
|
||||
else if(token == RETOUR) strcpy(valeur, "RETOUR");
|
||||
else if(token == LIRE) strcpy(valeur, "LIRE");
|
||||
else if(token == ECRIRE) strcpy(valeur, "ECRIRE");
|
||||
|
||||
else if( token == ID_VAR ) {
|
||||
strcpy( nom, "id_variable" );
|
||||
strcpy( valeur, yytext );
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
#include "analyseur_syntaxyque.h"
|
||||
|
||||
int uniteCourante;
|
||||
int afficheSyntaxyque = 1;
|
||||
extern char yytext[100];
|
||||
extern int nb_ligne;
|
||||
|
||||
void openSection( const char * section ) {
|
||||
affiche_balise_ouvrante( section, 1 );
|
||||
affiche_balise_ouvrante( section, afficheSyntaxyque );
|
||||
}
|
||||
|
||||
void closeSection( const char * section ) {
|
||||
affiche_balise_fermante( section, 1 );
|
||||
affiche_balise_fermante( section, afficheSyntaxyque );
|
||||
}
|
||||
|
||||
void elementConsome () {
|
||||
char token[128];
|
||||
char nom[128];
|
||||
nom_token( uniteCourante, nom, token );
|
||||
affiche_element(nom, token, afficheSyntaxyque);
|
||||
}
|
||||
|
||||
void syntaxError()
|
||||
@@ -36,7 +44,7 @@ void syntaxErrorMsg( const char * msg )
|
||||
void programme() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( est_premier( _optDecVariables_, uniteCourante ) ) {
|
||||
if( est_premier( _optDecVariables_, uniteCourante ) || est_premier( _listeDecFonctions_, uniteCourante )) {
|
||||
optDecVariables();
|
||||
listeDecFonctions();
|
||||
} else {
|
||||
@@ -54,6 +62,7 @@ void optDecVariables() {
|
||||
listeDecVariables();
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -82,6 +91,7 @@ void listeDecVariablesBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
declarationVariable();
|
||||
@@ -97,9 +107,11 @@ void declarationVariable() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ENTIER ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == ID_VAR ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
optTailleTableau();
|
||||
@@ -117,12 +129,15 @@ void optTailleTableau() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == CROCHET_OUVRANT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == NOMBRE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == CROCHET_FERMANT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "']' été attendu" );
|
||||
@@ -155,6 +170,7 @@ void declarationFonction() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ID_FCT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
listeParam();
|
||||
@@ -171,11 +187,13 @@ void listeParam() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == PARENTHESE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
optListeDecVariables();
|
||||
|
||||
if( uniteCourante == PARENTHESE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "')' été attendu" );
|
||||
@@ -232,11 +250,13 @@ void instructionAffect() {
|
||||
var();
|
||||
|
||||
if( uniteCourante == EGAL ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -255,11 +275,13 @@ void instructionBloc() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ACCOLADE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
listeInstructions();
|
||||
|
||||
if( uniteCourante == ACCOLADE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "'}' été attendu" );
|
||||
@@ -288,11 +310,13 @@ void instructionSi() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == SI ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == ALORS ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
instructionBloc();
|
||||
@@ -311,6 +335,7 @@ void optSinon() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == SINON ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
instructionBloc();
|
||||
@@ -325,11 +350,13 @@ void instructionTantque() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == TANTQUE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == FAIRE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
instructionBloc();
|
||||
@@ -350,6 +377,7 @@ void instructionAppel() {
|
||||
appelFct();
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -365,11 +393,13 @@ void instructionRetour() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == RETOUR ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -385,17 +415,21 @@ void instructionEcriture() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ECRIRE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == PARENTHESE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == PARENTHESE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -417,6 +451,7 @@ void instructionVide() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == POINT_VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "';' été attendu" );
|
||||
@@ -442,6 +477,7 @@ void expressionBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == OU ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
conjonction();
|
||||
@@ -470,6 +506,7 @@ void conjonctionBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ET ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
negation();
|
||||
@@ -485,6 +522,7 @@ void negation() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == NON ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
comparaison();
|
||||
@@ -513,7 +551,14 @@ void comparaison() {
|
||||
void comparaisonBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == EGAL || uniteCourante == INFERIEUR) {
|
||||
if( uniteCourante == EGAL) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expArith();
|
||||
comparaisonBis();
|
||||
} else if( uniteCourante == INFERIEUR) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expArith();
|
||||
@@ -542,7 +587,14 @@ void expArith()
|
||||
void expArithBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == PLUS || uniteCourante == MOINS) {
|
||||
if( uniteCourante == PLUS ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
terme();
|
||||
expArithBis();
|
||||
} else if( uniteCourante == MOINS) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
terme();
|
||||
@@ -570,7 +622,14 @@ void terme() {
|
||||
void termeBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == FOIS || uniteCourante == DIVISE ) {
|
||||
if( uniteCourante == FOIS ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
facteur();
|
||||
termeBis();
|
||||
} else if( uniteCourante == DIVISE) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
facteur();
|
||||
@@ -586,28 +645,34 @@ void facteur() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == PARENTHESE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == PARENTHESE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "')' été attendu" );
|
||||
}
|
||||
} else if( uniteCourante == NOMBRE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else if( est_premier( _appelFct_, uniteCourante ) ) {
|
||||
appelFct();
|
||||
} else if( est_premier( _var_, uniteCourante ) ) {
|
||||
var();
|
||||
} else if( uniteCourante == LIRE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == PARENTHESE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == PARENTHESE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "')' été attendu" );
|
||||
@@ -626,6 +691,7 @@ void var() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ID_VAR ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
optIndice();
|
||||
@@ -640,11 +706,13 @@ void optIndice() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == CROCHET_OUVRANT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
|
||||
if( uniteCourante == CROCHET_FERMANT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "']' été attendu" );
|
||||
@@ -660,14 +728,17 @@ void appelFct() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == ID_FCT ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
if( uniteCourante == PARENTHESE_OUVRANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
listeExpressions();
|
||||
|
||||
if( uniteCourante == PARENTHESE_FERMANTE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
} else {
|
||||
syntaxErrorMsg( "')' été attendu" );
|
||||
@@ -699,6 +770,7 @@ void listeExpressionsBis() {
|
||||
openSection( __func__ );
|
||||
|
||||
if( uniteCourante == VIRGULE ) {
|
||||
elementConsome();
|
||||
uniteCourante = yylex();
|
||||
|
||||
expression();
|
||||
@@ -708,4 +780,4 @@ void listeExpressionsBis() {
|
||||
}
|
||||
|
||||
closeSection( __func__ );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,23 +11,26 @@ FILE *yyin;
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
yyin = fopen(argv[1], "r");
|
||||
if(argc == 0 && yyin == NULL){
|
||||
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]);
|
||||
yyin = fopen(argv[2], "r");
|
||||
if(argc < 3 && yyin == NULL){
|
||||
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//test_yylex_internal(yyin);
|
||||
if (!strcmp(argv[1], "-l")) {
|
||||
test_yylex_internal(yyin);
|
||||
} else if (!strcmp(argv[1], "-s")) {
|
||||
initialise_premiers();
|
||||
initialise_suivants();
|
||||
|
||||
initialise_premiers();
|
||||
initialise_suivants();
|
||||
uniteCourante = yylex();
|
||||
programme();
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "option Inconue");
|
||||
}
|
||||
|
||||
uniteCourante = yylex();
|
||||
|
||||
programme();
|
||||
|
||||
uniteCourante = yylex();
|
||||
|
||||
if(uniteCourante != FIN) {
|
||||
printf("Erreur EOF");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user