0
我想编译下面的程序,但收到无法识别的规则错误。我有以下lex程序,它给我许多无法识别的行18,25,28,37,41,43,44,50,56,58,61的错误规则错误无法识别的规则lex中的错误
命令用于运行:$ lex lab.l
%{
#include <iostream>
#include <string>
using namespace std;
%}
%option noyywrap
%%
(\"(?:[^"]|\"\")*\")(,|\r\n?|\n)?
{
string temp = yytext;
while(temp.find("\"\"")!=string::npos){
temp.replace(temp.find("\"\""),2,""");
temp.replace(temp.find("\"\""),2,""");
}
temp.erase(0,1);
temp.erase(temp.find("\""), 1);
while(temp[temp.size() - 1] == '\n'){
temp.erase(temp.size() - 1,1);
}
while(temp.find("\n")!=string::npos)
temp.replace(temp.find("\n"),1,"<br>");
if(temp[temp.size() - 1] == ','){
temp.erase(temp.size() - 1,1);
cout << "<td>" << temp << "</td>";
}
else{
cout << "<td>" << temp << "</td>\n</tr>\n<tr>";
}
}
("(?:|"")*"|[^",\r\n]*),?
{
string temp = yytext;
if(temp[temp.size() - 1] == ','){
temp.erase(temp.size() - 1,1);
if(yyleng == 1)
temp = " ";
cout << "<td>" << temp << "</td>";
}
else{
if(yyleng > 1)
cout << "<td>" << temp << "</td>\n</tr>\n<tr>";
}
}
%%
int main(void)
{
cout << "<html>\n\t<body>\n\t\t<table border=3>\n<tr>";
yylex();
cout << "</tr>\n\t\t</table>\n\t</body>\n</html>";
return 0;
}