Erreur: expected specifier-qualifier-list bef

Riadh -  
 Riadh -
Bonjour,
j'ai programmé des fichiers, un fichier .l un autre .y et un.h et lors de la compilation j'ai l'erreur suivante:

In file included from DrawLex1.l:4:
analyser.y:24: erreur: expected specifier-qualifier-list before «nodeType»
analyser.y: Dans la fonction «fonction» :
analyser.y:69: attention : incompatible implicit declaration of built-in function «strcpy»


voila le fichier.y:


%{
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "arbre.h"

/* prototypes */
nodeType *flot(int value);
nodeType *fonction(char* ft);
nodeType *carSpecial(int oper, int nops, ...);
void freeNode(nodeType *p);
void yyerror(char *s);
int ex(nodeType *p);
int yylex(void);

int sym[26]; /* symbol table */

%}
%union{
char *cIndex;
int intval;
float ival;
char sIndex;
nodeType *nPtr;
};
%token <cIndex> DRAW
%token <intval> NUMBER
%token <ival> FLOAT
%token <sIndex> VIR
%token <sIndex> PARTHO
%token <sIndex> PARTHF
%type <nPtr> ligne av couple parametre

%%

phrase: ligne phrase ';'|;
ligne: av PARTHF {$$=carSpecial(PARTHF,2,$1,NULL);}


av: DRAW PARTHO parametre {$$=carSpecial(PARTHO,2,$1,$3);};
parametre: couple VIR couple {$$=carSpecial(VIR,2,$1,$3);};
couple: FLOAT VIR FLOAT {$$=carSpecial(VIR,2,$1,$3);};

%%

#define SIZEOF_NODETYPE ((char *)&p->fl - (char *)p)
nodeType *flot(int value) {
nodeType *p;
size_t nodeSize;
/* allocate node */
nodeSize = SIZEOF_NODETYPE + sizeof(floatNodeType);
if ((p = malloc(nodeSize)) == NULL)
yyerror("out of memory");
/* copy information */
p->type = tFloat;
p->fl.value = value;
return p;
}
nodeType *fonction(char* ft ) {
nodeType *p;
size_t nodeSize;
/* allocate node */
nodeSize = SIZEOF_NODETYPE + sizeof(fctNodeType);

if ((p = malloc(nodeSize)) == NULL)
yyerror("out of memory");
/* copy information */
p->type = tFunction;
strcpy(p->fct.fct, ft);
return p;
}
nodeType *carSpecial(int oper, int nops, ...) {
va_list ap;
nodeType *p;
size_t nodeSize;
int i;
/* allocate node */
nodeSize = SIZEOF_NODETYPE + sizeof(cpNodeType) +
(nops - 1) * sizeof(nodeType*);
if ((p = malloc(nodeSize)) == NULL)
yyerror("out of memory");
/* copy information */
p->type = tCaSpe;
p->cp.type = oper;
p->cp.nparam = nops;
va_start(ap, nops);
for (i = 0; i < nops; i++)
p->cp.parametres[i] = va_arg(ap, nodeType*);
va_end(ap);
return p;
}

void freeNode(nodeType *p) {
int i;
if (!p) return;
if (p->type == tCaSpe) {
for (i = 0; i < p->cp.nparam; i++)
freeNode(p->cp.parametres[i]);
}
free (p);
}
void yyerror(char *s) {
fprintf(stdout, "%s\n", s);
}
int main(void) {
yyparse();
return 0;
}


y'a t-il une solution SVP

1 réponse

mamiemando Messages postés 33778 Date d'inscription   Statut Modérateur Dernière intervention   7 884
 
Le type nodeType n'est pas défini ligne 24. Tu ne peux donc à ce stade que manipuler des nodeType * (car le compilateur sait qu'il doit réserver la taille pour une adresse) mais pas un nodeType (car il ne connaît pas encore la taille occupée par une structure nodeType).

Il faut donc déclarer au préalable la structure nodeType (éventuellement au travers d'un include si ce type est défini dans un autre fichier) ou continuer à utiliser des pointeurs.

Pour enlever ton warning, inclue <string.h>.

Bonne chance
0
Riadh
 
bonjour,
voici aussi le fichier arbre.h:


typedef enum { tFloat, tCaSpe, tFunction } nodeEnum;
/* float */
typedef struct {
int value; /* value of constant */
} floatNodeType;
/* caractères-spéciaux */
typedef struct {
int type; /* subscript to sym array */
int nparam;
struct nodeTypeTag * parametres[1];
} cpNodeType;
/* function */
typedef struct {
char* fct; /* operator */

} fctNodeType;

typedef struct nodeTypeTag {
nodeEnum type; /* type of node */
/* union must be last entry in nodeType */
/* because operNodeType may dynamically increase */
union {
floatNodeType fl; /* constants */
fctNodeType fct; /* identifiers */
cpNodeType cp; /* operators */
};
} nodeType;
extern int sym[26];


mais normalement j'ai fai un include mais j'ai tjrs la même erreur.
0