I have searched almost every material online. But I am still confused why lexer cannot identify yylval.
Here is the case:
I have defined a bunch of ADT in node.h
and realize them in node.c
, my purpose is to generate a AST after these structures are properly stored. But I am stucked with bison file.
First, I change %union
to union YYSTYPE {...};
and typedef union YYSTYPE YYSTYPE;
, I don't why I need to do this, some other files posted online seems to work well with %uinion
.
Then, I am stucked with yylval
things. I have done bison -d
things, and checked it already in parser.c
(I have specified the bison output), so I think extern YYSTYPE yylval;
should work. But it doesn't. So I wonder if there is another way to solve yylval undeclared problem.
I only use the two types of YYSTYPE
struct, int
and char *
, can I separate the union YYSYTPE
and struct for the AST? This means, the nonterminals will have no associated types. Do you guys have any other ideas??
YYSTYPE
and struct for the AST", and I don't think it necessary. Have you got problems when using%union
and%type
in bison? – Viscid%union
and%union YYSTYPE
works in the same way, however, in my case, I have to choose the latter. I don't know why? For%union
and%type
, I know the relationship between them. I just know how to solve the error withYYSTYPE undefined
. When I searched online, I found it a common problem. – Mozart