Hi, I use MSVC 2005 beta2 to build flex/bison, but I have many errors when I build my programms with them. With flex.exe and bison.exe from GnuWin32, I generated the files: lex.yy.c and y.tab.c Then, with MSVC I created a Win32 console application. Whitin, I put main.c, lex.yy.c, y.tab.c , and my header files. But when I built my project, I have these errors:
description_fichier_correspondance.lex(81) : error C2065: 'yylval' : undeclared identifier description_fichier_correspondance.lex(129) : error C2224: left of '.sval' must have struct/union type description_fichier_correspondance.lex(116) : error C2224: left of '.uval' must have struct/union type description_fichier_correspondance.lex(88) : error C2224: left of '.ival' must have struct/union type description_fichier_correspondance.lex(81) : error C2224: left of '.ival' must have struct/union type description_fichier_correspondance.lex(52) : error C2065: 'logfile' : undeclared identifier description_fichier_correspondance.lex(130) : error C2065: 'T_STR' : undeclared identifier description_fichier_correspondance.lex(97) : error C2065: 'T_DOUBLE' : undeclared identifier description_fichier_correspondance.lex(89) : error C2065: 'T_ENTIER' : undeclared identifier description_fichier_correspondance.lex(82) : error C2065: 'T_NONSIGNE' : undeclared identifier Here my flex/bison files : ============================================== D [0-9] /* mantisse */ E [DEde][\+\-]?{D}+ /* exposant */ H [0-9a-fA-F] /* digit hexa */ O [0-7] /* digit octal */ B [01] /* digit binaire */ %START CM %option yylineno %option noyywrap %% "/*" { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); BEGIN CM; } <CM>"*/" { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); BEGIN 0; } <CM>\* | <CM>[a-zA-Z0-9_\-\.]* | <CM>[\%\(\)\[\]\{\}\,\+\:\/ ]* { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); } [ \t\n] { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); } [\(\)\[\]\{\}\,] { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); return *yytext; } \+?{D}+ { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.ival = atol( yytext ); return T_NONSIGNE; } \-{D}+ { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.ival = atol( yytext ); return T_ENTIER; } [\+\-]?{D}+"."{D}*({E})? | [\+\-]?{D}*"."{D}+({E})? | [\+\-]?{D}+{E} { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.dval = (double) atof( yytext ); return T_DOUBLE; } \%[hH]{H}+ { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.uval = (unsigned long) strtol( yytext+2, (char **)NULL, 16); return T_NONSIGNE; } \%[bB]{B}+ { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.uval = (unsigned long) strtol( yytext+2, (char **)NULL, 2); return T_NONSIGNE; } \%[oO]{O}+ { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.uval = (unsigned long) strtol( yytext+2, (char **)NULL, 8); return T_NONSIGNE; } [a-zA-Z][a-zA-Z0-9_\-\.]* { if (logfile != (FILE *)NULL) fprintf(logfile, "%s", yytext); yylval.sval = malloc( yyleng+1 ); if ( yylval.sval == (char*)NULL ) { fprintf( stderr, "Memoire pleine\n"); exit(-1); } strcpy( yylval.sval, yytext ); return T_STR; } %% ====================================================== %{ #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <errno.h> #include <string.h> #define ERREUR_SYNTAXE "Erreur de syntaxe dans la description d'une correspondance" #define TEST_PTR(ptr,type) if (ptr == (type *)NULL) {\ error("pointeur (type *)ptr NULL");\ exit(-1);\ } #include "structure_correspondance.h" #include "structure_format_thomson.h" #include "leste.h" /* "LT_structures.h" pour utiliser LT_MAX_NAME */ %} /*types possibles pour les elements syntaxiques d'un fichier de correspondance*/ %union { long ival; unsigned long uval; double dval; char* sval; LISTE_CORRESPONDANCE* lcorrespondanceval; }; /* definition de nom de Type: T_ENTIER T_NONSIGNE T_DOUBLE T_STR */ %token <ival> T_ENTIER %token <uval> T_NONSIGNE %token <dval> T_DOUBLE %token <sval> T_STR /* types des differents elements syntaxiques d'un fichier de correspondance*/ %type <uval> nb_messages id_liaison id_message offset %type <dval> periode nombre_flottant %type <sval> nom_bus nom_message %type <lcorrespondanceval> description_correspondance liste_correspondance /*-----------------Description du fichier de correspondance-------------------*/ %start description_fichier_correspondance %% description_fichier_correspondance : liste_correspondance { tete_correspondance( $1 ); } ; liste_correspondance : '{' description_correspondance '}' { $$ = $2; } | liste_correspondance '{' description_correspondance '}' { $$ = add_correspondance( $1, $3 ); } | error '}' { fichier_correspondance_error(ERREUR_SYNTAXE); } ; description_correspondance : nom_bus nom_message id_liaison id_message offset periode nb_messages { $$ = cre_correspondance( $1, $2, $3 , $4, $5, $6, $7 ); } | nom_bus nom_message id_liaison id_message offset { $$ = cre_correspondance( $1, $2, $3 , $4, $5 , 0.0, 0 ); } ; nom_bus : T_STR { $$ = $1; } ; nom_message : T_STR { $$ = $1; } ; id_liaison : T_NONSIGNE { $$ = $1; } ; id_message : T_NONSIGNE { $$ = $1; } ; nb_messages : T_NONSIGNE { $$ = $1; } ; offset : T_NONSIGNE { $$ = $1; } ; periode : nombre_flottant { $$ = $1; } ; nombre_flottant : T_ENTIER { $$ = (double) $1; } | T_NONSIGNE { $$ = (double) $1; } | T_DOUBLE { $$ = (double) $1; } ; %% /*-------------Fin de description du fichier de correspondance----------------*/ static int was_error; static FILE* logfile; static FILE* infile; static FILE* errfile; extern int yywrap(); extern int yylineno; extern FILE* yyin; extern char* allouer( /* unsigned long size */ ); /* routine d'allocation systeme de memoire */ static char empty_string[] = ""; char mess_buffer[120]; unsigned long taille_LISTE_CORRESPONDANCE= sizeof(LISTE_CORRESPONDANCE); static RACINE_CORRESPONDANCE* root_ptr; /******************************************************************************* * * FONCTION : free_racine_correspondance * * PARAMETRES : racine de la structure de correspondance * * ACTIONS : cette fonction libere la memoire occupee par * la structure de correspondace le scenario * * VALEURS RETOURNEES : 0 si Ok * *******************************************************************************/ void free_racine_correspondance( racine ) RACINE_CORRESPONDANCE* racine; { LISTE_CORRESPONDANCE* element; #ifdef DEBUG_YACC fprintf(stdout,"free_racine_correspondance()\n"); #endif while ( racine->liste_correspondance !=(LISTE_CORRESPONDANCE *)NULL ) { element = racine->liste_correspondance; racine->liste_correspondance = racine->liste_correspondance->prochaine_correspondance; free(element->nom_bus); free(element->nom_message); free(element); } racine->nb_correspondance = 0; } /******************************************************************************* * * FONCTION : analyse_fichier_correspondance * * PARAMETRES : fichier a analyser et fichiers de sorties (erreurs..) * * ACTIONS : routine de lancement de l'analyseur de fichier de * correspondance Format Commun <-> Format Thomson * * VALEURS RETOURNEES : 1 si Ok, O si erreur, * racine de la structure de correspondance ainsi cree * *******************************************************************************/int analyse_fichier_correspondance( in, log, err, racine ) FILE* in; FILE* log; FILE* err; RACINE_CORRESPONDANCE* racine; { #ifdef DEBUG_YACC fprintf(stdout,"analyse_fichier_correspondance()\n"); TEST_PTR( racine, RACINE_CORRESPONDANCE ); #endif root_ptr = racine; infile = in; logfile = log; errfile = err; yyin = infile; /* initialisation de analyse_fichier_correspondance */ was_error = 0; /* Lors de l'appel a la fonction la structure de correspondance sera initialisee: La racine de cette structure: 'root_ptr' (variable globale) est initialisee lors de l'appel a 'tete_correspondance' */ yyparse(); if (was_error) { free_racine_correspondance(racine); } return !was_error; } /******************************************************************************* * * FONCTION : fichier_correspondance_warning * * PARAMETRES : pointeur sur la chaine a afficher * * ACTIONS : routine de signalisation d'un WARNING * * VALEURS RETOURNEES : Aucune * *******************************************************************************/ fichier_correspondance_warning( str ) char *str; { if (logfile != (FILE *)NULL) fprintf( logfile, "\n<line %4d> WARNING: %s\n\n",yylineno, str ); if (errfile != (FILE *)NULL) fprintf( errfile, "<line %4d> WARNING: %s\n",yylineno, str ); } /******************************************************************************* * * FONCTION : fichier_correspondance_error * * PARAMETRES : pointeur sur la chaine a afficher * * ACTIONS : routine de signalisation d'une ERREUR * * VALEURS RETOURNEES : Aucune * *******************************************************************************/ fichier_correspondance_error( str ) char *str; { if (logfile != (FILE *)NULL) fprintf( logfile, "\n<line %4d> ERREUR: %s\n\n",yylineno, str ); if (errfile != (FILE *)NULL) fprintf( errfile , "<line %4d> ERREUR: %s\n",yylineno, str ); was_error = 1; } /******************************************************************************* * * FONCTION : yyerror * * PARAMETRES : pointeur sur la chaine a afficher * * ACTIONS : visualisation d'une erreur de syntaxe dans la * grammaire * * VALEURS RETOURNEES : Aucune * *******************************************************************************/ yyerror( str ) char *str; { if (logfile != (FILE *)NULL) fprintf( logfile, "\n<line %4d> %s\n\n", yylineno, str ); if (errfile != (FILE *)NULL) fprintf( errfile, "\n<line %4d> %s\n", yylineno, str ); was_error = 1; } /******************************************************************************* * * FONCTION : yywrap * * PARAMETRES : Aucun * * ACTIONS : on a atteint la fin du fichier: retour pour la fin de * l'analyse * * VALEURS RETOURNEES : 1 * *******************************************************************************/ ywrap() { return 1; }; /*----------------------Actions associees a la grammaire----------------------*/ #include "lex.yy.c" /* utilisation de yyparse() */ /******************************************************************************* * * FONCTION : tete_correspondance * * PARAMETRES : liste des correspondance * * ACTIONS : creation de l'entete de structure * * VALEURS RETOURNEES : La racine de la structure de correspondance: * 'root_ptr' (variable globale) est initialisee * *******************************************************************************/ void tete_correspondance( liste ) LISTE_CORRESPONDANCE *liste; { if (was_error) return; #ifdef DEBUG_YACC fprintf(stdout,"tete_correspondance()\n"); TEST_PTR( liste, LISTE_CORRESPONDANCE ); #endif root_ptr->liste_correspondance = liste; root_ptr->nb_correspondance = 0; while (liste != (LISTE_CORRESPONDANCE *)NULL) { root_ptr->nb_correspondance++; liste = liste->prochaine_correspondance; } } /******************************************************************************* * * FONCTION : add_correspondance * * PARAMETRES : liste des correspondances, * la correspondance a ajoutee * * ACTIONS : ajout d'une correspondance dans la liste des * correspondances * * VALEURS RETOURNEES : liste des correspondances * *******************************************************************************/ LISTE_CORRESPONDANCE *add_correspondance( liste, correspondance ) LISTE_CORRESPONDANCE *liste; LISTE_CORRESPONDANCE *correspondance; { LISTE_CORRESPONDANCE *ptr; if (was_error) return (LISTE_CORRESPONDANCE *)NULL; #ifdef DEBUG_YACC fprintf(stdout,"add_correspondance(%s %s)\n", correspondance->nom_bus, correspondance->nom_message ); TEST_PTR( liste, LISTE_CORRESPONDANCE); TEST_PTR( correspondance, LISTE_CORRESPONDANCE ); #endif ptr = liste; while (1) { /* verification de l'unicite du nom de correspondance */ if( (!strcmp(ptr->nom_bus,correspondance->nom_bus)) &&(!strcmp(ptr->nom_message,correspondance->nom_message)) ) { sprintf(mess_buffer,"une correspondance pour <%s/%s> est deja declare", ptr->nom_bus,ptr->nom_message); fichier_correspondance_warning(mess_buffer); } /* ajout d'une correspondance en fin de liste */ if (ptr->prochaine_correspondance == (LISTE_CORRESPONDANCE *)NULL) { ptr->prochaine_correspondance = correspondance; break; } ptr = ptr->prochaine_correspondance; } return liste; } /******************************************************************************* * * FONCTION : cre_correspondance * * PARAMETRES : Noms du bus et du message, * Identificateurs de la liaison et du message, * Periode et Nb de messages repetes pour les analogiques * * ACTIONS : creation d'une nouvelle correspondance * * VALEURS RETOURNEES : une correspondance * *******************************************************************************/ LISTE_CORRESPONDANCE *cre_correspondance( Nom_bus, Nom_message, Id_liaison, Id_message, Offset, Periode, Nb_messages ) char *Nom_bus; char *Nom_message; unsigned long Id_liaison; unsigned long Id_message; unsigned long Offset; double Periode; unsigned long Nb_messages; { LISTE_CORRESPONDANCE *ptr; if (was_error) return (LISTE_CORRESPONDANCE *)NULL; #ifdef DEBUG_YACC fprintf(stdout,"cre_correspondance( %s %s %d %d %d %f %d )\n", Nom_bus, Nom_message, Id_liaison, Id_message, Offset, Periode, Nb_messages ); TEST_PTR( Nom_bus, char ); TEST_PTR( Nom_message, char ); TEST_PTR( ptr, LISTE_CORRESPONDANCE ); #endif ptr = (LISTE_CORRESPONDANCE*) allouer( taille_LISTE_CORRESPONDANCE ); ptr->prochaine_correspondance = (LISTE_CORRESPONDANCE *)NULL; if ( ( strlen(Nom_bus) >= LT_MAX_NAME ) || ( strlen(Nom_message) >= LT_MAX_NAME ) ) { sprintf(mess_buffer,"Pour <%s/%s> un nom est trop grand: lg >= %d", Nom_bus, Nom_message, LT_MAX_NAME ); fichier_correspondance_error(mess_buffer); } ptr->nom_bus = Nom_bus; ptr->nom_message = Nom_message; if ( Id_liaison > ID_LIAISON_MAX ) { sprintf(mess_buffer,"Identificateur de liaison: %d > %d", Id_liaison, ID_LIAISON_MAX ); fichier_correspondance_error(mess_buffer); return ptr; } if ( Id_message > ID_MESSAGE_MAX ) { sprintf(mess_buffer,"Identificateur de message: %d > %d", Id_message, ID_MESSAGE_MAX ); fichier_correspondance_error(mess_buffer); return ptr; } if ( Offset > OFFSET_MAX ) { sprintf(mess_buffer,"Offset: %d > %d", Offset, OFFSET_MAX ); fichier_correspondance_error(mess_buffer); return ptr; } ptr->id_liaison = (unsigned char)Id_liaison; ptr->id_message = (unsigned short)Id_message; ptr->offset = (short)Offset; ptr->nb_messages_repetes = Nb_messages; ptr->periode = Periode; return ptr; } ================================================ Thx _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison