Resolv bug de nom

This commit is contained in:
2016-02-02 18:00:51 +01:00
parent 91a7241cb4
commit 707aa5b2ad
2 changed files with 93 additions and 91 deletions

View File

@@ -10,11 +10,47 @@
#include "stdio.h" #include "stdio.h"
#include "analyseur_lexical.h" #include "analyseur_lexical.h"
void openSection ( const char * section );
void closeSection ( const char * section );
void programme (void);
void optDecVariables (void);
void listeDecVariables (void);
void listeDecVariablesBis (void);
void declarationVariable (void);
void optTailleTableau (void);
void listeDecFonctions (void);
void declarationFonction (void);
void listeParam (void);
void optListeDecVariables (void);
void instruction (void);
void instructionAffect (void);
void instructionBloc (void);
void listeInstructions (void);
void instructionSi (void);
void optSinon (void);
void instructionTantque (void);
void instructionAppel (void);
void instructionRetour (void);
void instructionEcriture (void);
void instructionVide (void);
void expression (void);
void expressionBis (void);
void conjonction (void);
void conjonctionBis (void);
void negation (void);
void comparaison (void);
void comparaisonBis (void);
void expression (void);
void expArith (void); void expArith (void);
void expArithBis (void); void expArithBis (void);
void terme (void); void terme (void);
void termeBis (void); void termeBis (void);
void facteur (void); void facteur (void);
void var (void);
void optIndice (void);
void appelFct (void);
void listeExpressions (void);
void listeExpressionsBis (void);
#endif #endif

View File

