在为简单扫描仪编译 flex 和 bison 源时,我遇到以下错误:
$ gcc -o lab5 lab5.tab.c lex.yy.c -lfl
ld: library not found for -lfl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
lex源代码:
%{
#include <stdio.h>
#include <string.h>
#include "lab5.tab.h"
void showError();
%}
integer (\+?[1-9][0-9]*)
id ([a-zA-Z_][a-zA-Z0-9_]*)
%%
{id} {sscanf(yytext, "%s", yylval.name); return ID;}
{integer} {yylval.number = atoi(yytext); return INT;}
";" return SEMICOLON;
. {showError(); return OTHER;}
%%
void showError() {
printf("Other input");
}
Run Code Online (Sandbox Code Playgroud)
野牛源代码:
%{
#include <stdio.h>
int yylex(); …Run Code Online (Sandbox Code Playgroud)