Remove All errors

This commit is contained in:
2016-02-02 18:15:32 +01:00
parent 707aa5b2ad
commit a9ec673316
2 changed files with 124 additions and 98 deletions

View File

@@ -9,9 +9,13 @@
#include "util.h" #include "util.h"
#include "stdio.h" #include "stdio.h"
#include "analyseur_lexical.h" #include "analyseur_lexical.h"
#include "premiers.h"
#include "suivants.h"
void openSection ( const char * section ); void openSection ( const char * section );
void closeSection ( const char * section ); void closeSection ( const char * section );
void syntaxError (void);
void syntaxErrorMsg( const char * msg );
void programme (void); void programme (void);
void optDecVariables (void); void optDecVariables (void);
void listeDecVariables (void); void listeDecVariables (void);

View File

@@ -2,17 +2,39 @@
int uniteCourante; int uniteCourante;
extern char yytext[100]; extern char yytext[100];
extern int nb_ligne;
void openSection( const char * section ) { void openSection( const char * section ) {
affiche_balise_ouvrantexpression( section, 1 ); affiche_balise_ouvrante( section, 1 );
} }
void closeSection( const char * section ) { void closeSection( const char * section ) {
affiche_balise_fermantexpression( section, 1 ); affiche_balise_fermante( section, 1 );
}
void syntaxError()
{
char token[128];
char nom[128];
nom_token( uniteCourante, nom, token );
fprintf( stderr, "Erreur de syntax, proche de la ligne %d, et de l'unite courante '%s' (%d - %s)\n", nb_ligne, token, uniteCourante, nom );
exit( 1 );
}
void syntaxErrorMsg( const char * msg )
{
char token[128];
char nom[128];
nom_token( uniteCourante, nom, token );
fprintf( stderr, "Erreur de syntax, proche de la ligne %d, et de l'unite courante '%s' (%d - %s)\n", nb_ligne, token, uniteCourante, nom );
fprintf( stderr, "%s\n", msg );
exit( 1 );
} }
void programme() { void programme() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _optDecVariables_, uniteCourante ) ) { if( est_premier( _optDecVariables_, uniteCourante ) ) {
optDecVariables(); optDecVariables();
@@ -21,11 +43,11 @@ void programme() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void optDecVariables() { void optDecVariables() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _listeDecVariables_, uniteCourante ) ) if( est_premier( _listeDecVariables_, uniteCourante ) )
{ {
@@ -36,15 +58,15 @@ void optDecVariables() {
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
} }
} else if ( !est_suivanterme( _optDecVariables_, uniteCourante ) ) { } else if ( !est_suivant( _optDecVariables_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeDecVariables() { void listeDecVariables() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _declarationVariable_, uniteCourante ) ) { if( est_premier( _declarationVariable_, uniteCourante ) ) {
declarationVariable(); declarationVariable();
@@ -53,26 +75,26 @@ void listeDecVariables() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeDecVariablesBis() { void listeDecVariablesBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {
uniteCourante = yylex(); uniteCourante = yylex();
declarationVariable(); declarationVariable();
listeDecVariablesBis(); listeDecVariablesBis();
} else if( !est_suivanterme( _listeDecVariablesBis_, uniteCourante ) ) { } else if( !est_suivant( _listeDecVariablesBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void declarationVariable() { void declarationVariable() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ENTIER ) { if( uniteCourante == ENTIER ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -88,11 +110,11 @@ void declarationVariable() {
syntaxErrorMsg( "'ENTIER' été attendu" ); syntaxErrorMsg( "'ENTIER' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void optTailleTableau() { void optTailleTableau() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -108,29 +130,29 @@ void optTailleTableau() {
} else { } else {
syntaxErrorMsg( "Un nombre été attendu" ); syntaxErrorMsg( "Un nombre été attendu" );
} }
} else if( !est_suivanterme( _optTailleTableau_, uniteCourante ) ) } else if( !est_suivant( _optTailleTableau_, uniteCourante ) )
{ {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeDecFonctions() { void listeDecFonctions() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _declarationFonction_, uniteCourante ) ) { if( est_premier( _declarationFonction_, uniteCourante ) ) {
declarationFonction(); declarationFonction();
listeDecFonctions(); listeDecFonctions();
} else if( !est_suivanterme( _listeDecFonctionss_, uniteCourante ) ) { } else if( !est_suivant( _listeDecFonctions_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void declarationFonction() { void declarationFonction() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -142,11 +164,11 @@ void declarationFonction() {
syntaxErrorMsg( "Un identificateur de fonction été attendu" ); syntaxErrorMsg( "Un identificateur de fonction été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeParam() { void listeParam() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -162,23 +184,23 @@ void listeParam() {
syntaxErrorMsg( "'(' été attendu" ); syntaxErrorMsg( "'(' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void optListeDecVariables() { void optListeDecVariables() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _listeDecVariables_, uniteCourante ) ) { if( est_premier( _listeDecVariables_, uniteCourante ) ) {
listeDecVariables(); listeDecVariables();
} else if( !est_suivanterme( _optListeDecVariables_, uniteCourante ) ) { } else if( !est_suivant( _optListeDecVariables_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instruction() { void instruction() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _instructionAffect_, uniteCourante ) ) { if( est_premier( _instructionAffect_, uniteCourante ) ) {
instructionAffect(); instructionAffect();
@@ -200,11 +222,11 @@ void instruction() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionAffect() { void instructionAffect() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _var_, uniteCourante ) ) { if( est_premier( _var_, uniteCourante ) ) {
var(); var();
@@ -226,11 +248,11 @@ void instructionAffect() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionBloc() { void instructionBloc() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ACCOLADE_OUVRANTE ) { if( uniteCourante == ACCOLADE_OUVRANTE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -246,24 +268,24 @@ void instructionBloc() {
syntaxErrorMsg( "'{' été attendu" ); syntaxErrorMsg( "'{' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeInstructions() { void listeInstructions() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _instruction_, uniteCourante ) ) { if( est_premier( _instruction_, uniteCourante ) ) {
instruction(); instruction();
listeInstructions(); listeInstructions();
} else if( !est_suivanterme( _listeInstructions_, uniteCourante ) ) { } else if( !est_suivant( _listeInstructions_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionSi() { void instructionSi() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == SI ) { if( uniteCourante == SI ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -282,25 +304,25 @@ void instructionSi() {
syntaxErrorMsg( "'si' été attendu" ); syntaxErrorMsg( "'si' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void optSinon() { void optSinon() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == SINON ) { if( uniteCourante == SINON ) {
uniteCourante = yylex(); uniteCourante = yylex();
instructionBloc(); instructionBloc();
} else if( !est_suivanterme( _optSinon_, uniteCourante ) ) { } else if( !est_suivant( _optSinon_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionTantque() { void instructionTantque() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == TANTQUE ) { if( uniteCourante == TANTQUE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -318,11 +340,11 @@ void instructionTantque() {
syntaxErrorMsg( "'tantque' été attendu" ); syntaxErrorMsg( "'tantque' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionAppel() { void instructionAppel() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _instructionAppel_, uniteCourante ) ) { if( est_premier( _instructionAppel_, uniteCourante ) ) {
appelFct(); appelFct();
@@ -336,11 +358,11 @@ void instructionAppel() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionRetour() { void instructionRetour() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == RETOUR ) { if( uniteCourante == RETOUR ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -356,11 +378,11 @@ void instructionRetour() {
syntaxErrorMsg( "'retour' été attendu" ); syntaxErrorMsg( "'retour' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionEcriture() { void instructionEcriture() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ECRIRE ) { if( uniteCourante == ECRIRE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -388,11 +410,11 @@ void instructionEcriture() {
syntaxErrorMsg( "'ecrire' été attendu" ); syntaxErrorMsg( "'ecrire' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void instructionVide() { void instructionVide() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -400,11 +422,11 @@ void instructionVide() {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void expression() { void expression() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _conjonction_, uniteCourante ) ) { if( est_premier( _conjonction_, uniteCourante ) ) {
conjonction(); conjonction();
@@ -413,26 +435,26 @@ void expression() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void expressionBis() { void expressionBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == OU ) { if( uniteCourante == OU ) {
uniteCourante = yylex(); uniteCourante = yylex();
conjonction(); conjonction();
expressionBis(); expressionBis();
} else if( !est_suivanterme( _expressionBis_, uniteCourante ) ) { } else if( !est_suivant( _expressionBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void conjonction() { void conjonction() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _negation_, uniteCourante ) ) { if( est_premier( _negation_, uniteCourante ) ) {
negation(); negation();
@@ -441,26 +463,26 @@ void conjonction() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void conjonctionBis() { void conjonctionBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ET ) { if( uniteCourante == ET ) {
uniteCourante = yylex(); uniteCourante = yylex();
negation(); negation();
conjonctionBis(); conjonctionBis();
} else if( !est_suivanterme( _conjonctionBis_, uniteCourante ) ) { } else if( !est_suivant( _conjonctionBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void negation() { void negation() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == NON ) { if( uniteCourante == NON ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -472,11 +494,11 @@ void negation() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void comparaison() { void comparaison() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _expression_, uniteCourante ) ) { if( est_premier( _expression_, uniteCourante ) ) {
expArith(); expArith();
@@ -485,55 +507,55 @@ void comparaison() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void comparaisonBis() { void comparaisonBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == EGAL || uniteCourante == INFERIEUR) { if( uniteCourante == EGAL || uniteCourante == INFERIEUR) {
uniteCourante = yylex(); uniteCourante = yylex();
expArith(); expArith();
comparaisonBis(); comparaisonBis();
} else if( !est_suivanterme( _comparaisonBis_, uniteCourante ) ) { } else if( !est_suivant( _comparaisonBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void expArith() void expArith()
{ {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _terme_, yylval ) ) { if( est_premier( _terme_, uniteCourante ) ) {
terme(); terme();
expArithBis(); expArithBis();
} else { } else {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void expArithBis() { void expArithBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == PLUS || uniteCourante == MOINS) { if( uniteCourante == PLUS || uniteCourante == MOINS) {
uniteCourante = yylex(); uniteCourante = yylex();
terme(); terme();
expArithBis(); expArithBis();
} else if( !est_suivanterme( _expArithBis_, uniteCourante ) ) { } else if( !est_suivant( _expArithBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void terme() { void terme() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _facteur_, uniteCourante ) ) { if( est_premier( _facteur_, uniteCourante ) ) {
facteur(); facteur();
@@ -542,26 +564,26 @@ void terme() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void termeBis() { void termeBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == FOIS || ylval == DIVISE ) { if( uniteCourante == FOIS || uniteCourante == DIVISE ) {
uniteCourante = yylex(); uniteCourante = yylex();
facteur(); facteur();
termeBis(); termeBis();
} else if( !est_suivanterme( _termeBis_, uniteCourante ) ) { } else if( !est_suivant( _termeBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void facteur() { void facteur() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -597,11 +619,11 @@ void facteur() {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void var() { void var() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ID_VAR ) { if( uniteCourante == ID_VAR ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -611,11 +633,11 @@ void var() {
syntaxErrorMsg( "Indice de variable été attendu" ); syntaxErrorMsg( "Indice de variable été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void optIndice() { void optIndice() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -627,15 +649,15 @@ void optIndice() {
} else { } else {
syntaxErrorMsg( "']' été attendu" ); syntaxErrorMsg( "']' été attendu" );
} }
} else if( !est_suivanterme( _optIndice_, uniteCourante ) ) { } else if( !est_suivant( _optIndice_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void appelFct() { void appelFct() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
uniteCourante = yylex(); uniteCourante = yylex();
@@ -657,33 +679,33 @@ void appelFct() {
syntaxErrorMsg( "Identificateur de fonction été attendu" ); syntaxErrorMsg( "Identificateur de fonction été attendu" );
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeExpressions() { void listeExpressions() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( est_premier( _expression_, uniteCourante ) ) { if( est_premier( _expression_, uniteCourante ) ) {
expression(); expression();
listeExpressionsBis((); listeExpressionsBis();
} else if( !est_suivanterme( _listeexpressions_, uniteCourante ) ) { } else if( !est_suivant( _listeExpressions_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }
void listeExpressionsBis(() { void listeExpressionsBis() {
openSection( __FUNCTION__ ); openSection( __func__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
listeExpressionsBis((); listeExpressionsBis();
} else if( !est_suivanterme( _listeexpressionsBis_, uniteCourante ) ) { } else if( !est_suivant( _listeExpressionsBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
} }
closeSection( __FUNCTION__ ); closeSection( __func__ );
} }