📄 anayword.h
字号:
#ifndef ANAYWORD
#define ANAYWORD
#include "include.h"
/***********************************************************************************
* 查关键字表Search() *
***********************************************************************************/
int Search(char *buf)
{
for (int i=0;i<KEYSNUM;i++)
{
if ( strcmp(keys[i],buf)==0 )
{
strcpy(table[p].name,buf);
table[p].no=i;
p++;
return 1;
}
// if(p==16)//&&buf!="ident")
// printf("error");
}
return 0;
}
/***********************************************************************************
* 查关键字表Scan() *
***********************************************************************************/
void Scan(FILE *fp)
{
int j=0,k=0;
char strID[32];//ID字符串数组
char strNum[100];//无符号数字符串数组
while (ch ==' '||ch =='\n'||ch =='\t') ch = fgetc(fp);
if ( IsLetter(ch) )
{//构造标志符的有限自动机
strID[j++] = ch;
ch = fgetc(fp);
while ( IsLetter(ch) || IsDigit(ch) )
{
strID[j++] = ch;
ch = fgetc(fp);
}
strID[j]='\0';
if( Search(strID) ) ;
else
{
//table[p]=IDENT;
strcpy(table[p].name,strID);
table[p].no=IDENT;
//strcpy(IDTable[IDptr],strID);
//IDptr++;
p++;
}
fseek(fp, -1L, 1);
return;
}
if ( IsDigit(ch) )
{//构造无符号数字的有限自动机
strNum[k++] = ch;
ch = fgetc(fp);
while (IsDigit(ch))
{
strNum[k++] = ch;
ch = fgetc(fp);
}
if (ch=='.')
{
ch = fgetc(fp);
if (IsDigit(ch))
{
strNum[k++]='.';
strNum[k++]=ch;
ch = fgetc(fp);
while (IsDigit(ch))
{
strNum[k++]=ch;
ch = fgetc(fp);
}
fseek(fp, -1L, 1);
strNum[k]='\0';
strcpy(table[p].name,strID);
table[p].no=CONST;
p++;
return;
}
fseek(fp, -2L, 1);
strNum[k]='\0';
strcpy(table[p].name,strID);
table[p].no=CONST;
p++;
return;
}
fseek(fp, -1L, 1);
strNum[k]='\0';
strcpy(table[p].name,strNum);
table[p].no=CONST;
p++;
return;
}
//Search(&ch);
switch (ch)
{
case '=': Search("="); //查符号表
return;
case '<': ch = fgetc(fp);
if (ch=='=')
{ Search("<=");
return;
}
else if (ch=='>')
{ Search("<>");
return;
}
else
fseek(fp, -1L, 1);
Search("<");
return;
case '>': ch = fgetc(fp);
if (ch=='=')
{ Search(">=");
return;
}
else
fseek(fp, -1L, 1);
Search(">");
return;
case ':': ch = fgetc(fp);
if (ch=='=')
{ Search(":=");
return;
}
else
fseek(fp, -1L, 1);
Search(":");
return;
case '.': Search(".");
return;
case '(': ch = fgetc(fp);
if (ch=='*') //若是注释,则读掉
{
ch = fgetc(fp);
do{
while (ch!='*') ch = fgetc(fp);
ch = fgetc(fp);
}while(ch!=')') ;
return;
}
else
fseek(fp, -1L, 1);
Search("(");
return;
case ')': Search(")");return;
case '+': Search("+");return;
case '-': Search("-");return;
case '*': Search("*");return;
case '/': Search("/");return;
case ',': Search(",");return;
case ';': Search(";");return;
default:
break;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -