这个语法分析器错在哪里?

#include<iostream>
using namespace std;
#define MAXSIZE 100

typedef struct
{
 char *base;
 char *top;
 int size;
}sqstack;

typedef struct
{
 char t;
 int number;
}zongheti;
zongheti a[8];

typedef struct
{
 char m;
 char *p;
}wf;
wf wenfa[20][20];
char zanshi[20];
int max=0;
int k;

void initstack(sqstack &s)
{
 s.base=(char *)malloc(MAXSIZE*sizeof(char));
 s.size=MAXSIZE;
 s.top=s.base;
}

int data[9][9]=
{
     1,1,-1,-1,-1,-1,1,1,
  1,1,-1,-1,-1,-1,1,1,
  1,1,1,1,-1,-1,1,1,
  1,1,1,1,-1,-1,1,1,
  1,1,1,1,-1,-1,1,1,
  1,1,1,1,2,2,1,1,
  -1,-1,-1,-1,-1,-1,0,2,
  1,1,1,1,2,2,1,1,
  -1,-1,-1,-1,-1,-1,2,0
};

int feizhongjie(char t)
{
 if(t<='Z'&&t>='A')
 return 1;
 else
  return 0;
}

void push(sqstack &s,char t)
{
 *s.top=t;
 s.top++;
}

char pop(sqstack &s)
{
 char t;
 t=*(s.top--);
 return t;
}
char gettop(sqstack &s)
{
 char t;
 t=*(s.top-1);
 return t;
}

void guiyue(sqstack &s,char *p)
{
 int i=0,j=0;
 char *q;
 q=p;
 while(p<s.top)
 {
  zanshi[i]=*p;
  p++;
  i++;
 }
 zanshi[i]='/0';
 s.top=q;
 for(i=0;i<k;i++)
  for(j=0;j<max;j++)
 
   if(!strcmp(wenfa[i][j].p,zanshi))
   {push(s,wenfa[i][j].m);
       break;
   }
}
int main()
{
 sqstack s;
 initstack(s);
 a[0].t='+';
 a[0].number=1;
 a[1].t='-';
 a[1].number=2;
 a[2].t='*';
 a[2].number=3;
 a[3].t='/';
 a[3].number=4;
 a[4].t='i';
 a[4].number=5;
 a[5].t='(';
 a[5].number=6;
 a[6].t=')';
 a[6].number=7;
 a[7].t='$';
 a[7].number=8;
 int i,j,n;
 char *p,*t;
 char str[20][20];
 char string[20];
 cout<<"输入文法规则数"<<endl;
 cin>>k;
 cout<<"请输入相应的文法规则"<<endl;
    for(i=0;i<k;i++)
  cin>>str[i];
 for(i=0;i<k;i++)
 {
    n=0;
   for(j=0;j!='/n';j++)
     if(str[i][j]=='|')
    n++;
        if(max<n)
    max=n;
 }
 for(i=0;i<k;i++)
  for(j=0;j<max;j++)
  {
   wenfa[i][j].m='N';
   wenfa[i][j].p=(char*)malloc(20*sizeof(char));
   *wenfa[i][j].p='/0';
  
  }
    
 for(i=0;i<k;i++)
 {
         
   if(feizhongjie(str[i][0]))
   {
      str[i][0]='N';
      n=0;
      j=1;
      t=wenfa[i][n].p;
    }
         else
   {
    cout<<"不合法"<<endl;
    return -1;
   }
    for(j=1;str[i][j]!=';';j++)
  {
   
   if(feizhongjie(str[i][j]))
   {
    str[i][j]='N';
                *(wenfa[i][n].p)=str[i][j];
       wenfa[i][n].p++;
   }
   else
   {
    if(str[i][j]!='|'&&str[i][j]!='-'&&str[i][j]!='>')
    {
     *(wenfa[i][n].p)=str[i][j];
     wenfa[i][n].p++;
    }
    else
    {
     if(str[i][j]=='|')
     {
      *wenfa[i][n].p='/0';
      wenfa[i][n].p=t;
      n++;
      wenfa[i][n].m='N';
      t=wenfa[i][n].p;
      }
    }
   }
  }
  *wenfa[i][n].p='/0';
  wenfa[i][n].p=t;
 }
 cout<<"输入要分析的短语,按$结束:"<<endl;
 cin>>string;
 push(s,'$');
 i=0;
 int x=0,y=0;
 do
 {
     int z=0,b;
        if(feizhongjie(gettop(s)))
     p=s.top-2;
     else
     p=s.top-1;
  if(string[i]=='$'&&*p=='$')
  {
   cout<<"输入串是文法的一个句子"<<endl;
      return 0;
  }
  else
  {
   for(b=0;b<8;b++)
   {
    if(a[b].t==*p)
    {
     z++;
     y=a[b].number;
    }
    else
     if(a[b].t==string[b])
     {
      z++;
      x=a[b].number;
     }
    if(z==2)
     break;
   }
   if(data[x][y]==1||data[x][y]==0)
   {
    push(s,string[i]);
    i++;
    p=s.top-1;
   }
   else
    if(data[x][y]==-1)
    {
     p--;
     if(!feizhongjie(*p))
     {
      p++;
      guiyue(s,p);
      i++;
     }
        else
     {
      guiyue(s,p);
         i++;
     }
    }
    else
     return -1;
  }

 }while(1);
}

这个程序错哪里

09-09

程序编译运行无错,结果却不对。rn#include rn#include rn#define num 100rntypedef char DataType;rntypedef struct node rnDataType data;rnstruct node *lchild,*rchild;rnBinTNode;rntypedef BinTNode * BinTree;rnint found;rnBinTNode *p;rnBinTree CreateBinTree(BinTree bt)rnrnBinTNode * Q[num];rnBinTNode * s;rnint front ,rear;rnchar ch;rnch=getchar();bt=NULL;rnfront=1;rear=0;rnwhile(ch!='#')rns=NULL;rnif(ch!='@')rns=(BinTNode *)malloc(sizeof(BinTNode));rns->data=ch;rns->lchild=s->rchild=NULL;rnrnrear++;rnQ[rear]=s;rnif(rear==1)rnbt=s;rnelsernrnif(s!=NULL && Q[front]!=NULL)rnif(rear % 2==0)rnQ[front]->lchild=s;rnelsernQ[front]->rchild=s;rnif(rear % 2 !=0)rnfront ++;rnrnch=getchar();rnrnreturn bt;rnrnvoid Preorder(BinTree bt)rnrnBinTNode * stack[num];rnint top=0;rnBinTNode * s;rnstack[top]=bt;rnwhile(top>=0)rnrns=stack[top];rntop--;rnif(s!=NULL)rn printf("%c",s->data);rntop++;rnstack[top]=s->rchild;rntop++;rnstack[top]=s->lchild;rnrnrnrnvoid Inorder(BinTree bt)rnrnBinTNode * stack[num];rnint top=0;rnstack[top]=bt;rndornrnwhile(stack[top]!=NULL)rnrntop=top+1;rnstack[top]=stack[top-1]->lchild;rnrntop=top-1;rnif(top>=0)rnrnprintf("%c",stack[top]->data);rnstack[top]=stack[top]->rchild;rnrnwhile(top>=0);rnrnvoid Postorder(BinTree bt)rnrnBinTNode * stack[num];rnint tag[num];rnint top;rnBinTNode * s;rntop=0;rns=bt;rndornrnwhile(s!=NULL)rnrntop++;rnstack[top]=s;rntag[top]=0;rns=s->lchild;rnrnif(top>0)rnrns=stack[top];rnif(top>0)rnrnprintf("%c",stack[top]->data);rntop--;rns=stack[top];rnrnif(top>0)rnrnif(tag[top]!=1)rns=s->rchild;rntag[top]=1;rnrnelse s=NULL;rnrnrnwhile(top!=0);rnrnvoid main()rnrnBinTree bt;rnint xz=1;rnchar ch1;rnwhile(xz)rnprintf(" 二叉树的遍历 \n");rnprintf("================================\n");rnprintf(" 1.建立二叉树的存储结构 \n");rnprintf(" 2.求二叉树的前序遍历 \n");rnprintf(" 3.求二叉树的中序遍历 \n");rnprintf(" 4.求二叉树的后序遍历 \n");rnprintf(" 0.退 出 系 统 \n");rnprintf("================================\n");rnprintf(" 请 选 择 :0—4 ");rnscanf("%d",&xz);rnswitch(xz)rncase 1: printf("输入二叉树的按层结点值,用@表示空节点,#表示结束(按完全二叉树): \n");rnbt=CreateBinTree(bt);rnprintf("二叉树的链式存储结构建立完成! \n");rnbreak;rncase 2: printf("该二叉树的前序遍历序列为: ");rnPreorder(bt);rnprintf("\n");rnbreak;rncase 3: printf("该二叉树的中序遍历序列是 ");rnInorder(bt);rnprintf("\n");rnbreak;rncase 4: printf("该二叉树的后序遍历序列是 ");rnPostorder(bt);rnprintf("\n");rnbreak;rncase 0: return;rnrnrn

这个程序错在了哪里

08-17

一个简单的窗口程序,编译时都正确,可是连接就出了错误,如下两个,而且不指明我错在了那里。rn(1)LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _mainrn(2)Debug/test.exe : fatal error LNK1120: 1 unresolved externalsrn源文件如下:rnrn#includernLRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);rnint APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,rn LPSTR lpCmdLine,int nCmdShow)rnrn WNDCLASS wndclass;rn HWND hwnd;rn MSG msg;rn //定义窗口类rn wndclass.style=CS_HREDRAW|CS_VREDRAW;rn wndclass.lpfnWndProc=WndProc;rn wndclass.cbClsExtra=0;rn wndclass.cbWndExtra=0;rn wndclass.hInstance=hInstance;rn wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);rn wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);rn wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);rn wndclass.lpszMenuName=NULL;rn wndclass.lpszClassName="Ctest";rn if(!RegisterClass(&wndclass)) return FALSE;rn //定义窗口rn hwnd=CreateWindow("Ctest",rn "test",rn WS_OVERLAPPEDWINDOW,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn NULL,rn NULL,rn hInstance,rn NULL);rn ShowWindow(hwnd,nCmdShow);rn UpdateWindow(hwnd);rn //消息循环rn while (GetMessage(&msg,NULL,0,0))rn rn TranslateMessage(&msg);rn DispatchMessage(&msg);rn rn return msg.wParam;rnrnrnLRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)rnrn switch(message)rn rn case WM_PAINT:rn HDC hdc;rn PAINTSTRUCT ps;rn hdc=BeginPaint(hwnd,&ps);rn TextOut(hdc,0,0,"This is a Windows example.",26);rn EndPaint(hwnd,&ps);rn return 0;rn case WM_DESTROY:rn PostQuitMessage(0);rn return 0;rn rn return DefWindowProc(hwnd,message,wParam,lParam);rn

这个是错哪里

10-28

#includern#include /*把输入输出函数的头文件包含进来*/rn#include rnint x=10, y=10; /*定义两整型的变量来表示主角坐标*/rnint i, j;rnint map[15][15]=rnrn1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,rn ;rnvoid draw(int x,int y) /*加一个*/rnrnclrscr (); /*函数清屏*/rn for(i=0;i<15;i++)rn for(j=0;j<15;j++)rnrn if(map[i][j]==1)rn rn gotoxy(x+1, y+1);rn printf("%c" ,3);rn rnrngotoxy(x, y);/*把光标移到指定的坐标*/rnprintf("%c" ,2); /* 在指定的坐标显示字符*/rnrnvoid main() /*程序*/rnrnrnrnrndraw(x,y) ;rnwhile ("")/*等待按键*/rnrnswitch (bioskey(0) ) /*对变量key的值进行判断*/rnrnrnrnrncase 18432: /*如果按的是向上键*/rny-=1 ;rndraw(x,y);rn break; /*让物体向上运动,并退出switch*/rnrncase 20480: /*如果按的是向下键*/rny+=1 ;rndraw(x,y) ;rnbreak; /*让物体向下运动,并退出switch*/ rncase 19200: /*向左键*/rnx-=1 ;rndraw(x,y);rn break;;/*向左运动*/ rncase 19712: /*向右键*/rnx+=1 ;rn draw(x,y);rn break;/*向右运动*/rnrnrnrnrnrnrn为什么心和笑脸是同时移动的,我设心的个楼显示不对

这个空指针异常错在哪里

06-20

[code=Java]rn2009-6-20 9:54:29 org.apache.catalina.core.AprLifecycleListener lifecycleEventrn信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_06\bin;C:\Program Files\Apache Software Foundation\Tomcat 5.5\binrn2009-6-20 9:54:30 org.apache.coyote.http11.Http11BaseProtocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2009-6-20 9:54:30 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 844 msrn2009-6-20 9:54:30 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2009-6-20 9:54:30 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/5.5.23rn2009-6-20 9:54:30 org.apache.catalina.core.StandardHost startrn信息: XML validation disabledrnlog4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).rnlog4j:WARN Please initialize the log4j system properly.rn[color=#FF0000]java.lang.NullPointerException[/color]rn2009-6-20 9:54:36 org.apache.coyote.http11.Http11BaseProtocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2009-6-20 9:54:36 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2009-6-20 9:54:36 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/31 config=nullrn2009-6-20 9:54:36 org.apache.catalina.storeconfig.StoreLoader loadrn信息: Find registry server-registry.xml at classpath resourcern2009-6-20 9:54:36 org.apache.catalina.startup.Catalina startrn信息: Server startup in 6921 msrnrn[/code]

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