?? my_read_in.h
字號:
#include "my_judge.h"
#include "my_error.h"
//////////////////////////////////////
// 詞法分析部分功能函數(shù)清單:
//
void GetChar();
//將下一輸入字符讀到ch中,搜索指示器前移一字符位置。
void GetBC();
//檢查ch中的字符是否為空白。
//若是,則調(diào)用GetChar直至ch中進入一個非空格字符。
void Concat();
//將ch中的字符接到strToken之后
void Retract();
//將搜索指示器回調(diào)一個字符位置,設ch為空白字符。
int InsertId();
//將strToken中的標識符加入變量名表
int InsertConst();
//將strToken中的常量加入常量表
int Reserve();
//對strToken中的字符查保留字表,若它是一個保留字則返回它的編碼,
//否則返回0,(假定0不是保留字的編碼)。
int Reserve_Flag();
//對strToken中的字符查符號表,若它是一個符號則返回它的編碼,
//否則返回0,(假定0不是符號的編碼)。
void Get_A_Word(ofstream onfile);
//讀入一個單詞,并轉換他的內(nèi)碼。
//
///////////////////////////////////////////////////////////////
//////////////////////////////////////
// 詞法分析部分功能函數(shù)清單:
//
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
void GetChar()
{
ch=buff[I];
I++;
//cout<<"get_ch-----: "<<ch<<endl;
};
///////////////////////////////////////////////////////
void GetBC()
{
while(ch==32)
{
ch=buff[I];
I++;
}
};
///////////////////////////////////////////////////////
void Concat()
{
char temp[2];
temp[0]=ch;
temp[1]='\0';
strcat(strToken,temp);
};
///////////////////////////////////////////////////////
void Retract()
{
I--;
ch=32;
};
///////////////////////////////////////////////////////
int InsertId()
{
for(int i=0;i<=J;i++)
{
if(strcmp(strToken,b[i])==0)
{
return b_value[i];
}
}
strcpy(b[J],strToken);
b_value[J]=BY_BEGIN_OF_V+1+J;
J++;
return b_value[J-1];
}
///////////////////////////////////////////////////////
int InsertConst()
{
for(int i=0;i<=K;i++)
{
if(strcmp(strToken,c[i])==0)
{
return c_value[i];
}
}
strcpy(c[K],strToken);
c_value[K]=BY_BEGIN_OF_C+1+K;
K++;//全局變量K返回的是本待測程序的常量個數(shù)
return c_value[K-1];
}
/////////////////////////////////////////////////////////
void Get_A_Word(ofstream onfile)
{
int code=0;
strcpy(strToken,"");
GetChar();
GetBC();
if(isalpha_S(ch))//單詞如果以小寫字母開始
{
//cout<<"單詞如果以小寫字母開始"<<endl;
while(isalnum(ch)||isalpha(ch)||isunderline(ch))//后接數(shù)字、字母、下劃線
{
Concat();
GetChar();
}
Retract();
code=InsertConst();// //cout<<"這樣的單詞是常量或函子"<<endl;
if(code!=0)
{
/*****/onfile<<code<<endl;
/*****/onfile<<strToken<<endl;
Syn_Lines++;
//onfile<<endl;
}
else
{
error(0);
}
}
else//單詞不是以小寫字母開始
{
if(isalpha_G(ch)||isunderline(ch))//單詞如果以大寫字母或者下劃線開始
{
//cout<<"單詞如果以大寫字母或者下劃線開始"<<endl;
while(isalnum(ch)||isalpha(ch)||isunderline(ch))//后接數(shù)字、字母、下劃線
{
Concat();
GetChar();
}
Retract();
code=InsertId(); //cout<<"這樣的單詞是變量"<<endl;
if(code!=0)
{
/*******/onfile<<code<<endl;
/*******/onfile<<strToken<<endl;
Syn_Lines++;
//onfile<<endl;
}
else
{
error(0);
}
}
else//單詞不以大寫字母、小寫字母、下劃線開始,則單詞是符號或無效符號
{
//cout<<"單詞不以大寫字母、小寫字母、下劃線開始,則單詞是符號或無效符號"<<endl;
switch (ch)
{
case '.': Concat(); code=DOT; break;
case ',': Concat(); code=COM; break;
case ';': Concat(); code=SEM; break;
case '(': Concat(); code=LBR; break;
case ')': Concat(); code=RBR; break;
case '!': Concat(); code=BRK; break;
case ':':
Concat(); GetChar();
if (ch=='-')
{ Concat(); code=IF; }
else
{ Retract(); code=0; }
break;
}
if(code!=0)
{
/********/onfile<<code<<endl;
/********/onfile<<strToken<<endl;
Syn_Lines++;
//onfile<<endl;
}
else
{
error(0);
}
}
}
//字符串讀函數(shù) fgets(str,n,fp)
//從指定文件(fp)讀入n-1 個字符,如果在讀入n-1個字符之前遇到換行符或EOF(-1),
//讀入即結束,結束后,在最后加上一個'\0'
//fgets函數(shù)返回str的地址
}
/////////////////////////////////////////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -