Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3026 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  flex && unix && c++

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

flex && unix && c++

n°1346919
BlackHole
Moi j'ai un gros gun
Posté le 14-04-2006 à 14:54:52  profilanswer
 

Bonjour,  
 
J'ai un probleme d'execution d'un programme. Il est developpé en C++ avec l'appel a une fonction d'analyse lexical generer automaiquement sous flex. Son but: recuperer des information utile dans des fichiers .h et .c.  
 
Je l'ai tester sous windows et il fonctionne correctement. Mais au passage sous unix il fonctionne sauf la fonction d'analyse lexical ne marche pas.  
Precision: on passe bien dedans.  
voici le fichier .l  
 
Code:  
%{  
#include "PARSER.h"  
%}  
%option noyywrap  
%s macroVerHi macroVerLo macro256Proc macroProcessState macroVendor  
/****************************useful expressions********************************/  
versionHigh      "#define HIGH_SW_VERSION"[ \t]*  
versionLow      "#define LOW_SW_VERSION"[ \t]*"0x"  
more256Proc     "RTK_MORE_THAN_256_PROCESSES_FTR"  
processState    "TRA_PROCESS_STATE_DBG"  
vendorString    "USB_TRACE_VENDOR_STR_FTR"  
macro           .+  
retourchariot   \n  
 
%%  
{versionHigh}   {BEGIN(macroVerHi);}  
{versionLow}   {BEGIN(macroVerLo);}  
{more256Proc}   {BEGIN(macro256Proc);}  
{processState}   {BEGIN(macroProcessState);}  
{vendorString}   {BEGIN(macroVendor);}  
 
<macroVerHi>{macro}/\n            {fprintf(yyout, "%s", yytext);BEGIN(INITIAL);}  
<macroVerLo>{macro}/\n            {fprintf(yyout, "%s\n", yytext);BEGIN(INITIAL);}  
<macro256Proc>{macro}/\n         {fprintf(yyout, "More256Processes\n" );BEGIN(INITIAL);}  
<macroProcessState>{macro}/\n      {fprintf(yyout, "ProcessState\n" );BEGIN(INITIAL);}  
<macroVendor>{macro}/\n            {fprintf(yyout, "VendorString\n" );BEGIN(INITIAL);}  
 
{retourchariot}       {/* on fait rien */}  
.                     {/* on fait rien */}  
%%  
void parsingMisc(void)  
{  
    yylex();  
}  
 
 
voici le make file  
 
Code:  
parsingmisc.c: parsingmisc.l  
   flex -oparsingmisc.c -Pmiscfile parsingmisc.l  
   dos2unix lex.yy.c lex.yy.c  
     
main.exe: main.o MISC.o PARSER.o parsingmisc.o  
   g++ -Wall -o main.exe main.o MISC.o PARSER.o parsingmisc.o  
 
parsingmisc.o: parsingmisc.c parsingmisc.h  
   g++ -Wall -c parsingmisc.c -lfl  
     
PARSER.o: PARSER.cpp PARSER.h  
   g++ -Wall -c PARSER.cpp    
 
MISC.o: MISC.cpp MISC.h PARSER.h  
   g++ -Wall -c MISC.cpp  
 
main.o: main.cpp MISC.h  
   g++ -Wall -c main.cpp  
 
clean:  
   rm -f main.o MISC.o PARSER.o parsingmisc.o  
 
cleanall: clean  
   rm -f main.exe  
   rm -f parsingmisc.c  
     
all: parsingmisc.c main.exe  

mood
Publicité
Posté le 14-04-2006 à 14:54:52  profilanswer
 

n°1346924
_darkalt3_
Proctopathe
Posté le 14-04-2006 à 14:56:17  profilanswer
 

balise code :o !
 

n°1346925
zapan666
Tout est relatif
Posté le 14-04-2006 à 14:58:01  profilanswer
 

