RRTBL.Cpp
上传用户:tenhai
上传日期:2021-02-19
资源大小:492k
文件大小:2k
源码类别:

组合框控件

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "error.h"
  3. #include "symbol.h"
  4. #include "symbtbl.h"
  5. #include "grmrgrph.h"
  6. #include "rrtbl.h"
  7. unsigned int *rolestring;
  8. unsigned int *postfixstring;
  9. int rrready;
  10. rr_tbl_entry_t *rr_tbl;
  11. expecini(void){
  12.   rolestring=(unsigned int *)calloc(arccount+2, sizeof(unsigned int));
  13.   postfixstring=(unsigned int *)calloc(arccount+2, sizeof(unsigned int));
  14.   return 0;
  15. }
  16. expecrelease(void){
  17.   free(rolestring);
  18.   free(postfixstring);
  19.   rolestring=NULL;
  20.   postfixstring=NULL;
  21.   return 0;
  22. }
  23. rrini(void){
  24.   int scan, totaldim=tcount*(tntcount-1);
  25.   EGEN
  26.   ((rr_tbl=(rr_tbl_entry_t *)
  27.    calloc(totaldim, sizeof(rr_tbl_entry_t)))==NULL, MEMFUL, return -1;)
  28.   for (scan=0;scan<totaldim;scan++){
  29.       rr_tbl[scan].lrr=NULL;
  30.       rr_tbl[scan].rrr=NULL;
  31.   }
  32.   return 0;
  33. }
  34. rrrelease(void){
  35.   int scan, totaldim=tcount*(tntcount-1);
  36.   rulrol_struct *prr, *qrr;
  37.   if (rr_tbl==NULL)
  38.      return 0;
  39.   for (scan=0;scan<totaldim;scan++){
  40.      for (prr=rr_tbl[scan].lrr;prr!=NULL;prr=qrr){
  41.          qrr=prr->nxt;
  42.          free(prr);
  43.      }
  44.      for (prr=rr_tbl[scan].rrr;prr!=NULL;prr=qrr){
  45.          qrr=prr->nxt;
  46.          free(prr);
  47.      }
  48.      rr_tbl[scan].lrr=NULL;
  49.      rr_tbl[scan].rrr=NULL;
  50.   }
  51.   free(rr_tbl);
  52.   rr_tbl=NULL;
  53.   return 0;
  54. }
  55. listrr(void){
  56.   unsigned int term, sym, totalsym=tntcount-1;
  57.   for (term=0; term<tcount; term++){
  58.       for (sym=0; sym<totalsym; sym++){
  59.           rr_tbl_entry_t rr_tbl_entry=rr_tbl[term*totalsym+sym];
  60.           rulrol_struct *prr;
  61.         
  62.   printf("( %s, %s ):n", 
  63.           sym>=(tcount-1)?
  64.           code2ntnode(sym+1)->literal:
  65.           code2tnode(sym+1)->literal, 
  66.           code2tnode(term)->literal);
  67.           
  68.           printf("lrr:");
  69.           for (prr=rr_tbl_entry.lrr;prr!=NULL;prr=prr->nxt)
  70.                printf("%d.%d %s%d/", prr->rule, prr->role, 
  71.                       prr->expmode=='s'?"shift":"reduce", 
  72.                       prr->expsymb);
  73.           printf("n");
  74.           printf("rrr:");
  75.           for (prr=rr_tbl_entry.rrr;prr!=NULL;prr=prr->nxt)
  76.                printf("%d.%d %s%d/", prr->rule, prr->role, 
  77.                       prr->expmode=='s'?"shift":"reduce", 
  78.                       prr->expsymb);
  79.           printf("n");
  80.       }
  81.       printf("################################################n");
  82.   }
  83.   return 0;
  84. }