RRTBL.Cpp
资源名称:ictprop.rar [点击查看]
上传用户:tenhai
上传日期:2021-02-19
资源大小:492k
文件大小:2k
源码类别:
组合框控件
开发平台:
Visual C++
- #include "stdafx.h"
- #include "error.h"
- #include "symbol.h"
- #include "symbtbl.h"
- #include "grmrgrph.h"
- #include "rrtbl.h"
- unsigned int *rolestring;
- unsigned int *postfixstring;
- int rrready;
- rr_tbl_entry_t *rr_tbl;
- expecini(void){
- rolestring=(unsigned int *)calloc(arccount+2, sizeof(unsigned int));
- postfixstring=(unsigned int *)calloc(arccount+2, sizeof(unsigned int));
- return 0;
- }
- expecrelease(void){
- free(rolestring);
- free(postfixstring);
- rolestring=NULL;
- postfixstring=NULL;
- return 0;
- }
- rrini(void){
- int scan, totaldim=tcount*(tntcount-1);
- EGEN
- ((rr_tbl=(rr_tbl_entry_t *)
- calloc(totaldim, sizeof(rr_tbl_entry_t)))==NULL, MEMFUL, return -1;)
- for (scan=0;scan<totaldim;scan++){
- rr_tbl[scan].lrr=NULL;
- rr_tbl[scan].rrr=NULL;
- }
- return 0;
- }
- rrrelease(void){
- int scan, totaldim=tcount*(tntcount-1);
- rulrol_struct *prr, *qrr;
- if (rr_tbl==NULL)
- return 0;
- for (scan=0;scan<totaldim;scan++){
- for (prr=rr_tbl[scan].lrr;prr!=NULL;prr=qrr){
- qrr=prr->nxt;
- free(prr);
- }
- for (prr=rr_tbl[scan].rrr;prr!=NULL;prr=qrr){
- qrr=prr->nxt;
- free(prr);
- }
- rr_tbl[scan].lrr=NULL;
- rr_tbl[scan].rrr=NULL;
- }
- free(rr_tbl);
- rr_tbl=NULL;
- return 0;
- }
- listrr(void){
- unsigned int term, sym, totalsym=tntcount-1;
- for (term=0; term<tcount; term++){
- for (sym=0; sym<totalsym; sym++){
- rr_tbl_entry_t rr_tbl_entry=rr_tbl[term*totalsym+sym];
- rulrol_struct *prr;
- printf("( %s, %s ):n",
- sym>=(tcount-1)?
- code2ntnode(sym+1)->literal:
- code2tnode(sym+1)->literal,
- code2tnode(term)->literal);
- printf("lrr:");
- for (prr=rr_tbl_entry.lrr;prr!=NULL;prr=prr->nxt)
- printf("%d.%d %s%d/", prr->rule, prr->role,
- prr->expmode=='s'?"shift":"reduce",
- prr->expsymb);
- printf("n");
- printf("rrr:");
- for (prr=rr_tbl_entry.rrr;prr!=NULL;prr=prr->nxt)
- printf("%d.%d %s%d/", prr->rule, prr->role,
- prr->expmode=='s'?"shift":"reduce",
- prr->expsymb);
- printf("n");
- }
- printf("################################################n");
- }
- return 0;
- }