@@ -3,18 +3,15 @@
int uniteCourante; int uniteCourante;
extern char yytext[100]; extern char yytext[100];
void openSection( const char * section ) void openSection( const char * section ) {
{
affiche_balise_ouvrantexpression( section, 1 ); affiche_balise_ouvrantexpression( section, 1 );
} }
void closeSection( const char * section ) void closeSection( const char * section ) {
{
affiche_balise_fermantexpression( section, 1 ); affiche_balise_fermantexpression( section, 1 );
} }
void programme() void programme() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _optDecVariables_, uniteCourante ) ) { if( est_premier( _optDecVariables_, uniteCourante ) ) {
@@ -27,8 +24,7 @@ void programme()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void optDecVariables() void optDecVariables() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _listeDecVariables_, uniteCourante ) ) if( est_premier( _listeDecVariables_, uniteCourante ) )
@@ -47,12 +43,11 @@ void optDecVariables()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeDecVariables() void listeDecVariables() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _declarationVariable_, uniteCourante ) ) { if( est_premier( _declarationVariable_, uniteCourante ) ) {
declarationVariablisteExpressions(); declarationVariable();
listeDecVariablesBis(); listeDecVariablesBis();
} else { } else {
syntaxError(); syntaxError();
@@ -61,14 +56,13 @@ void listeDecVariables()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeDecVariablesBis() void listeDecVariablesBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {
uniteCourante = yylex(); uniteCourante = yylex();
declarationVariablisteExpressions(); declarationVariable();
listeDecVariablesBis(); listeDecVariablesBis();
} else if( !est_suivanterme( _listeDecVariablesBis_, uniteCourante ) ) { } else if( !est_suivanterme( _listeDecVariablesBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
@@ -77,8 +71,7 @@ void listeDecVariablesBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void declarationVariablisteExpressions() void declarationVariable() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ENTIER ) { if( uniteCourante == ENTIER ) {
@@ -98,8 +91,7 @@ void declarationVariablisteExpressions()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void optTailleTableau() void optTailleTableau() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
@@ -124,9 +116,7 @@ void optTailleTableau()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeDecFonctions() void listeDecFonctions() {
{
/// LDF -> DF LDF | Ø
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _declarationFonction_, uniteCourante ) ) { if( est_premier( _declarationFonction_, uniteCourante ) ) {
@@ -139,8 +129,7 @@ void listeDecFonctions()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void declarationFonction() void declarationFonction() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
@@ -156,8 +145,7 @@ void declarationFonction()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeParam() void listeParam() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
@@ -177,8 +165,7 @@ void listeParam()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void optListeDecVariables() void optListeDecVariables() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _listeDecVariables_, uniteCourante ) ) { if( est_premier( _listeDecVariables_, uniteCourante ) ) {
@@ -190,26 +177,25 @@ void optListeDecVariables()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instruction() void instruction() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _instructionAffect_, uniteCourante ) ) { if( est_premier( _instructionAffect_, uniteCourante ) ) {
instructionAffecterme(); instructionAffect();
} else if( est_premier( _instructionBloc_, uniteCourante ) ) { } else if( est_premier( _instructionBloc_, uniteCourante ) ) {
instructionBloc(); instructionBloc();
} else if( est_premier( _instructionSi_, uniteCourante ) ) { } else if( est_premier( _instructionSi_, uniteCourante ) ) {
instructionSi(); instructionSi();
} else if( est_premier( _instructionTantque_, uniteCourante ) ) { } else if( est_premier( _instructionTantque_, uniteCourante ) ) {
instructionTantquexpression(); instructionTantque();
} else if( est_premier( _instructionAppel_, uniteCourante ) ) { } else if( est_premier( _instructionAppel_, uniteCourante ) ) {
instructionAppel(); instructionAppel();
} else if( est_premier( _instructionRetour_, uniteCourante ) ) { } else if( est_premier( _instructionRetour_, uniteCourante ) ) {
instructionRetour(); instructionRetour();
} else if( est_premier( _instructionEcriture_, uniteCourante ) ) { } else if( est_premier( _instructionEcriture_, uniteCourante ) ) {
instructionEcriturexpression(); instructionEcriture();
} else if( est_premier( _instructionVide_, uniteCourante ) ) { } else if( est_premier( _instructionVide_, uniteCourante ) ) {
instructionVidexpression(); instructionVide();
} else { } else {
syntaxError(); syntaxError();
} }
@@ -217,8 +203,7 @@ void instruction()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionAffecterme() void instructionAffect() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _var_, uniteCourante ) ) { if( est_premier( _var_, uniteCourante ) ) {
@@ -244,8 +229,7 @@ void instructionAffecterme()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionBloc() void instructionBloc() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ACCOLADE_OUVRANTE ) { if( uniteCourante == ACCOLADE_OUVRANTE ) {
@@ -265,8 +249,7 @@ void instructionBloc()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeInstructions() void listeInstructions() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _instruction_, uniteCourante ) ) { if( est_premier( _instruction_, uniteCourante ) ) {
@@ -279,8 +262,7 @@ void listeInstructions()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionSi() void instructionSi() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == SI ) { if( uniteCourante == SI ) {
@@ -303,10 +285,7 @@ void instructionSi()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
// ICI void optSinon() {
void optSinon()
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == SINON ) { if( uniteCourante == SINON ) {
@@ -320,8 +299,7 @@ void optSinon()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionTantquexpression() void instructionTantque() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == TANTQUE ) { if( uniteCourante == TANTQUE ) {
@@ -343,8 +321,7 @@ void instructionTantquexpression()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionAppel() void instructionAppel() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _instructionAppel_, uniteCourante ) ) { if( est_premier( _instructionAppel_, uniteCourante ) ) {
@@ -362,8 +339,7 @@ void instructionAppel()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionRetour() void instructionRetour() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == RETOUR ) { if( uniteCourante == RETOUR ) {
@@ -383,8 +359,7 @@ void instructionRetour()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionEcriturexpression() void instructionEcriture() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ECRIRE ) { if( uniteCourante == ECRIRE ) {
@@ -397,6 +372,12 @@ void instructionEcriturexpression()
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == POINT_VIRGULE ) {
uniteCourante = yylex();
} else {
syntaxErrorMsg( "';' été attendu" );
}
} else { } else {
syntaxErrorMsg( "')' été attendu" ); syntaxErrorMsg( "')' été attendu" );
} }
@@ -410,8 +391,7 @@ void instructionEcriturexpression()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void instructionVidexpression() void instructionVide() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
@@ -423,8 +403,7 @@ void instructionVidexpression()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void expression() void expression() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _conjonction_, uniteCourante ) ) { if( est_premier( _conjonction_, uniteCourante ) ) {
@@ -437,8 +416,7 @@ void expression()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void expressionBis() void expressionBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == OU ) { if( uniteCourante == OU ) {
@@ -453,8 +431,7 @@ void expressionBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void conjonction() void conjonction() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _negation_, uniteCourante ) ) { if( est_premier( _negation_, uniteCourante ) ) {
@@ -467,8 +444,7 @@ void conjonction()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void conjonctionBis() void conjonctionBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ET ) { if( uniteCourante == ET ) {
@@ -483,13 +459,14 @@ void conjonctionBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void negation() void negation() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == NON ) { if( uniteCourante == NON ) {
uniteCourante = yylex(); uniteCourante = yylex();
comparaison();
} else if (est_premier( _comparaison_, uniteCourante )) {
comparaison(); comparaison();
} else { } else {
syntaxError(); syntaxError();
@@ -498,12 +475,11 @@ void negation()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void comparaison() void comparaison() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _expression_, uniteCourante ) ) { if( est_premier( _expression_, uniteCourante ) ) {
expression(); expArith();
comparaisonBis(); comparaisonBis();
} else { } else {
syntaxError(); syntaxError();
@@ -512,14 +488,13 @@ void comparaison()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void comparaisonBis() void comparaisonBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == EGAL || uniteCourante == INFERIEUR) { if( uniteCourante == EGAL || uniteCourante == INFERIEUR) {
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expArith();
comparaisonBis(); comparaisonBis();
} else if( !est_suivanterme( _comparaisonBis_, uniteCourante ) ) { } else if( !est_suivanterme( _comparaisonBis_, uniteCourante ) ) {
syntaxError(); syntaxError();
@@ -528,11 +503,11 @@ void comparaisonBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void expression() void expArith()
{ {
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _terme_, uniteCourante ) ) { if( est_premier( _terme_, yylval ) ) {
terme(); terme();
expArithBis(); expArithBis();
} else { } else {
@@ -542,8 +517,7 @@ void expression()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void expArithBis() void expArithBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == PLUS || uniteCourante == MOINS) { if( uniteCourante == PLUS || uniteCourante == MOINS) {
@@ -558,8 +532,7 @@ void expArithBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void terme() void terme() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _facteur_, uniteCourante ) ) { if( est_premier( _facteur_, uniteCourante ) ) {
@@ -572,8 +545,7 @@ void terme()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void termeBis() void termeBis() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == FOIS || ylval == DIVISE ) { if( uniteCourante == FOIS || ylval == DIVISE ) {
@@ -588,8 +560,7 @@ void termeBis()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void facteur() void facteur() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
@@ -629,8 +600,7 @@ void facteur()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void var() void var() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ID_VAR ) { if( uniteCourante == ID_VAR ) {
@@ -644,8 +614,7 @@ void var()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void optIndice() void optIndice() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
@@ -665,8 +634,7 @@ void optIndice()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void appelFct() void appelFct() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
@@ -692,8 +660,7 @@ void appelFct()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeExpressions() void listeExpressions() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( est_premier( _expression_, uniteCourante ) ) { if( est_premier( _expression_, uniteCourante ) ) {
@@ -706,8 +673,7 @@ void listeExpressions()
closeSection( __FUNCTION__ ); closeSection( __FUNCTION__ );
} }
void listeExpressionsBis(() void listeExpressionsBis(() {
{
openSection( __FUNCTION__ ); openSection( __FUNCTION__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {