魔王语言源代码Word格式文档下载.docx
- 文档编号:19184303
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:9
- 大小:32.87KB
魔王语言源代码Word格式文档下载.docx
《魔王语言源代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《魔王语言源代码Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。
voidPush(structStack&
s,chare){//压入元素
if(s.top-s.base>
=STACK_INIT_SIZE){
s.base=(char*)realloc(s.base,(s.stacksize+STACK_INCREMENT)*sizeof(char));
s.top=s.base+s.stacksize;
s.stacksize+=STACK_INCREMENT;
}
*(s.top)=e;
s.top++;
voidPop(structStack&
s,char&
e){//取出元素
e=*--s.top;
intStackEmpty(structStacks){//栈是否为空
if(s.top==s.base){
return1;
else{
return0;
voidClearStack(structStack&
s){
structQueue{
chardata;
structQueue*next;
structLinkQueue{
structQueue*front;
structQueue*rear;
voidInitQueue(structLinkQueue&
q){//构造队
q.front=q.rear=(structQueue*)malloc(sizeof(structQueue));
q.front->
next=NULL;
voidEnQueue(structLinkQueue&
q,chare){//元素入队
structQueue*p;
p=(structQueue*)malloc(sizeof(structQueue));
p->
data=e;
q.rear->
next=p;
q.rear=p;
voidDeQueue(structLinkQueue&
q,char&
e){//元素出队
p=q.front->
next;
e=p->
data;
next=p->
if(q.rear==p){
q.rear=q.front;
free(p);
intQueueEmpty(structLinkQueueq){//队是否为空
if(q.front==q.rear){
voidInStack(char*ch,structStack&
s){//把字符数组从右至左压入栈中
inti,L=0;
while(ch[L]!
='
\0'
){
L++;
for(i=L-1;
i>
=0;
i--){
Push(s,ch[i]);
intmain(){
inti=0;
charA[]="
sae"
;
charB[]="
tsaedsae"
charflag='
0'
//flag用来标记处理括号
intmark=1;
intf=0;
structStackS;
structStacktemp;
//用来处理括号外的元素
InitStack(S);
InitStack(temp);
structLinkQueueQ;
InitQueue(Q);
charMoWang[100]="
\0"
chare1,key,e2,e;
printf("
**************************************************************\n"
);
**欢迎光临广东工业大学**\n"
******************************\n"
**魔王语言解释系统**\n"
*班级:
计算机学院网络工程2007级4班*\n"
*姓名:
黄文龙学号:
3107007087*\n"
**************************************************************\n\n"
请输入你想要解释的魔王语言(最多含有一个括号):
\n"
gets(MoWang);
InStack(MoWang,S);
//把要解释的魔王语言压入栈中
while(!
StackEmpty(S)){
Pop(S,e1);
if(e1=='
('
if(StackEmpty(S)){
魔王语言错误!
mark=0;
break;
)'
f=1;
elseif(!
(e1>
a'
&
e1<
z'
)&
!
A'
Z'
)){
魔王语言错误!
}
if(mark==0){
if(f!
=1){
elseif(e1=='
if(mark==1&
f==1){
ClearStack(S);
StackEmpty(S)){//栈不空时
B'
Push(temp,e1);
){//用队存储括号中的元素
Push(temp,flag);
//有括号的话就用flag标记
while(e1!
EnQueue(Q,e1);
if(!
QueueEmpty(Q)){
DeQueue(Q,key);
f=0;
StackEmpty(temp)){//边处理边进栈
Pop(temp,e1);
if(e1!
=flag){//把括号外的元素压入中
Push(S,e1);
QueueEmpty(Q)){//处理括号中的元素进栈
DeQueue(Q,e2);
Push(S,key);
Push(S,e2);
=0){//最后还要压一个key
解释后的语言为:
StackEmpty(S)){//依次出栈输出处理后的元素
Pop(S,e);
EnQueue(Q,e);
//元素进队是为了输出对应汉字
if(e=='
%s"
B);
elseif(e=='
A);
%c"
e);
QueueEmpty(Q)){//输出对应汉字
DeQueue(Q,e);
switch(e){
case'
t'
:
天"
break;
d'
:
地"
s'
上"
一只"
e'
鹅"
追"
g'
赶"
x'
下"
n'
蛋"
h'
恨"
天上一只鹅地上一只鹅"
上一只鹅"
default:
*"
system("
pause"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 魔王 语言 源代码