为什么 ubuntu 在 运行 lex 程序时显示错误
why ubuntu showing error while running lex program
我正在尝试 运行 UBUNTU 中带有 .l
文件扩展名的词法程序,我已经安装了 flex 和 bison,并且能够获得 lex.yy.c文件,但是当我给出命令 cc lex.yy.c -lfd
或 cc lex.yy.c
时,终端显示错误:
first.l:2:10: fatal error: iostream: No such file or directory
#include <iostream>
^~~~~~~~~~
我的代码是:
%{
#include <iostream>
using namespace std;
#define YY_DECL extern "C" int yylex()
%}
%%
[ \t\n] ;
[0-9]+\.[0-9]+ { cout << "Found a floating-point number:" << yytext << endl; }
[0-9]+ { cout << "Found an integer:" << yytext << endl; }
[a-zA-Z0-9]+ { cout << "Found a string: " << yytext << endl; }
%%
int main(int, char**) {
// lex through the input:
yylex();
}
我重新安装了 flex 和 bison ans,还卸载并安装了 gcc,但没有任何变化!任何帮助将不胜感激,
您正在尝试使用 C 编译器编译 C++ 代码。请改用 g++
。
这里是 运行 的正确代码:
%%
[0-9]+\.[0-9]* { printf("Found a floating-point number:"); }
[0-9]* { printf("Found an integer:"); }
[a-zA-Z0-9]* { printf("Found a string: "); }
%%
main(int argc, char** argv)
{
yylex();
}
我正在尝试 运行 UBUNTU 中带有 .l
文件扩展名的词法程序,我已经安装了 flex 和 bison,并且能够获得 lex.yy.c文件,但是当我给出命令 cc lex.yy.c -lfd
或 cc lex.yy.c
时,终端显示错误:
first.l:2:10: fatal error: iostream: No such file or directory
#include <iostream>
^~~~~~~~~~
我的代码是:
%{
#include <iostream>
using namespace std;
#define YY_DECL extern "C" int yylex()
%}
%%
[ \t\n] ;
[0-9]+\.[0-9]+ { cout << "Found a floating-point number:" << yytext << endl; }
[0-9]+ { cout << "Found an integer:" << yytext << endl; }
[a-zA-Z0-9]+ { cout << "Found a string: " << yytext << endl; }
%%
int main(int, char**) {
// lex through the input:
yylex();
}
我重新安装了 flex 和 bison ans,还卸载并安装了 gcc,但没有任何变化!任何帮助将不胜感激,
您正在尝试使用 C 编译器编译 C++ 代码。请改用 g++
。
这里是 运行 的正确代码:
%%
[0-9]+\.[0-9]* { printf("Found a floating-point number:"); }
[0-9]* { printf("Found an integer:"); }
[a-zA-Z0-9]* { printf("Found a string: "); }
%%
main(int argc, char** argv)
{
yylex();
}