I have the following files:
CP.h
#ifndef CP_H_
#define CP_H_
class CP {
public:
enum Cardinalite {VIDE = '\0', PTINT = '?', AST = '*', PLUS = '+'};
CP(Cardinalite myCard);
virtual ~CP();
private:
Cardinalite card;
};
#endif /* CP_H_ */
And dtd.y
%{
using namespace std;
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include "AnalyseurDTD/DtdDocument.h"
#include "AnalyseurDTD/CP.h"
void yyerror(char *msg);
int yywrap(void);
int yylex(void);
DtdDocument * doc = new DtdDocument();
%}
%union {
char *s;
DtdElement * dtdelt;
CP *cpt;
CP::Cardinalite card;
}
And the following strange error:
AnalyseurDTD/dtd.y:20:2: error: ‘CP’ does not name a type
AnalyseurDTD/dtd.y:21:2: error: ‘CP’ does not name a type
The stange thing is that if I put CP *cpt; after DtdDocument * doc = new DtdDocument(); I have no error :/
Include the header in your scanner file before you include *.tab.h
// scanner.l file
%{
#include "myheader.h"
#include "yacc.tab.h"
// other C/C++ code
%}
// helper definitions
%%
// scanner rules
%%
%union
is defined in yacc.tab.h
so when you compile you need to make sure the compiler sees your new type definitions before it process yacc.tab.h
Recently I am working with flex and bison. There are several advises that may be helpful for you to locate the problem:
*.tab.h
). Find the definition of YYSTYPE
. There is a high probability that it doesn't include your header file AnalyseurDTD/CP.h
.AnalyseurDTD/CP.h
before you include the *.tab.h
. Add it wherever needed to make sure the class CP
is defined before YYSTYPE
.void *cpt;
in the union, then add type conversion in the rest of your code.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With