Bleuarff pouet | Bonjour
 J'ai un fichier .y qui a pour but de traduire un code en pseudo-langage en  anglais. Il se compile correctement, mais lorsque je l'execute, j'ai une syntax error à chaque ligne du fichier contenant mon code. Je ne comprend pas pourquoi, et depuis 3 heures que je suis dessus je sature. Qqun à une idée ?
   voila le fichier test.y:
  Code :
 - %{
 - #include <ctype.h>
 - #include <stdio.h>
 - #include <string.h>
 - %}
 - %token PROGRAMME
 - %token DEBUT
 - %token SI
 - %token CODE
 - %token LIGNE_VIDE
 - %token FIN
 - %%
 - input	:	input line
 -        |	/*vide*/
 - 	;
 - line	:	'\n'
 - 	|     	expr'\n'
 -      	;
 - expr	:	DEBUT	{printf("BEGIN\n" );}
 -      	|	FIN	{printf("END\n" );}
 -      	|	SI	{printf("IF THEN\n" );}
 - 	|	CODE	/*empty*/
 - 	|	PROGRAMME	{printf("PROGRAM\n" );}
 - 	|	LIGNE_VIDE /*rien*/
 - 	;
 - %%
 - FILE *yyin;
 - int yylex(){
 - 	int i=0;
 - 	int c;
 - 	char l[50]="";
 - 	fgets(l, 50, yyin);
 - 	if (l!=NULL){
 -   while ((l[i]!='\n') && (i<50)){
 -   	i++;
 -   }
 -   if (l[i]=='\n')
 -   {
 -   	l[i]='\0';
 -   }
 -   if (strcmp(l, "PROGRAMME" )==0){
 -   	return PROGRAMME;
 -   }
 -   else if (strcmp(l, "DEBUT" )==0)
 -   {	return DEBUT;}
 -   else if (strcmp(l, "FIN" )==0)
 -   {	return FIN;}
 -   else if (strncmp(l, "SI", 2)==0)
 -   {	return SI;}
 -   else if (l[0]=='\0'){
 -   	return LIGNE_VIDE;
 -   }
 -   else{
 -   	printf("%s\n",l);
 -   	return CODE;
 -   }
 - 	}
 - }
 - int yyerror(char *s)
 - {
 - 	printf("erreur: %s\n",s);
 - }
 - main(){
 - 	yyin=fopen("gram", "r" );
 - 	while(!feof(yyin)){
 -   yyparse();
 - 	}
 - 	fclose(yyin);
 - }
 
  |  
 
   et mon fichier contenant le langage:
  Code :
 - PROGRAMME
 - DEBUT
 - SI (a=b) ALORS
 - DEBUT
 - 	"pouet"
 - FIN
 - FIN
 
  |  
    Message édité par Bleuarff le 06-06-2004 à 21:27:12
  |