📄 matchkeywords.h
字号:
/*=============================================
** 2005-8-22 **
** 匹配关键字 **
** lizhu zhang **
=============================================*/
#include <string.h>
#include "biaoshifu.h"
#include "integer.h"
#include "realint.h"
#include "RealCharInt.h"
#include "JieXianFu.h"
//关键字数组
char keyWords[][15]={"and","array","begain","bool","call","case","char","constant","do",
"else","end","false","for","if","input","integer","not","of","or",
"output","procedure","program","read","real","repeat","set","then",
"to","true","until","var","while","write"};
/*============================================
**参数说明:
** [in]pword :输入要查找的信息
** [out]pErrMsg:返回出错信息
** [out]col :返回出错列
**返回值:如果找到,返回种别码,否则返回出错列值+61
===============================================*/
int FFindKind(const char *pWord,char *pErrMsg,int &col)
{
//接受函数返回值,然后根据其判断函数操作状况.
int rW =0;
//返回值临时变量
int kind=0;
int i=0;
//将大写字母变成小小写字母
char word[2048];
strcpy(word,pWord);
strcpy(word,strlwr(word));
//识别关键字
for(;i<=32;i++)
{
if(strcmp(word,&keyWords[i][0])==0)
{
kind = i+1;
return kind;
}
}
//识别界限符
kind = FJieXianFu(word);
//找到则返回种别码,否则继续以下的匹配
if(kind != 0)
return kind;
//=================================
//识别标识符
kind = FBiaoShiFu(word);
if(kind != -1)
return kind;
//=================================
//识别整常数
rW = FInt(word);
if(rW == 0)
{
kind = 35;
//成功
return kind;
}
else
if(rW == 1)
{
//其他
;
}
else
{
//错误的整常数,可能为实常数
//===================================
//识别实常数
rW = FRealInt(word);
//识别成功
if(rW == 0)
{
kind = 36;
return kind;
}
else
{
strcpy(pErrMsg,word);
strcat(pErrMsg," 错误!");
return rW+61;
}
}
//===================================
//识别实符常数
rW = FRealCharInt(word);
if(rW == 0 )
{
kind = 37;
return kind;
}
else
if(rW == -1)
return rW;
else
{
strcpy(pErrMsg,"“ ");
strcat(pErrMsg,word);
strcat(pErrMsg," ” 错误!");
return rW+61;
}
cout<<"Test FRealCharInt pos:"<<kind<<endl;
//===================================
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -