finderror.h
来自「一个简单的词法分析程序。是编译原理的部分课程设计。因为时间有限。未能完成全部。如」· C头文件 代码 · 共 104 行
H
104 行
/*=============================================
** 2005-8-31 **
** **
** lizhu zhang **
=============================================*/
/*============================================
**参数说明:
** [in]pFile :源文件的文件名
** [in]tokenCount :token字的计数
** [in]row,col :行列计数
** [in]end :结束标志1:本行缺少结束标志
**返回值:如果找到,返回种别码,否则返回出错列值+61
===============================================*/
void FFindError(const char *pFile,const int tokenCount,int &tRow,int &tCol,const int end)
{
int count = tokenCount;
//种别码
int kind;
//定义一个单词记录数组
char newWord[2048];
//列的临时计数,也作为注释行返回的接受者
int tempCol;
//行列计数
int row(1),col(0);
//错误信息结构
PErrMsg pErrMsg;
//分配空间
pErrMsg = (struct ERRMSG*)malloc(sizeof(ERRMSG));
//错误信息缓冲区
char errMsg[1024];
//错误标识
int err = 0;
//字符串缓冲区
char word[2048];
//源文件结束标志:1,文件未结束;0,文件结束
int flagSoceEnd(1);
//从源文件中读取一行数据
err = FFileRead(pFile,word,row,flagSoceEnd);
while(err&&flagSoceEnd && count != 0)
{
//对行进行处理,看是否为注释行
tempCol = FHandleCom(word,errMsg);
if(tempCol == -1)
{
//是注释行,不进行任何操作
goto CONTINUE;
} //不是注释行
else
if(tempCol == 0)
{
do
{
//存放检测值是否存在的函数的返回值的临时变量
// int testWordExist;
//获得一个单词,并的到列计数
FGetWord(word,col,newWord);
//对单词进行识别
kind = FFindKind(newWord,errMsg,tempCol);
if(count != 0)
{
count -= 1;
col +=1;
continue;
}
else
if(count == 0)
break;
}while(col<=(int)strlen(word));
}
if(count != 0 && !end)
{
count -= 1;
}
else
break;
/*if(count == 1 && end)
break;
else
{
count -= 1;
}*/
CONTINUE://对列初始化
col = 0;
//行计数加1
row++;
//获得新的一行
err = FFileRead(pFile,word,row,flagSoceEnd);
}
tRow = row + 1;
tCol = col;
if(count == 0)
{
pErrMsg->row = row;
pErrMsg->col = col;
strcpy(pErrMsg->pErrMsg,"");
strcat(pErrMsg->pErrMsg,"'");
strcat(pErrMsg->pErrMsg,newWord);
strcat(pErrMsg->pErrMsg," '错误!");
//如果写入错误信息失败则退出整个分析过程
if(!FFileWrite("Error.txt",2,pErrMsg))
return ;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?