0

I have a school project, building a compiler. There is a header file given by the course staff, "proj.h" including a struct "Node", which should be used to build the parsing tree, and a set of functions. (That header does not include a #define for YYSTYPE to the Node type, and shouldn't be changed). I would like to use Node* in my .lex file, such as:

yylval = makeNode(...);

definition of makeNode:

Node *makeNode(const char* type,const char* value, Node *child);

I have tried defining the YYSTYPE both in .lex file and .ypp.

.lex:

#include "proj.h"
#include "parser.tab.hpp"
#define YYSTYPE Node*

.ypp:

#include "proj.h"
#define YYSTYPE Node*

I'm compiling using g++. It seems that the lval doesn't get the actual defintion as Node* as it should. There is a compilation error when trying to assign lval:

Invalid conversion from 'Node* {aka n*}' to 'YYSTYPE {aka int}'

Any help appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • That sounds like you don't `#define YYSTYPE` early enough. Could you be a bit clearer where the lines you quote appear in the files? Did you use `-Wall` in your g++ command? What other errors/warnings were produced? (I'd definitely put the define before including the bison header file.) – rici Jan 01 '17 at 11:44
  • I have tried that too, defining YYSTYPE before including the .tab.cpp. When doing so, it seems that the tab.cpp file does not include the proj header, since I get "undifined reference to 'makeNode'". the compilation command is: `g++ parser.tab.cpp lex.yy.c` – user7362181 Jan 01 '17 at 11:58
  • And where is makeNode *defined*? That error doesn't say it is undeclared, so there is no evidence that the header file is being skipped (which could not happen without an error message, anyway.) – rici Jan 01 '17 at 15:25
  • Actually, it was a linkage error, compiling proj.c as well solved the problem. Thanks! – user7362181 Jan 01 '17 at 21:20

0 Answers0