uhm, je sais pas si c'est ça mais sous windows, le retour à la ligne, c'est \r\n Donc si tu parce ton fichier windows sous unix, ça peut être être la cause du problème
 
Essaye toujours avec ça, ça ne mange pas de pain  

Code :
  1. retourchariot   \\r\\n


Message édité par zapan666 le 14-04-2006 à 14:58:35

---------------
my flick r - Just Tab it !
n°1346971
BlackHole
Moi j'ai un gros gun
Posté le 14-04-2006 à 15:49:40  profilanswer
 

Bon pour les purist et pour des complement d'info:
 
le makefile sous UNIX
 

Code :
  1. parsingmisc.c: parsingmisc.l
  2. flex -l -oparsingmiscUNIX.c -Pmiscfile parsingmisc.l
  3. dos2unix parsingmiscUNIX.c parsingmisc.c
  4. main.exe: main.o MISC.o PARSER.o parsingmisc.o
  5. g++ -Wall -o main.exe main.o MISC.o PARSER.o parsingmisc.o
  6. parsingmisc.o: parsingmisc.c parsingmisc.h
  7. g++ -Wall -c parsingmisc.c -lfl
  8. PARSER.o: PARSER.cpp PARSER.h
  9. g++ -Wall -c PARSER.cpp
  10. MISC.o: MISC.cpp MISC.h PARSER.h
  11. g++ -Wall -c MISC.cpp
  12. main.o: main.cpp MISC.h
  13. g++ -Wall -c main.cpp
  14. clean:
  15. rm -f main.o MISC.o PARSER.o parsingmisc.o
  16. cleanall: clean
  17. rm -f main.exe
  18. rm -f parsingmisc.c
  19. all: parsingmisc.c main.exe


 
le fichier .h de la classe appelante

Code :
  1. #ifndef PARSEUR_H
  2. #define PARSEUR_H
  3. #include <string>
  4. #include <stdio.h>
  5. #ifndef EXTERNAL_VARIABLE
  6. #define EXTERNAL_VARIABLE
  7. extern FILE* miscfilein;
  8. extern FILE* miscfileout;
  9. #endif
  10. using namespace std;
  11. class Parser
  12. {
  13. public:
  14. Parser();
  15. ~Parser();
  16. void parsingMISCsection(const string fichierentree);
  17. };
  18. #endif


 
le fichier Cpp de la classe
 

Code :
  1. #include "PARSER.h"
  2. #include "parsingmisc.h"
  3. Parser::Parser()
  4. {
  5. //none
  6. }
  7. Parser::~Parser()
  8. {
  9. //none
  10. }
  11. void Parser::parsingMISCsection(const string fichierentree)
  12. {
  13. miscfilein= fopen(fichierentree.c_str(), "r" );
  14. if (miscfilein==NULL)
  15. {
  16.  cout<<"impossible d'ouvrir "<<fichierentree<<endl;
  17.  exit(-1);
  18. }
  19. miscfileout = fopen("resultat.txt","a" );
  20. if (miscfileout==NULL)
  21. {
  22.  printf("impossible d'ouvrir resultat.txt" );
  23.  exit(-1);
  24. }
  25. parsingMisc();
  26. fclose(miscfileout);
  27. fclose(miscfilein);
  28. }


 
le fichier .h regoupant toutes mes analyse futures

Code :
  1. #ifndef TOTO
  2. #define TOTO
  3. void parsingMisc(void);
  4. #endif


 
le fichier l generant un fichier C pour faire  l'analyse lexical

