[求助]lex and yacc(2) 例子ch2-03运行不了
新手,从网上down下来lex and yacc second 第二版例子ch2-03,无法运行多文件单词计数程序。我是在redhat 9中试的,有没有哪位碰到过,谢谢 我想你在问问题的时候,最好应该把代码附上.
然后给出你运行的例子,包括你是如何编译的.
像这样
$ echo Hello,world!
Hello,world!
谢谢提醒,我考虑代码比较长一点,就没有贴上来
经过调试,确定是作者的代码有误
yywrap()
{
FILE *file;此处没有初始化为null,导致后面一直返回0,死循环了
if ((currentFile != 0) && (nFiles > 1) && (currentFile < nFiles)) {
/*
* we print out the statistics for the previous file.
*/
printf("%8lu %8lu %8lu %s\n", lineCount, wordCount,
charCount, fileList);
totalCC += charCount;
totalWC += wordCount;
totalLC += lineCount;
charCount = wordCount = lineCount = 0;
fclose(yyin); /* done with that file */
}
while (fileList != (char *)0) {
file = fopen(fileList, "r");
if (file != NULL) {
yyin = file;
break;
}
fprintf(stderr,
"could not open %s\n",
fileList);
}
return (file ? 0 : 1);/* 0 means there's more input */
页:
[1]