📄 ll_1.c
字号:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
struct xxx //矩阵的坐标
{char ch;
int biaohao;};
struct xxx xx[7]={{'E',0},{'F',1},{'T',2},{'U',3},{'P',4},{')',5},{'#',6}};
struct xxx yy[6]={{'i',0},{'(',1},{'+',2},{')',3},{'*',4},{'#',5}};
struct str //产生式和矩阵
{int num; //产生式标号
char AA; //左端
char BB[3]; //右端
};
struct str css[8]={{1,'E',"TF"},
{2,'F',"+TF"},
{3,'F',"^"},
{4,'T',"PU"},
{5,'U',"*PU"},
{6,'U',"^"},
{7,'P',"(E)"},
{8,'P',"i"}};
struct str jz[7][6]={ {{1,'P',"FT"},{1,'P',"FT"}},
{{-2,' '," "},{-2,' '," "},{2,'N',"FT"},{3,'P',"^"},{-2,' '," "},{3,'P',"^"}},
{{4,'P',"UP"},{4,'P',"UP"}},
{{-2,' '," "},{-2,' '," "},{6,'P',"^"},{6,'P',"^"},{5,'N',"UP"},{6,'P',"^"}},
{{8,'N',"^"},{7,'N',")E"}},
{{-2,' '," "},{-2,' '," "},{-2,' '," "},{-1,'N',"^"}},
{{-2,' '," "},{-2,' '," "},{-2,' '," "},{-2,' '," "},{-2,' '," "},{0,' ',"OK!"}} };
char s[10]={"#E"}; //s栈 初始值是#E
char in[10]; //输入流
int x=0,y=0; //坐标
int inport; //输入流指针
int sport=1; //s栈指针
void position() //当前坐标赋给x,y
{
int i;
for(i=0;i<7;i++)
{if s[sport]==xx[i].ch
break;}
x=i;
i=0;
while in[inport]!=yy[i].ch
i++;
y=i;
}
void print() //显示函数
{
int i;
i=0;
putch('\n');
puts(s); //显示s栈
printf('\t');
puts(in); //显示输入流
putch('\t');
if jz[x][y].num>0 //显示表达式
{putch(css[jz[x][y].num-1].aa);
puts(css[jz[x][y].num-1].bb);
}
printf('\t');
}
void move() //改变函数
{
position;
if jz[x][y].num==-2
{puts("表达式错误!!");
abort();
}
else if jz[x][y].num==-1
}
void main()
{
printf("请输入一个表达式:(****#)\n ");
gets(in); //输入流
inport=strlen(in);//输入流指针初始化
printf("s栈\t输入流\t产生式");
while ((x=6)&&(y=5))
{print;
move;};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -