📄 vocabulary.cpp
字号:
// Vocabulary.cpp: implementation of the CVocabulary class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Scanner.h"
#include "Vocabulary.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVocabulary::CVocabulary()
{
CString c,s;
Vocabulary[0]="";
Vocabulary[1]="break";
Vocabulary[2]="case";
Vocabulary[3]="char";
Vocabulary[4]="class";
Vocabulary[5]="const";
Vocabulary[6]="default";
Vocabulary[7]="delete";
Vocabulary[8]="do";
Vocabulary[9]="double";
Vocabulary[10]="else";
Vocabulary[11]="float";
Vocabulary[12]="for";
Vocabulary[13]="friend";
Vocabulary[14]="if";
Vocabulary[15]="include";
Vocabulary[16]="int";
Vocabulary[17]="long";
Vocabulary[18]="new";
Vocabulary[19]="operator";
Vocabulary[20]="private";
Vocabulary[21]="protected";
Vocabulary[22]="public";
Vocabulary[23]="return";
Vocabulary[24]="short";
Vocabulary[25]="static";
Vocabulary[26]="struct";
Vocabulary[27]="switch";
Vocabulary[28]="template";
Vocabulary[29]="this";
Vocabulary[30]="try";
Vocabulary[31]="typedef";
Vocabulary[32]="undef";
Vocabulary[33]="unsigned";
Vocabulary[34]="using";
Vocabulary[35]="virtual";
Vocabulary[36]="void";
Vocabulary[37]="while";
Vocabulary[38]="wchart_t";
Vocabulary[39]="auto";
Vocabulary[40]="enum";
Vocabulary[41]="goto";
Vocabulary[42]="then";
Vocabulary[43]="union";
Vocabulary[44]="sizeof";
Vocabulary[45]="catch";
for(int x=1;x<45;x++) //排序
{
for(int y=x+1;y<46;y++)
{
if(Vocabulary[x]>Vocabulary[y])
{
c=Vocabulary[x];
Vocabulary[x]=Vocabulary[y];
Vocabulary[y]=c;
}
}
}
for (int i=46;i<=50;i++)
Vocabulary[i]="";
Vocabulary[51]="{";
Vocabulary[52]="}";
Vocabulary[53]="[";
Vocabulary[54]="]";
Vocabulary[55]="(";
Vocabulary[56]=")";
Vocabulary[57]=";";
Vocabulary[58]=",";
Vocabulary[59]=".";
Vocabulary[60]="!";
Vocabulary[61]=":";
Vocabulary[62]="&";
Vocabulary[63]="|";
Vocabulary[64]="+";
Vocabulary[65]="-";
Vocabulary[66]="*";
Vocabulary[67]="/";
Vocabulary[68]=">";
Vocabulary[69]="<";
Vocabulary[70]="%";
Vocabulary[71]="#";
Vocabulary[72]="_";
Vocabulary[73]="`";
Vocabulary[74]="~";
Vocabulary[75]="@";
Vocabulary[76]="^";
Vocabulary[77]="?";
Vocabulary[78]="$";
Vocabulary[79]="'";
Vocabulary[80]='"';
Vocabulary[81]="\\";
Vocabulary[82]="=";
Vocabulary[83]=9; // Tab Key : ASC(9)
Vocabulary[83]="";
Vocabulary[84]="";
Vocabulary[85]="\r";
Vocabulary[86]="\n";
Vocabulary[87]="//"; //注释符号
Vocabulary[88]="++";
Vocabulary[89]="--";
Vocabulary[90]="==";
Vocabulary[91]="+=";
Vocabulary[92]="-=";
Vocabulary[93]="*=";
Vocabulary[94]="<<";
Vocabulary[95]=">>";
for(int m=51;m<95;m++)
{
for(int n=m+1;n<96;n++)
{
if(Vocabulary[m]>Vocabulary[n])
{
s=Vocabulary[m];
Vocabulary[m]=Vocabulary[n];
Vocabulary[n]=s;
}
}
}
}
CVocabulary::~CVocabulary()
{
}
int CVocabulary::GetCode(CString cs) //判断cs是否是关键字,
//是则返回在vocabulary数组中的位置
{
int low = 0;
int high = 45;
int mid;
while( low <= high )
{
mid = ( low + high ) / 2;
if( cs == Vocabulary[mid] )
{
return mid;
}
else if( cs < Vocabulary[mid])
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
return -1;
}
CVocabulary::FindSymbol(CString s ) //查找并判断s是否是字符,是则返回在vocabulary数组中的位置
{
int low =50;
int high=95;
int mid;
while( low <= high )
{
mid = ( low + high ) / 2;
if(s ==Vocabulary[mid] )
{
return mid;
}
else if(s < Vocabulary[mid] )
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -