C++ g++;flex和bison‘;yylex’;未在此范围中声明
我是flex和bison的新手。C++ g++;flex和bison‘;yylex’;未在此范围中声明,c++,bison,flex-lexer,C++,Bison,Flex Lexer,我是flex和bison的新手。 当我编译我得到的代码时,请提供帮助。'yylex'未在此范围内声明 这是我的sample.ll文件: %{ #include <iostream> using namespace std; %} %% [ \t\n] /*do nothing*/ ("//")(.)* { cout << "comments" << endl; } "(" { cout << "start
当我编译我得到的代码时,请提供帮助。
'yylex'未在此范围内声明
这是我的sample.ll文件:
%{
#include <iostream>
using namespace std;
%}
%%
[ \t\n] /*do nothing*/
("//")(.)* { cout << "comments" << endl; }
"(" { cout << "start (" << endl; }
")" { cout << "end )" << endl; }
"+" { cout << "+ detected" << endl; }
"-" { cout << "- detected" << endl; }
"/" { cout << "/ detected" << endl; }
"*" { cout << "* detected" << endl; }
"=" { cout << "= detected" << endl; }
"==" { cout << "==" << endl; }
"<" { cout << "<" << endl; }
"<=" { cout << "<=" << endl; }
">" { cout << ">" << endl; }
">=" { cout << ">=" << endl; }
"!=" { cout << "!=" << endl; }
("\"")([a-zA-Z0-0\ ]*)("\"") { cout << "string : " << yytext << endl; }
[0-9]+ { cout << "int = " << yytext << endl; }
([0-9]+)(".")([0-9]+) { cout << "double = " << yytext << endl; }
[a-zA-Z][a-zA-Z0-9]* { cout << "a varible or error : " << yytext << endl; }
"." { cout << ". detected" << endl; }
. { cout << "unknown : " << yytext << endl; }
%%
int main(int argc, char** argv) {
// lex through the input:
yylex();
}
%{
#包括
使用名称空间std;
%}
%%
[\t\n]/*什么也不做*/
(“//”)(.*)*cOUT如果您想使用C++模板,则需要使用完全不同的接口。这些在手册和手册中进行了描述,您的第一步将是阅读并相应地修改代码。
如果你只想使用C++(因为,显然,你更容易编写<代码> cOUT> p>。如果你想使用C++模板,你需要使用完全不同的接口。这些都在手册和手册中描述,你的第一步就是阅读并相应地修改你的代码。
<如果你只想使用C++(因为,显然,编写更为舒适,你不能后退几步,首先学习如何使用多个源文件构建项目。解决方案不是#将
源文件包含在彼此中。使用头文件、对象文件和链接。也许可以学习使用生成
,以及一种自动化构建的方法。)丁。后退几步,首先学习如何使用多个源文件构建项目。解决方案不是将源文件包含在彼此中。使用头文件、对象文件和链接。也许可以学习使用生成,以及一种自动化构建的方法。
%start init
%token NUMBER
%{
#include <iostream>
using namespace std;
%}
%%
init : exp
;
exp : term
| exp '+' term { cout << "+"; }
| exp '-' term { cout << "-"; }
;
term : factor
| term '*' factor { cout << "*"; }
| term '/' factor { cout << "/"; }
;
factor : NUMBER { cout << $1; }
| '('exp')'
;
%%
#include "lex.yy.cc"