mtk358
mtk358

Reputation: 565

'YYSTYPE' has no member

In my YACC file, I have this:

%union {
    Node *node;
    FuncParamList *fParam;
    CallParamList *cParam;
    char *str;
    struct {
        char *name;
        Node *node;
    } nameNodePair;
}

This is my Lex file (note that it includes the header file generated by YACC):

%{
    #include "yacc_parser.hh"
%}

%%

if              return IF;
ei              return ELSEIF;
else            return ELSE;
endif           return ENDIF;
while           return WHILE;
loop            return LOOP;
func            return FUNC;
end             return END;

:=              return ASSIGN;
\.              return DOT;
,               return COMMA;
:               return COLON;
\(              return OPAREN;
\)              return CPAREN;

(\n|\r\n?)      { /* increment line count */ return LF; }
;               return LF;

[!?A-Za-z][!?A-Za-z0-9]         { yylval.str = yytext; return NAME; }
[0-9]+                          { yylval.str = yytext; return INTEGER; }

%%

But I get this error when I compile:

/home/michael/Projects/lang/lib/lex_lexer.l:26:9: error: ‘YYSTYPE’ has no member named ‘str’
/home/michael/Projects/lang/lib/lex_lexer.l:27:9: error: ‘YYSTYPE’ has no member named ‘str’

I made sure that the YACC header file contains the YYSTYPE definition, and the Lex output file does include it before it uses YYSTYPE. What should I do?

Upvotes: 0

Views: 4408

Answers (1)

M'vy
M'vy

Reputation: 5774

[should be a comment, but I need spacing and blanks to be readable. Will edit to make it real solution when all will be clarify]

Edit1: new conf So let's clarify a bit the file you shall have :

C++ code style / yacc_parser.yy : containing the %union

C++ code style / yacc_parser.hh and yacc_parser.cc : generated by the yacc yacc_parser.yy command

C code style / lex_lexer.l : includes yacc_parser.h

C code style / lex_lexer.c : generated by lex lex_lexer.l command

Then you compile&link : gcc -Wall lex_lexer.c yacc_parser.cc that should produce the executable file.

Since you mix C and C++ code, I almost sure you need to use a extern "C" { ... } somewhere to link your union as a C type not C++. That may explain why you c code can't find the struct member.

Maybe

%union {
    extern "C" {
    ...teh code...
    }
}

for my information, why have you a mix of C and C++? why not only one language?

Upvotes: 1

Related Questions