Code :
  1. %{
  2. #include "PARSER.h"
  3. %}
  4. %option noyywrap
  5. %s macroVerHi macroVerLo macro256Proc macroProcessState macroVendor
  6. /****************************useful expressions********************************/
  7. versionHigh "#define HIGH_SW_VERSION"[ \t]*
  8. versionLow "#define LOW_SW_VERSION"[ \t]*"0x"
  9. more256Proc "RTK_MORE_THAN_256_PROCESSES_FTR"
  10. processState "TRA_PROCESS_STATE_DBG"
  11. vendorString "USB_TRACE_VENDOR_STR_FTR"
  12. macro .+
  13. retourchariot \r\n
  14. %%
  15. {versionHigh} {BEGIN(macroVerHi);}
  16. {versionLow} {BEGIN(macroVerLo);}
  17. {more256Proc} {BEGIN(macro256Proc);}
  18. {processState} {BEGIN(macroProcessState);}
  19. {vendorString} {BEGIN(macroVendor);}
  20. <macroVerHi>{macro} {printf("versionHigh\n" );fprintf(yyout, "%s", yytext);BEGIN(INITIAL);}
  21. <macroVerLo>{macro} {printf("versionLow\n" );fprintf(yyout, "%s\n", yytext);BEGIN(INITIAL);}
  22. <macro256Proc>{macro} {printf("more256Proc\n" );fprintf(yyout, "More256Processes\n" );BEGIN(INITIAL);}
  23. <macroProcessState>{macro} {printf("processState\n" );fprintf(yyout, "ProcessState\n" );BEGIN(INITIAL);}
  24. <macroVendor>{macro} {printf("vendorString\n" );fprintf(yyout,"VendorString\n" );BEGIN(INITIAL);}
  25. {retourchariot} {/* on fait rien */}
  26. {macro} {/* on fait rien */}
  27. %%
  28. void parsingMisc(void)
  29. {
  30.     printf("Start parsing\n" );
  31.     yylex();
  32.     printf("Finish parsing\n" );
  33. }

n°1346974
BlackHole
Moi j'ai un gros gun
Posté le 14-04-2006 à 15:52:27  profilanswer
 

Le changement des balise de retour chariot \n sous windows en \r\n sous unix ne cahnge rien.
en executant ce code on ne voit pas les sorties standards des printf des macros. en contre partie celles du  void parsingMisc(void) sont bien visible

n°1346985
_darkalt3_
Proctopathe
Posté le 14-04-2006 à 16:11:00  profilanswer
 

Qu'est-ce qui ne fonctionne pas exactement ?
 
t'as débuggé ton code ligne par ligne sous unix ?

n°1348661
BlackHole
Moi j'ai un gros gun
Posté le 18-04-2006 à 11:44:07  profilanswer
 

oui lord de l'appel de la fonction ecrite en flex soit il ne reconais rien et sort le tout sur la sortie yyout ou il reconnais tous comme la derniere option soit "n'import quoi"
 

n°1348676
BlackHole
Moi j'ai un gros gun
Posté le 18-04-2006 à 12:00:10  profilanswer
 

please help me


Message édité par BlackHole le 18-04-2006 à 12:00:44
n°1348718
_darkalt3_
Proctopathe
Posté le 18-04-2006 à 12:51:14  profilanswer
 

t'as plusieurs jeux de test ?

n°1352640
BlackHole
Moi j'ai un gros gun
Posté le 24-04-2006 à 13:03:37  profilanswer
 

Probleme resolu:
 
L'importation de programme ecrite sous windows introduit des caractere de fin de ligne invisible sous nedit (LINUX et UNIX) seul Xemacs les affiche.
Donc il vous faut ecrire le programme sous unix directement.
 
1 semaine et demi pour ça ... BANG BANG


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  flex && unix && c++

 

Sujets relatifs
lecture "dynamique" d'un fichier sous Unixlancer un shell ou un executable unix
shell unix application de masques...[C / Unix] Recuperer un evenement clavier en mode console
[UNIX - SHELL] Définition du prompt en kshFaire un script shell sous Unix
novice en programmation doit programmer sous unix.Appel de commande shell unix en java
GD lib, plateforme windows et unixDifference shell Unix et shell Linux
Plus de sujets relatifs à : flex && unix && c++


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)