| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:为什么出现内存不可read
只看楼主 加入收藏
fkl888
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-12
收藏
 问题点数:0 回复次数:0 
为什么出现内存不可read

这是个简单的某个文法的LL(1),可对 i+i*i# 这类匹配
为什么我输入有'i'的时候就回出现什么内存不可读


#include<string.h>
#include<stdlib.h>
#include<iostream.h>

char a[]={'E','e','T','t','F','A','M'};
char b[]={'i','+','-','*','/','(',')','#'};
char *f[7][8]={{"Te","0","0","0","0","Te","0","0"},{"0","ATe","ATe","0","0","0","k","k"},
{"Ft","0","0","0","0","Ft","0","0"},{"0","k","k","MFt","MFt","0","k","k"},
{"i","0","0","0","0","(E)","0","0"},{"0","+","-","0","0","0","0","0"},
{"0","0","0","*","/","0","0","0"}};
struct stack{
char s[20];
int t;};
typedef struct stack *pseqstack;

pseqstack create(void)
{ pseqstack pastack;
pastack=(pseqstack)malloc(sizeof(struct stack));
if(pastack==NULL)
cout<<"out of space"<<endl;
else pastack->t=-1;
return(pastack);
}


void push(pseqstack pastack,char x)
{ pastack->t=pastack->t+1;
int i=0;
i=pastack->t;

pastack->s[i]=x;
}

void pop(pseqstack pastack)
{if(pastack->t==-1)
cout<<"underflow"<<endl;
else
pastack->t=pastack->t-1;
}

char top(pseqstack pastack)
{return(pastack->s[pastack->t]);
}


void macth(pseqstack pastack,char *p)
{ int j=0,m=0,n=0,q=0;
char tp;
char temp[10];

for(;;)
{tp=top(pastack);

if(tp=='#')
{if(p[j]=='#')
cout<<"macth"<<endl;

else
cout<<"error"<<endl;
break;
}
if(tp=='i'||tp=='+'||tp=='-'||tp=='*'||tp=='/'||tp=='('||tp==')')
{

if(tp==p[j])
{pop(pastack);
j++;
continue;}
else
{cout<<"error"<<endl;
break;
}
}
for(m=0;m<7;m++)
{if(a[m]==tp)
break;}
for(n=0;n<8;n++)
{if(b[n]==p[j])
break;}
strcpy(temp,f[m][n]);
if(strcmp(temp,"k")==0)

{pop(pastack);
continue;
}
if(strcmp(temp,"0")==0)
{cout<<"error"<<endl;
break;
}
else
{for(n=0;temp[n]!='\0';n++)
{
q=q+1;
}
for(n=q-1;n>=0;n--)
{
push(pastack,temp[n]);
}
}

}

}
void main()
{ char ru[10];
char j;

pseqstack pk=create();

j='#';
push(pk,j);
j='E';
push(pk,j);
cout<<"shu ru zifu chuan: ";
cin>>ru;

macth(pk,ru);
}

[此贴子已经被作者于2007-3-20 19:22:55编辑过]

搜索更多相关主题的帖子: 内存 read 
2007-03-20 19:09
快速回复:为什么出现内存不可read
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023633 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved