I’m working on a simple parser using Yacc and Lex. When trying to compile, I get the following errors:
<code>parcial1.l:10:10: error: use of undeclared identifier 'DELETE'
parcial1.l:11:10: error: no member named 'num' in 'union YYSTYPE'
parcial1.l:11:37: error: use of undeclared identifier 'NUMBER'
</code>
<code>parcial1.l:10:10: error: use of undeclared identifier 'DELETE'
parcial1.l:11:10: error: no member named 'num' in 'union YYSTYPE'
parcial1.l:11:37: error: use of undeclared identifier 'NUMBER'
</code>
parcial1.l:10:10: error: use of undeclared identifier 'DELETE'
parcial1.l:11:10: error: no member named 'num' in 'union YYSTYPE'
parcial1.l:11:37: error: use of undeclared identifier 'NUMBER'
here’s the relevant parts from the lex file:
<code>%%
"add" { return ADD; }
"list" { return LIST; }
"delete" { return DELETE; }
[0-9]+ { yylval.num = atoi(yytext); return NUMBER; }
"[^"]+" { yylval.str = strdup(yytext); return STRING; }
[ tn]+ { /* Ignore whitespace */ }
%%
</code>
<code>%%
"add" { return ADD; }
"list" { return LIST; }
"delete" { return DELETE; }
[0-9]+ { yylval.num = atoi(yytext); return NUMBER; }
"[^"]+" { yylval.str = strdup(yytext); return STRING; }
[ tn]+ { /* Ignore whitespace */ }
%%
</code>
%%
"add" { return ADD; }
"list" { return LIST; }
"delete" { return DELETE; }
[0-9]+ { yylval.num = atoi(yytext); return NUMBER; }
"[^"]+" { yylval.str = strdup(yytext); return STRING; }
[ tn]+ { /* Ignore whitespace */ }
%%
And from the yacc file:
<code>%union {
int num;
char* str;
}
%token ADD
%token LIST
%token DELETE
%token <str> STRING
%token <num> NUMBER
</code>
<code>%union {
int num;
char* str;
}
%token ADD
%token LIST
%token DELETE
%token <str> STRING
%token <num> NUMBER
</code>
%union {
int num;
char* str;
}
%token ADD
%token LIST
%token DELETE
%token <str> STRING
%token <num> NUMBER
I believe identifiers and members have been properly declared so I cannot find why this error is showing.
Running in Mac M1 Sonoma 14.6.1
bison (GNU Bison) 2.3
flex 2.6.4 Apple(flex-34)
2