LEX 可能出现问题 yyterminate 不确定是否有帮助!
你好,我的 lex 解析器有问题。当我发现错误而使用 yyterminate 退出时,它将显示错误,正如您可以在最底部看到的那样。但是当我输入一个新的 URI 时,它仍然认为代码中有错误。似乎标准输入没有被清除,因为它不断出现相同的错误。显然,代码混乱,在这里发布的内容太多,但我认为问题出在 main 或 yyterminate 上。任何帮助将不胜感激。
main( int argc, char * argv[] ){
char temp[10];
int q;
while(1)
{
YY_FLUSH_BUFFER;
yyrestart(stdin);
printf("\nPlease enter your URI: ");
yyin = stdin;
q= yylex();
if(errorFlag !=1)
{
if(validScheme==1)
R.protocol = "HTCPCP/1.0";
R.content = "message/coffee-pot";
if((helpFlag==1)||(helpFlag==2))
{
propfind();
theServer();
}
}
}
}
........
这是主要的地方,我应该能够循环询问 URI,然后转到函数,然后返回以询问另一个 uri,只要存在,这就可以正常工作没有错误。 ........
<sep_state>. {printf("error in sep state");errorFlag=1; yyterminate(); }
<pot_value>[^0-2] { printf("Pot Value error"); errorFlag=1; yyterminate(); }
<pot_state>. { printf("pot state error");errorFlag=1; yyterminate();}
<sep_state>. { printf("couldnt recognise host");errorFlag=1; yyterminate();}
这是我正在做一些错误检查的地方。如果没有一个值匹配,我希望它出错,因此它匹配所有输入(我认为)。 ......
Please enter your URI: coffee://128.0.111.11111/pot-0?
Host not recognised. Use 127.0.0.1/
Please enter your URI: coffee://127.0.0.1/pot-0?
Host not recognised. Use 127.0.0.1/
这是标准输出的输出。我想输入一个 uri 解析它发送它。当我收到错误时,我想报告错误并使用新的 URI 重新开始,一旦收到错误,即使我在其中输入正确的 URI,它也会保留该错误,但仍然收到错误。希望这一切都有道理。并希望得到任何帮助。干杯
hi im having problems with my lex parser. When i use yyterminate to exit as i found an error, it will display the error fine as you can see down the very bottom. But when i go to enter in a new URI it still thinks there is an error in the code. seems like stdin isnt been cleared as it keeps getting the same error. obviously there is code messing, way to much to post in here but this is where i think the problem is with main or yyterminate. any help would be appreciated.
main( int argc, char * argv[] ){
char temp[10];
int q;
while(1)
{
YY_FLUSH_BUFFER;
yyrestart(stdin);
printf("\nPlease enter your URI: ");
yyin = stdin;
q= yylex();
if(errorFlag !=1)
{
if(validScheme==1)
R.protocol = "HTCPCP/1.0";
R.content = "message/coffee-pot";
if((helpFlag==1)||(helpFlag==2))
{
propfind();
theServer();
}
}
}
}
........
here is the main where i should be able to loop around asking for a URI and then go to functions and then return to ask for another uri, this works fine as long as there is no error.
........
<sep_state>. {printf("error in sep state");errorFlag=1; yyterminate(); }
<pot_value>[^0-2] { printf("Pot Value error"); errorFlag=1; yyterminate(); }
<pot_state>. { printf("pot state error");errorFlag=1; yyterminate();}
<sep_state>. { printf("couldnt recognise host");errorFlag=1; yyterminate();}
this is where i am doing some error checking. if none of the values have been matched i want it to error hence it matching all input(i think).
.......
Please enter your URI: coffee://128.0.111.11111/pot-0?
Host not recognised. Use 127.0.0.1/
Please enter your URI: coffee://127.0.0.1/pot-0?
Host not recognised. Use 127.0.0.1/
this is the output to stdout. I want to input a uri parse it send it. when i get an error i want to report the error and start again with a new URI yet, once it gets an error it holds the error even when i type a correct URI in i still get the error. Hope this all makes sense. and would appreciate any help.Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经设法克服了这个问题,我没有重置缓冲区,所以 ij 使用 yyrestart(stdin) 这阻止了它用相同的错误填充屏幕,并让它识别新的 uri,我需要重置状态,所以所有现在正在工作。感谢您的帮助。
i have managed to overcome the problem, i wasnt resetting the buffer so i j used yyrestart(stdin) this stopped it filling up the screen with the same error, and to get it to recognise a new uri i needed to reset the state, so all is working now. Thanks for the help.