【发布时间】:2011-02-06 12:49:03
【问题描述】:
有一些类似的 C 代码:
int doCommand(char* command)
{
// +2 on strlen is for the two extra '\0' characters
// needed by flex when scanning strings.
YY_BUFFER_STATE yybs = yy_scan_buffer(command, strlen(command)+2);
yy_switch_to_buffer(yybs);
yyparse();
yy_delete_buffer(yybs);
}
它在类似(伪代码)的循环中被调用:
read characters upto and including '\n' into a buffer;
add two '\0' characters;
call doCommand(buffer);
zero the buffer; // NOTE: same buffer will be used next loop.
问题是在成功处理第一个命令后,输入的任何其他命令都不会得到处理。
我已经打印出 yylineno(当 flex 扫描仪看到 '\n' 时它会增加)并且它只增加一次,在第一个命令之后。
我无法确定是我在使用 flex 时做错了什么,还是 yyparse 在第一次运行后停止调用扫描仪。
如果有人能准确指出正在发生的事情,我会非常高兴。
【问题讨论】: