www.pudn.com > csouce.rar > cifa.cpp


#include  
#include  
#include 
#include 
#include 
#include 
const long stakmaxsize=6000; 
int flag; 
const char keyword[][20]={{'i','n','t'},{'v','o','i','d'},{'i','f'}, 
{'c','h','a','r'},{'b','o','o','l'},{'b','r','e','a','k'},{'c','a','s','e'}, 
{'c','a','t','c','h'},{'c','o','n','s','t'},{'f','o','r'},{'e','l','s','e'}, 
{'c','o','n','t','i','n','u','e'},{'c','l','a','s','s'},{'w','h','i','l','e'}, 
{'d','o'},{'g','o','t','o'},{'f','l','o','a','t'},{'d','o','u','b','l','e'}, 
{'l','o','n','g'},{'s','w','i','t','c','h'},{'f','r','i','e','n','d'},{'s','t','a','t','i','c'}, 
{'p','u','b','l','i','c'},{'p','r','i','v','a','t','e'},{'p','r','o','t','e','c','t','e','d'}, 
{'r','e','t','u','r','n'},{'i','n','l','i','n','e'},{'t','r','y'},{'s','t','r','u','c','t'}}; 
 
 
char Ischeck[]={' ','\n','+','-','*','(',')','{','}', 
';','=','\"',',','&','[',']','!',':','<','>','\'','/'}; 
bool isCheck(const char& ch) 
{ 
  for(int i=0;i<27;i++) 
  if(ch==Ischeck[i]) return true; //判断字符 
  return false;                    
}                               
struct stack                    //堆栈 
{ 
  char stak[stakmaxsize];         //定义一个字符型堆栈 
  int top; 
}; 
void initstak(stack& s)         //初始化 
{ 
  s.top=-1; 
} 
void clearstak(stack& s)         //清堆栈函数 
{ 
  s.top=-1; 
} 
void push(stack& s,const char& item)     //入堆栈 
{ 
  if(s.top==stakmaxsize-1) 
{ 
  cerr<<"溢出"<': Getchar(fp,ch); 
if(ch=='=') 
{cout<<"算符 "<<">="<"<"<>filename; 
check(filename); 
}