%{ #include "y.tab.h" #include #include #include "list.h" extern int yylval ; unsigned lineCount=0, wordCount=0, etats=0,etiquettes=0 ; // gcc list.c ;lex mainEs.l ; gcc lex.yy.c -o mainEs -lfl //garder espaces: //listEtats etat|etat,listEtats //{listEtats} { printf(" listeEtats:%s",yytext); } ; %} space [ ]+|[\t]+ //:espace=p5 etat nul|Q[0-9]* //etendre cette def etiquette [a-z][a-zA-Z0-9]* virgule \, eol \n %% {virgule} { printf("\nvirgul:%s",yytext); return VIRGULE ; } {etat} {printf("\netat:%s",yytext); return ETAT; } {etiquette} { etiquettes++; printf("\netiqt:%s",yytext); {listLabels_p ptrLablCour; listLabels_p label1; printf("\n Labels"); if(!(ptrLablCour=NULL) ) { /* ptrLablCour = malloc (ptrLablCour) */ ;/* pr ne pas en creer à chaq nouveau label */ ptrLablCour=(listLabels_t*)malloc(sizeof(listLabels_t)); if ( !ptrLablCour) { printf("\nAllocation impossible");ptrLablCour->val="0000";printf("\nptrLablCour->val=",ptrLablCour->val);/* test AP malloc*/} } if ( ptrLablCour== NULL) //AP malloc printf("ici"); return -1; // if (label1!=((listLabels_p)malloc(sizeof(struct listLabels_t)))) if (!(label1=(struct listLabels *) malloc(sizeof(struct listLabels)))) abort(); printf("\n dacodac"); // printf("\nlbl1 non nul et lbl$3=%d",$3); label1->prec = NULL; label1->val="poubl"; //printf("\nyytext=%s",yytext); // int b=3; printf("b=is%s",b); label1->suiv=NULL; ptrLablCour->suiv=label1; (label1->prec)=ptrLablCour; ptrLablCour=label1; /* attention const char* */ /* =ptrLablCour=ptrLablCour+1 */ /*p63*/ printf("fin labls"); } return LABEL; } {space} { printf("\nspace "); return SPACE; } {eol} { printf("\neol"); return EOL;} /*p33*/ %% main(){//p37 //voir non deterministe listLabels_t * label1; printf("insertion label1"); FILE * file ; if (!(file=fopen("dat.dat", "r") )) { printf("Erreur") ; abort() ; } yyin=file ; printf("\nLecture OK2") ; printf("\nlbl lv y1 ") ; // yylex() ; int choix =1 ; while( choix != (-1)) { printf("\nMENU******************************************************") ; printf( "\n1)prendre MT\n2)afer(MT)\n\n0)Interpreteur de commandes \n-1:Sortir\n") ; scanf("%i", &choix) ; switch(choix ) { printf("in switch"); case -1:exit(0) ; case 1: { printf("\nchoix 1=get MT") ; //stdin while(!feof(yyin)) { printf("\n WHILE:\n"); printf("\nbefore parse\n"); //yyparse();//p17 //yylex(); printf("\nafter parse"); } printf("\nSyntaxe de dat.dat OK"); //adequation:mem nb de case d'1 ligne sur l autre: listLabels label1; listLabels * uneListLabels; uneListLabels=&label1; printf("\nuneListLabels=%i", uneListLabels); enumListLabel(uneListLabels); break; } default : printf("default") ; break ; } } printf("sortie") ; return (EXIT_SUCCESS) ; } typedef struct listLabels { struct listLabels * prec; //char * nom[30]; char * val; struct listLabels * suiv; // listLabels_t, *listLabels_p; } listLabels_t, *listLabels_p; //typedef struct listLabels listLabels_t;