kichou90
Messages postés1Date d'inscriptionjeudi 26 décembre 2013StatutMembreDernière intervention26 décembre 2013
-
26 déc. 2013 à 14:13
bonjour,
quelqu'un peut m'aidé ,mon travaille consiste a faire un mini compilateur C avec l'outils flex et bison et j'ai un problem lors de l'execution de mon programme bison,
je reçoi cette erreur lors de l'execution :
********************************************************************************
mahmoud@mahmoud:~/Desktop$ bison -d mini_c.y
mini_c.y: warning: 18 nonterminals useless in grammar
mini_c.y: warning: 50 rules useless in grammar
mini_c.y:75.8-9: fatal error: start symbol PG does not derive any sentence
*******************************************************************************
mon code est
%{
#include "global.h"
#include <stdio.h>
#include <stdlib.h>
extern FILE *yyout;
extern char *yytext;
typedef struct element{
char *nom;
char *type;
double value;
struct element *svt;
} element;
element *E;
int chercher (element *t, char *s)
{element *temp=t;
if (temp==NULL) return 0;
else
while (temp!= NULL){
if (!strcmp(temp->nom,s)) { printf("trouver %s",temp->nom); return 1;}
temp=temp->svt;
}
s=NULL;
return 0;
}
void afficher(element *t)
{
element *z=t;
if (z==NULL) printf("vide \n");
while (z!= NULL)
{
printf("nom: %s type: %s \n",z->nom,z->type);
z=z->svt;
}
}
void Ajout(char *nom,char *type,element **tete)
{element *n;
if (chercher(*tete,nom)==0)
{
n=(element*)malloc(sizeof(element));
n->nom=nom;
n->type=type;
n->svt=*tete;
*tete=n;
}
}
%}
%union{ int I;
double R;
char *S;
struct element *E;
}
%token <I> CSTI
%token <R> CSTR
%token <S> INTEGER REAL CHAR LONG LOGICAL FLOAT
%token <E> IDF
%token stdlib stdio math include Main IF DOWHILE END ENDDO ENDIF ENDR WHILE THEN ELSE FOR TRUE FALSE '.' 'h' '#' ';' ',' '(' ')' '*' '-' '+' '=' '/' '%' not_equal equal inferieur_eq superieur_eq et ou
%left '+' '-'
%left '*' '/' '%'
%left inferieur superieur inferieur_eq superieur_eq //'<' '>' '<=' '>='
%left not_equal equal //'!=' '=='
%left et ou //'&&' '||'
%start PG
%%
PG: Entete Liste_declaration Main '(' ')' '{' Instruction '}' {printf("correcte\n");YYACCEPT;} //fonction a ajouté
Entete: '#' include inferieur Nom_bibl'.''h' superieur ; // point h !! a revoir
Nom_bibl: stdio //{strcopy($$=$1);}
| stdlib //{strcopy($$=$1);}
| math //{strcopy($$=$1);}
;
Liste_declaration: declaration ';' Liste_declaration
| declaration ';'
;
declaration: Type Liste_idf
;
Liste_idf: CST Liste_idf
|CST
;
Type: INTEGER {$<S>$=$1;}
| LONG {$<S>$=$1;}
| CHAR {$<S>$=$1;}
| LOGICAL {$<S>$=$1;}
| REAL {$<S>$=$1;}
;
Instruction : Instruction Inst_if
| Instruction Inst_for
| Instruction Inst_while
| Inst_if
| Inst_for
| Inst_while
;
Inst_if : IF '('EXP_COND')' THEN Instruction ENDIF
| IF '('EXP_COND')' THEN Instruction ELSE Instruction ENDIF ;
;
Inst_for : FOR '('EXP_COND')' Instruction
;
Inst_while : DOWHILE '('EXP_COND')' Instruction ENDDO
;
EXP_COND : COND
| '('COND et COND')'
| '('COND ou COND')'
;
COND : '('EXP inferieur EXP')'
|'('EXP superieur EXP')'
|'('EXP equal EXP')'
|'('EXP not_equal EXP')'
|'('EXP inferieur_eq EXP')'
|'('EXP superieur_eq EXP')'
|'('EXP equal LOG')'
|'('EXP not_equal LOG')'
;
EXP: VAR //{$$=$1;}
|EXP '+' VAR
|EXP '-' VAR
|EXP '*' VAR
|EXP '/' VAR
;
VAR:IDF'('CSTI')'
|IDF'('IDF')'
|IDF {if ($1->type=="INTEGER") $<I>$=$1->value; else if($1->type=="REAL") $<R>$=$1->value; }
|CST ;
CST:CSTI {$<I>$=$1;}
|CSTR {$<R>$=$1;}
;
LOG : TRUE|FALSE;
%%
int yyerror(char *s) {printf("%s\n",s); }
extern char *yytext;
extern int nb_line;
int yyerror ( char* msg)
{
printf("%d: %s avant %s\n", nb_line, msg, yytext);
}
int main (void)
{
yyparse();
}