📄 compile.h
字号:
/*==================================================
************简单的一遍编译器c++语言的实现**************
==================================================*/
#ifndef _COMPILE_H_
#define _COMPILE_H_
#include <stdio.h>
#include <ctype.h>
#include <string.h>
struct entry //符号表的表项形式
{
char *lexptr;
int token;
};
class translate //简单的一遍编译器类的定义
{
public:
translate():lastchar(-1), lastentry(0),
lineno(1), tokenval(NONE)
{ }
~translate()
{ }
public:
void init ();
void parse();
protected:
//保护成员函数声明
int lookup(char s[]);
int insert(char s[],int tok);
void error(char *m);
void emit(int t, int tval);
int lexan();
private:
//私有成员函数声明
void expr();
void term();
void factor();
void match(int t);
protected:
//类中使用的常量定义
static const int BSIZE = 128; //缓冲区大小
static const int NONE = -1;
static const char EOS = '\0';
static const int NUM = 256;
static const int DIV = 257;
static const int MOD = 258;
static const int ID = 259;
static const int DONE = 260;
static const int STRMAX = 999; //lexemes数组的大小
static const int SYMMAX = 100; //symtable的大小
private:
//私有成员变量声明
char lexemes[STRMAX] ;
int lastchar ; //lexmes的最后引用位置
entry symtable[SYMMAX] ;
int lastentry ;
char lexbuf[BSIZE] ;
int lineno ;
int tokenval ; //与记号关联的属性值
int lookahead ;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -