cod*_*erx 6 compiler-construction lex
我正在尝试使此示例代码正常工作,但我不断收到错误:fatal error: 'y.tab.h' file not found #include "y.tab.h" 。我该怎么办?
%{
#include <stdlib.h>
void yyerror(char *);
#include "y.tab.h"
%}
%% [0-9]+ {
yylval = atoi(yytext);
return INTEGER;
}
[-+\n] return *yytext;
[ \t] ; /* skip whitespace */
. yyerror("invalid character");
%%
int yywrap(void) {
return 1;
}
Run Code Online (Sandbox Code Playgroud)
当您使用 -dy 运行 bison 时,会生成包含在 flex 文件中的“y.tab.h”文件。例子:
flex mylex.l
bison -dy myparser.y
Run Code Online (Sandbox Code Playgroud)
那么你应该将它们编译在一起:
gcc lex.yy.c myparser.tab.c -o mycompiler.exe
Run Code Online (Sandbox Code Playgroud)