📄 compliehead.h
字号:
#include "stdio.h"
#include "malloc.h"
typedef struct
{
int attribute;
char* value;
}AttributeByte;
typedef enum
{
KEYWORD,
SYMBOL,
OPERATION,
CONST_NUM,
CONST_STRING,
CONST_CHAR,
BOUNDARY,
EMPTY
};
FILE* initFile(const char* fileName, char* openFileType)
{
FILE* pScrFile;
if((pScrFile = fopen(fileName, openFileType)) == NULL)
{
printf("Can't open file!");
}
return pScrFile;
}
void loadFromFileToBuffer(FILE* pScrFile, char* pBuffer, int bufferSize)
{
char ch;
int i;
for(i=0; i<bufferSize; i++)
{
if(!feof(pScrFile))
{
ch = fgetc(pScrFile);
*pBuffer = ch;
pBuffer ++;
}
}
}
void putAttributeToFile(FILE* pDesFile, AttributeByte* pByte)
{
char* ch;
bool empty;
empty = false;
switch(pByte->attribute)
{
case KEYWORD:
ch = "KEYWORD";
break;
case SYMBOL:
ch = "SYMBOL";
break;
case OPERATION:
ch = "OPERATION";
break;
case CONST_NUM:
ch = "CONST_NUM";
break;
case BOUNDARY:
ch = "BOUNDARY";
break;
case CONST_STRING:
ch = "CONST_STRING";
break;
case CONST_CHAR:
ch = "CONST_CHAR";
break;
case EMPTY:
empty = true;
break;
}
if(!empty)
{
while(*ch != '\0')
{
fputc(*ch, pDesFile);
ch ++;
}
fputc(32, pDesFile);
ch = pByte->value;
while(*ch != '\0')
{
fputc(*ch, pDesFile);
ch ++;
}
fputc('\n', pDesFile);
}
}
void closeFile(FILE *pFile)
{
fclose(pFile);
}
bool isLetter(char inputChar)
{
if((inputChar >= 65 && inputChar <= 90) || (inputChar >= 97 && inputChar <= 122))
{
return true;
}
return false;
}
bool isNumber(char inputChar)
{
if(inputChar >= 48 && inputChar <= 57)
{
return true;
}
return false;
}
bool is16Number(char inputChar)
{
if((inputChar >= 48 && inputChar <= 57 ) || (inputChar >= 65 && inputChar <= 70) || (inputChar >= 97 && inputChar <= 102))
{
return true;
}
return false;
}
//debug
void printBuffer(char *buffer, int bufferSize)
{
int i;
for(i=0; i<bufferSize; i++)
{
printf("%c", buffer[i]);
}
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -