📄 init.h
字号:
/*Initial Declaration*/
/* 接受标记 */
#define ACC -2
/* 保留字符号 */
#define SYMBOL_IF 0
#define SYMBOL_THEN 1
#define SYMBOL_ELSE 2
#define SYMBOL_WHILE 3
#define SYMBOL_BEGIN 4
#define SYMBOL_DO 5
#define SYMBOL_END 6
/* 赋值语句 */
#define a 7
/* ;号 */
#define SEMICOLON 8
/* 布尔表达式 */
#define e 9
/* #号 */
#define WELL 10
/* 语句 */
#define S 11
/* 复合语句 */
#define L 12
/* 临时变量 */
#define TEMPVAR 15
/* B and */
#define EA 18
/* B or */
#define EO 19
/* 加 */
#define PLUS 34
/* 乘 */
#define TIMES 36
/* := */
#define BECOMES 38
/* and */
#define OPTION_AND 39
/* or */
#define OPTION_OR 40
/* not */
#define OPTION_NOT 41
/* 关系运算符 */
#define ROP 42
/* ( */
#define LPARENT 48
/* ) */
#define RPARENT 49
/* 变量 */
#define IVAR 56
/* 整常量 */
#define INTCONST 57
/********************************/
char ch='\0';
int count=0;/*二元式的个数*/
static char spelling[10]={""};
static char line[81]={""};
char *pline;
static char ntab1[100][10];
struct ntab{
int tc;
int fc;
}ntab2[200];
int label=0;
struct rwords{
char sp[10];
int sy;
};
struct rwords reswords[10]={
{"if",SYMBOL_IF},
{"do",SYMBOL_DO},
{"else",SYMBOL_ELSE},
{"while",SYMBOL_WHILE},
{"then",SYMBOL_THEN},
{"begin",SYMBOL_BEGIN},
{"end",SYMBOL_END},
{"and",OPTION_AND},
{"or",OPTION_OR},
{"not",OPTION_NOT}
};
struct aa{
int sy1;
int pos;
}buf[1000],
n,
n1,
E,
sstack[100],
ibuf[100],
stack[1000];
struct aa oth;
struct fourexp{
char op[10];
struct aa arg1;
struct aa arg2;
int result;
}fexp[200];
int ssp=0;
struct aa *pbuf=buf;
int nlength=0;
int programlinenum=0;/*程序的行数*/
int tt1=0;
FILE *cfile;
/****************************************/
int newt=0;
int nxq=100;
int lr;
int lr1;
int sp=0;
int stack1[100];
int sp1=0;
int num=0;
struct ll{
int nxq1;
int tc1;
int fc1;
}labelmark[10];
int labeltemp[10];
int pointmark=-1,pointtemp=-1;
int sign=0;
/****************************************/
/**************程序语句的LR分析表**************************/
static int action[19][13]={
{2,-1,-1,3,4,-1,-1,5,-1,-1,10,1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,ACC,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,6,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,7,-1,-1,-1},
{2,-1,-1,3,4,-1,-1,5,-1,-1,-1,9,8},
{-1,-1,104,-1,-1,-1,104,-1,104,-1,104,-1,-1},
{-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,-1,-1,-1,105,-1,13,-1,-1,-1,-1},
{2,-1,-1,3,4,-1,-1,5,-1,-1,-1,14,-1},
{2,-1,-1,3,4,-1,-1,5,-1,-1,-1,15,-1},
{-1,-1,103,-1,-1,-1,103,-1,103,-1,103,-1,-1},
{2,-1,-1,3,4,-1,-1,5,-1,-1,-1,9,16},
{-1,-1,17,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,102,-1,-1,-1,102,-1,102,-1,102,-1,-1},
{-1,-1,-1,-1,-1,-1,106,-1,-1,-1,-1,-1,-1},
{2,-1,-1,3,4,-1,-1,5,-1,-1,-1,18,-1},
{-1,-1,101,-1,-1,-1,101,-1,101,-1,101,-1,-1}
};
/**************算术表达式的LR分析表**************************/
static int action1[10][7]={
{3,-1,-1,2,-1,-1,1},
{-1,4,5,-1,-1,ACC,-1},
{3,-1,-1,2,-1,-1,6},
{-1,104,104,-1,104,104,-1},
{3,-1,-1,2,-1,-1,7},
{3,-1,-1,2,-1,-1,8},
{-1,4,5,-1,9,-1,-1},
{-1,101,5,-1,101,101,-1},
{-1,102,102,-1,102,102,-1},
{-1,103,103,-1,103,103,-1}
};
/**************布尔表达式的LR分析表**************************/
static int action2[16][11]={
{1,-1,4,-1,5,-1,-1,-1,13,7,8},
{-1,2,-1,101,-1,101,101,101,-1,-1,-1},
{3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,102,-1,102,102,102,-1,-1,-1},
{1,-1,4,-1,5,-1,-1,-1,11,7,8},
{1,-1,4,-1,5,-1,-1,-1,6,7,8},
{-1,-1,-1,104,-1,9,10,104,-1,-1,-1},
{1,-1,4,-1,5,-1,-1,-1,14,7,8},
{1,-1,4,-1,5,-1,-1,-1,15,7,8},
{105,-1,105,-1,105,-1,-1,-1,-1,-1,-1},
{107,-1,107,-1,107,-1,-1,-1,-1,-1,-1},
{-1,-1,-1,12,-1,9,10,-1,-1,-1,-1},
{-1,-1,-1,103,-1,103,103,103,-1,-1,-1},
{-1,-1,-1,-1,-1,9,10,ACC,-1,-1,-1},
{-1,-1,-1,106,-1,9,10,106,-1,-1,-1},
{-1,-1,-1,108,-1,9,10,108,-1,-1,-1}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -