1
votes

Here is the relevant error:

grammar.y:72: error: conflicting declaration ‘typedef union YYSTYPE YYSTYPE’
y.tab.h:83: error: ‘YYSTYPE’ has a previous declaration as ‘typedef union YYSTYPE YYSTYPE’
make: *** [y.tab.o] Error 1

I am using flex and byacc together to produce a translator. My build has this structure:

  1. Make the y.tab.h from the grammar.y file.
  2. Include y.tab.h in the tokens.lex file, and compile that to produce lex.yy.c.
  3. Include lex.yy.c back in the grammar file. This way, we can see yylex.

What seems to be happening is this: The y.tab.h contains a the union declaration of the YYSTYPE union. This gets included by lex.yy.c, which gets included by grammar.y. But at the same time, grammar.y is producing its own version of the union, and the two clash.

Is this not the standard approach? Is there something I need to change to make it build correctly?

1

1 Answers

0
votes

Oops. Turns out that I wasn't compiling with bison. My other system had yacc symlinked to bison, so I had to change the makefile to use bison rather than yacc.