📄 wordanalyse.cpp
字号:
}
}
else{
this->m_pPtWd.pFst_word=this->m_ptStr;//字头指针
this->m_pPtWd.piFst_word=this->m_piPointer;
}
//TRACE("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%: %s\n",this->m_ptStr);
// this->m_pPtWd.pFst_word=this->m_ptStr;//字头指针
// this->m_pPtWd.piFst_word=this->m_piPointer;//字头指针
VERIFY(this->m_pPtWd.pFst_word!=NULL);
if(*this->m_pPtWd.pFst_word!='\000'){
// TRACE("this->m_pPtWd.pFst_word从某字头起,后续字符串为 :%s\n",this->m_pPtWd.pFst_word);
// TRACE("--------------:%d\n",m_pPtWd.piFst_word);
// TRACE("this->m_pPtWd.piFst_word从某字头起,后续字符串为:%c\n",m_sBuffRes.GetAt(m_pPtWd.piFst_word));
}
else{
// TRACE("下一个字符为文件尾");
}
//识别变量名或基本字-------------------------------------------------------------------------
if(this->IsLetterOrChinese()){//字母或汉字
while(IsLetterOrChinese()||IsDigit()){//字母或数字
this->Concat();
isNotEnd=this->GetChar();
}
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
WType=this->Reserve();
// TRACE("种别码:%d\n",WType);
if(WType==$NOTBASEWORD){//一般变量
TDim.WdTp=$SIGN;
TDim.WordToTDSoS(this->m_sWord);
}
else{//基本字
TDim.WdTp=WType;
}
return TDim;
}
//识别实常数----------------------------------------------------------------------------
if(this->m_sChar=='.'){
this->Concat();
isNotEnd=this->GetChar();
if(this->IsDigit()){
while(this->IsDigit()){
this->Concat();
isNotEnd=this->GetChar();
}
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$FCONST;
TDim.WdVlue.dbconst=atof(this->m_sWord);
return TDim;
}
else{
if(isNotEnd){
this->Retract();
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DOT;//.
return TDim;
}
}
//整常数或实常数--------------------------------------------------------------------------
if(this->IsDigit()){
while(this->IsDigit()){
this->Concat();
isNotEnd=this->GetChar();// TRACE("this->m_sChar中的字符为%d",&this->m_sChar);
}
if(this->m_sChar=='.'){//实常数
this->Concat();//goto 4;
this->GetChar();
if(this->IsDigit()){
while(this->IsDigit()){
this->Concat();
isNotEnd=this->GetChar();
}
}
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$FCONST;
TDim.WdVlue.dbconst=atof(this->m_sWord);
return TDim;
}
else{//整常数
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
//是否在范围之内?
// TRACE("识别出的整常数字符串为:%s\n",this->m_sWord);
if(!this->IntIsInRange(this->m_sWord)){
MessageBox(NULL,"您所输入整数超出正常范围\r最大值:2147483647!","警告",MB_OK|MB_ICONASTERISK);
if(m_pctrEdit)
{
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_pPtWd.piLst_word+1);
this->m_pctrEdit->SetFocus();
}
TDim.WdTp=$ILLEGALWORD;
return TDim;
}
TDim.WdTp=$ICONST;
TDim.WdVlue.intconst=atoi(this->m_sWord);
return TDim;
}
}
//字符串常数------------------------------------------------------------------------------
if(this->m_sChar=='\"'){
if(!this->GetChar()){
MessageBox(NULL,"字符串常量漏了一个\"","",MB_OK|MB_ICONHAND);
if(m_pctrEdit)
{
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_piPointer-1);//??
this->m_pctrEdit->SetFocus();
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$ILLEGALWORD;
return TDim;
}
while(this->m_sChar!='\"'/*&&*this->m_ptStr!='\000'*/){
this->Concat();
isNotEnd=this->GetChar();
if(!isNotEnd){
MessageBox(NULL,"字符串常量漏了一个\"","",MB_OK|MB_ICONHAND);
if(m_pctrEdit)
{
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_piPointer-1);//??
this->m_pctrEdit->SetFocus();
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$ILLEGALWORD;
return TDim;
}
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$SCONST;
TDim.WordToTDSoS(this->m_sWord);//TRACE("识别的字符串常量为:%s\n",this->m_sWord);
return TDim;
}
//识别*------------------------------------------------------------------------------------------
if(this->m_sChar=='*'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$STAR;
return TDim;
}
//识别/-----------------------------------------------------------------------------------
if(this->m_sChar=='/'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DIVIDE;
return TDim;
}
//识别&&----------------------------------------------------------------------------------
if(this->m_sChar=='&'){
isNotEnd=this->GetChar();
if(this->m_sChar=='&'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DAND;
}
else{
TDim.WdTp=$ILLEGALWORD;//若仅为&,当非法字符处理
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
MessageBox(NULL,"非法字符","错误",MB_OK|MB_ICONHAND);
if(m_pctrEdit)
{
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_pPtWd.piLst_word);
this->m_pctrEdit->SetFocus();
}
}
return TDim;
}
//识别||----------------------------------------------------------------------------------
if(this->m_sChar=='|'){
isNotEnd=this->GetChar();
if(this->m_sChar=='|'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DOR;
}
else{
TDim.WdTp=$ILLEGALWORD;//若仅为|,当非法字符处理
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
MessageBox(NULL,"非法字符","错误",MB_OK|MB_ICONHAND);
if(m_pctrEdit)
{
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_pPtWd.piLst_word);
this->m_pctrEdit->SetFocus();
}
}
return TDim;
}
//识别=或==-------------------------------------------------------------------------------
if(this->m_sChar=='='){
isNotEnd=this->GetChar();
if(this->m_sChar=='='){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DEQ;
}
else{
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$EQU;
}
return TDim;
}
//识别!或!=-------------------------------------------------------------------------------
if(this->m_sChar=='!'){
isNotEnd=this->GetChar();
if(this->m_sChar=='='){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$NEQ;
}
else{
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$NOT;
}
return TDim;
}
//识别<或<=-------------------------------------------------------------------------------
if(this->m_sChar=='<'){
isNotEnd=this->GetChar();
if(this->m_sChar=='='){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LOEQ;
}
else{
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LOW;
}
return TDim;
}
//识别>或>=-------------------------------------------------------------------------------
if(this->m_sChar=='>'){
isNotEnd=this->GetChar();
if(this->m_sChar=='='){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LAEQ;
}
else{
if(isNotEnd){//没有到达文件尾
this->Retract();//后退一个“单元字符”
}
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LARGE;
}
return TDim;
}
//识别,-----------------------------------------------------------------------------------
if(this->m_sChar==','){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$COMMA;
return TDim;
}
//识别;-----------------------------------------------------------------------------------
if(this->m_sChar==';'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$DOTCO;
return TDim;
}
//识别(-----------------------------------------------------------------------------------
if(this->m_sChar=='('){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LPAR;
return TDim;
}
//识别)-----------------------------------------------------------------------------------
if(this->m_sChar==')'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$RPAR;
return TDim;
}
//识别{-----------------------------------------------------------------------------------
if(this->m_sChar=='{'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$LBP;
return TDim;
}
//识别}-----------------------------------------------------------------------------------
if(this->m_sChar=='}'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$RBP;
return TDim;
}
//识别+ ----------------------------------------------------------------------------------
if(this->m_sChar=='+'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$PLUS;
return TDim;
}
//识别- ----------------------------------------------------------------------------------
if(this->m_sChar=='-'){
this->m_pPtWd.pLst_word=CharPrev(this->m_sBuffRes.GetBuffer(0),this->m_ptStr);//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$MINUS;
return TDim;
}
//文件尾或非法字符----------------------------------------------------------------------------------------
if(!isNotEnd){
this->m_pPtWd.pLst_word=this->m_ptStr;//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer;//字尾指针
TDim.WdTp=$ENDOFFILE;
return TDim;
}
this->m_pPtWd.pLst_word=this->m_ptStr;//字尾指针
this->m_pPtWd.piLst_word=this->m_piPointer-1;//字尾指针
TDim.WdTp=$ILLEGALWORD;
/* MessageBox(NULL,"非法字符","错误",MB_OK|MB_ICONHAND);
if(m_pctrEdit){
this->m_pctrEdit->SetSel(this->m_pPtWd.piFst_word,this->m_pPtWd.piLst_word);
this->m_pctrEdit->SetFocus();
}*/
return TDim;
}
WordType CWordAnalyse::Reserve()
{
for(int i=0;i<SIZE_TB;i++){
// TRACE("基本字表第%d个元素:%s\n",i,this->Table_BaseWord[i].WdVlue.SignOrString);
if(!strcmp(this->m_sWord,this->Table_BaseWord[i].WdVlue.SignOrString))
break;
}
if(i>=SIZE_TB) return $NOTBASEWORD;
return this->Table_BaseWord[i].WdTp;
}
bool CWordAnalyse::IntIsInRange(CString str)
{
int len=str.GetLength();
CString strNormal("2147483647");
CString strBit,strNmBit;
if(len>10){
//if(m_pctrEdit){
// this->m_pctrEdit->SetSel(this->pScan,pScan-len);
// this->m_pctrEdit->SetFocus();
//}
return false;
}
if(len<10) return true;
//当其长度为10时
assert(len==10);
for(int i=9;i>=0;i--){
strBit=str[i];
strNmBit=strNormal[i];
if(atoi(strBit)>atoi(strNmBit)){
//if(m_pctrEdit){
// this->m_pctrEdit->SetSel(this->pScan,pScan-len);
// this->m_pctrEdit->SetFocus();}
return false;
}
if(atoi(strBit)<atoi(strNmBit)) return true;
assert(atoi(strBit)==atoi(strNmBit));
}
return true;
}
//如果前一次读入的是空操作符(文件尾),此操作后指针依然指向文件尾
//否则,指向前一个字的字头
void CWordAnalyse::BackWord()
{
this->m_piPointer=this->m_pPtWd.piFst_word;
this->m_ptStr=this->m_pPtWd.pFst_word;
// TRACE("------------------%S\n",this->m_ptStr);
if(*this->m_ptStr!='\000')VERIFY(this->m_sBuffRes.GetAt(this->m_piPointer)==this->m_ptStr[0]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -