📄 analyse.h
字号:
#include <ctype.h>
#include "Keyword.h"
#include "other.h"
//Open the file
int Openfile( char* filename , char* type )
{
//try to open the file
FILE *fp=fopen( filename , type );
//Check the file does exit or not
if(!fp)
{
//The file does not exit
perror("The file does not exist!");
return 0 ;
}
int Analyse( FILE* ) ;
//Analyse the sentence
Analyse(fp);
//close the file
fclose(fp);
return 1 ;
}
//Analyse
int Analyse( FILE* fp )
{
//get the character
char getch ;
//get the string
char str[100] ;
cleanstr( str , 100 ) ;
int i=0 ;
//Analyse
while((getch=fgetc(fp))!=EOF )
{
if ( getch != 10 )
{
str[i] = getch ;
i++ ;
}
else
{
//str[i] = getch ;
//printf("%s\n",str) ;
SubAnalyse(str) ;
//SubAnalyse ( str ) ;
cleanstr( str , 100 ) ;
i = 0 ;
}
}
}
//Sub Analyse
int SubAnalyse ( char *str )
{
char substr[100] ;
cleanstr( substr , 100 ) ;
int si = 0 ; // i for string
int sui = 0 ; // i for substring
for( si = 0 ; str[si]!='\0' ; si++ )
{
//meet blank
if( str[si]==32 )
{
cleanstr( substr , 100 ) ; //clean the substring
continue ;
}
//meet ;
else if( str[si]==59 )
{
cleanstr( substr , 100 ) ; //clean the substring
printf("; 特殊符号\n") ;
continue ;
}
else if( ispunct(str[si]) && str[si]!=34 )
{
cleanstr( substr , 100 ) ; //clean the substring
substr[sui] = str[si] ;
while( ispunct(str[si+1]) && str[si+1]!=32 && str[si+1]!=59 && str[si+1]!=34 )
{
sui++ ; si++ ;
substr[sui] = str[si] ;
}
if( Operatormarks(substr) )
{
printf("%s 运算符号\n",substr) ;
}
else printf("%s 特殊符号\n",substr) ;
sui = 0 ;
continue ;
}
//meet letter
else if( isupper(str[si]) || islower(str[si]) )
{
cleanstr( substr , 100 ) ; //clean the substring
substr[sui] = str[si] ;
while( isupper(str[si+1]) || islower(str[si+1]) || str[si+1]==46 )
{
sui++ ; si++ ;
substr[sui] = str[si] ;
}
if( Keyword(substr) )
{
printf("%s 关键字\n",substr) ;
}
else printf("%s 标识符\n",substr) ;
sui = 0 ;
continue ;
}
//meet number
else if( isdigit(str[si]) )
{
cleanstr( substr , 100 ) ; //clean the substring
substr[sui] = str[si] ;
while( isdigit(str[si+1]) || str[si+1]==46 )
{
sui++ ; si++ ;
substr[sui] = str[si] ;
}
printf("%s 数字\n",substr) ;
sui = 0 ;
continue ;
}
// meet string ""
else if( str[si]==34 )
{
cleanstr( substr , 100 ) ; //clean the substring
substr[sui] = str[si] ;
int change = 0 ;
while( 1 )
{
sui++ ; si++ ;
substr[sui] = str[si] ;
if( change==1 ) change=0 ; //meet \
else if( str[si]==92 ) change=1 ;
else if( str[si]==34 ) break ;
else continue ;
}
printf("%s 字符串\n",substr) ;
sui = 0 ;
continue ;
}
}
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -