我是flex和bison的新手
我编译代码时请帮忙‘yylex’ was not declared in this scope
这是我的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();
}
和我的sample.y文件是:
%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"
我使用flex -+ sample.l
编译.l文件,使用bison -L c++ sample.y
编译.y文件,当我运行g++ sample.tab.cc
时出现错误
我尝试int yylex();
和void yyerror(char const*);
进行修复,但我收到了另一个错误error: too many arguments to function ‘int yylex()
请帮帮我