⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dumpnode.c

📁 本工具提供一个词法分析器和语法分析器的集成开发环境
💻 C
字号:
#include <stdio.h>#include <ctype.h>#include "set.h"#include "syn.h"#include "hash.h"#include "generic.h"extern char *PRED_AND_LIST;extern char *PRED_OR_LIST;#ifdef __USE_PROTOSvoid dumpset1(set s)#elsevoid dumpset1(s)  set   s;#endif{  if (set_nil(s)) {    fprintf(stderr,"{}");  } else {    s_fprT(stderr,s);  };}#ifdef __USE_PROTOSvoid dumpset(set s)#elsevoid dumpset(s)  set   s;#endif{  dumpset1(s);  fprintf(stderr,"\n");}#ifdef __USE_PROTOSint isEndRule(Node * p)#elseint isEndRule(p)  Node *    p;#endif{  int       result=0;  if ( p->ntype == nJunction &&       ( (Junction *) p)->jtype == EndRule) {    result=1;  };  return result;}#ifdef __USE_PROTOSvoid dumppred1(int depth,Predicate *p)#elsevoid dumppred1(depth,p)  int           depth;  Predicate     *p;#endif{  int       i;  int       k;  for (i=0; i<depth ; i++) {    fprintf(stderr,"  ");  };  if (p->expr == PRED_AND_LIST ||      p->expr == PRED_OR_LIST) {    fprintf(stderr," %s", (p->expr == NULL ? "null expr" : p->expr));    if (p->inverted) fprintf(stderr," predicate inverted !");    if (p->redundant) {      fprintf(stderr," Redundant!");    };    if (p->isConst) fprintf(stderr," const %d !",p->constValue);    fprintf(stderr,"\n");  } else {    fprintf(stderr,"predicate k=%d",p->k);    k=set_int(p->completionSet);    if (k >= 0) {      fprintf(stderr," Incomplete Set=%d !",k);    };    k=set_int(p->completionTree);    if (k >= 0) {      fprintf(stderr," Incomplete Tree=%d !",k);    };    if (p->redundant) {      fprintf(stderr," Redundant!");    };    fprintf(stderr," \"%s\" (%x)", (p->expr == NULL ? "null expr" : p->expr) ,p);    if (p->source != NULL) {       fprintf(stderr,"line %d",p->source->line);    };    if (p->inverted) fprintf(stderr," predicate inverted !");    fprintf(stderr,"\n");    for (i=0; i<depth ; i++) {      fprintf(stderr,"  ");    };    fprintf(stderr,"scontext: ");    dumpset(p->scontext[1]);    for (i=0; i<depth ; i++) {      fprintf(stderr,"  ");    };    fprintf(stderr,"tcontext: ");    preorder(p->tcontext);    fprintf(stderr,"\n");  };  fprintf(stderr,"\n");  if (p->down != NULL) {    dumppred1(depth+1,p->down);  };  if (p->right != NULL) {    dumppred1(depth,p->right);  };}#ifdef __USE_PROTOSvoid dumppred(Predicate *p)#elsevoid dumppred(p)  Predicate     *p;#endif{  fprintf(stderr,"---------------------------------\n");  dumppred1(0,p);  fprintf(stderr,"\n");}#ifdef __USE_PROTOSvoid dumppredtree(Predicate *p)#elsevoid dumppredtree(p)  Predicate     *p;#endif{  fprintf(stderr,"predicate k=%d \"%s\" line %d\n",p->k,p->expr,p->source->line);  dumpset(p->scontext[1]);}#ifdef __USE_PROTOSvoid dumppredexpr(Predicate *p)#elsevoid dumppredexpr(p)  Predicate     *p;#endif{  fprintf(stderr,"    pred expr \"%s\"\n",p->expr);}#ifdef __USE_PROTOSvoid dt(Tree *t)#elsevoid dt(t)  Tree  *t;#endif{  MR_dumpTreeF(stderr,0,t,5);}#ifdef __USE_PROTOSvoid d(Node * p)#elsevoid d(p)  Node *    p;#endif{  Junction      *j;  RuleRefNode   *r;  TokNode       *t;  ActionNode    *a;  if (p==NULL) {    fprintf(stderr,"dumpNode: Node is NULL");    return;  };  switch (p->ntype) {    case nJunction :      j = (Junction *) p;      fprintf(stderr, "Junction (#%d in rule %s line %d) ",j->seq,j->rname,j->line);      if (j->guess) fprintf(stderr,"guess block ");      switch (j->jtype ) {        case aSubBlk :          fprintf(stderr,"aSubBlk");          break;        case aOptBlk :          fprintf(stderr,"aOptBlk");          break;        case aLoopBegin :          fprintf(stderr,"aLoopBeginBlk");          break;        case aLoopBlk :          fprintf(stderr,"aLoopBlk");          break;        case aPlusBlk :          fprintf(stderr,"aPlusBlk");          break;        case EndBlk :          fprintf(stderr,"EndBlk");          break;        case RuleBlk :          fprintf(stderr,"RuleBlk");          break;        case Generic :          fprintf(stderr,"Generic");          break;        case EndRule :          fprintf(stderr,"EndRule");          break;      };      if (j->halt) fprintf(stderr,"  halt!");      if (j->p1) fprintf(stderr," p1 valid");      if (j->p2) {        if (j->p2->ntype == nJunction) {           fprintf(stderr," (p2=#%d)",( (Junction *) j->p2)->seq);        } else {           fprintf(stderr," (p2 valid)");        };      };      if (j->fset != NULL && set_deg(*j->fset) != 0) {         fprintf(stderr,"\nfset:\n");         dumpset(*j->fset);      };      if (j->ftree != NULL) {         fprintf(stderr,"\nftree:\n");         preorder(j->ftree);      };      fprintf(stderr,"\n");      break;    case nRuleRef :       r = (RuleRefNode *) p;       fprintf(stderr, "RuleRefNode (in rule %s line %d) to rule %s\n", r->rname,r->line,r->text);       break;    case nToken :       t = (TokNode *) p;       fprintf(stderr, "TokNode (in rule %s line %d) token %s\n",t->rname,t->line,TerminalString(t->token));       break;    case nAction :       a =(ActionNode *) p;       if (a->is_predicate) {         fprintf(stderr, "Predicate (in rule %s line %d) %s",a->rname,a->line,a->action);         if (a->inverted) fprintf(stderr," action inverted !");         if (a->guardpred != NULL) {           fprintf(stderr," guarded");           dumppredexpr(a->guardpred);           if (a->ampersandPred) {             fprintf(stderr," \"&&\" style");           } else {             fprintf(stderr," \"=>\" style");           };         };         if (a->predEntry != NULL) fprintf(stderr," predEntry \"%s\" ",a->predEntry->str);         fprintf(stderr,"\n");       } else if (a->init_action) {         fprintf(stderr, "Init-Action (in rule %s line %d) %s\n",a->rname,a->line,a->action);       } else {         fprintf(stderr, "Action (in rule %s line %d) %s\n",a->rname,a->line,a->action);       };       break;   };}#ifdef __USE_PROTOSNode * dp1(Node * p)#elseNode * dp1(p)  Node *    p;#endif{  Node  *result=NULL;  if (p->ntype == nJunction) {    result=( (Junction *) p )->p1;    d(result);  } else {    fprintf(stderr,"dp1: Not a Junction node");  };  return result;}#ifdef __USE_PROTOSNode * dp2(Node * p)#elseNode * dp2(p)  Node *    p;#endif{  Node  *result=NULL;  if (p->ntype == nJunction) {    result=( (Junction *) p )->p2;    d(result);  } else {    fprintf(stderr,"dp2: Not a Junction node");  };  return result;}#ifdef __USE_PROTOSNode * dn(Node * p)#elseNode * dn(p)  Node *    p;#endif{  Node  *result=NULL;  if (p->ntype == nRuleRef) {    result=( (RuleRefNode *)p )->next;  } else if (p->ntype == nAction) {    result=( (ActionNode *)p )->next;  } else if (p->ntype == nToken) {    result=( (TokNode *)p )->next;  } else {    fprintf(stderr,"No next field: Neither a RuleRefNode, ActionNode, nor TokNode");  };  if (result != NULL) d(result);  return result;}#ifdef __USE_PROTOSvoid df(Node * p)#elsevoid df(p)  Node *    p;#endif{  int       count=0;  Node      *next;  fprintf(stderr,"#%d ",++count);  d(p);  for (next=p; next != NULL && !isEndRule(next) ; ) {    fprintf(stderr,"#%d ",++count);    if (next->ntype == nJunction) {      next=dp1(next);    } else {      next=dn(next);    };  };}#ifdef __USE_PROTOSNode * dfn(Node * p,int target)#elseNode * dfn(p,target)  Node *    p;  int       target;#endif{  Node      *result=NULL;  int       count=0;  Node      *next;  fprintf(stderr,"#%d ",++count);  d(p);  for (next=p; next != NULL && !isEndRule(next) ; ) {    fprintf(stderr,"#%d ",++count);    if (next->ntype == nJunction) {      next=dp1(next);    } else {      next=dn(next);    };    if (count == target) {      result=next;      break;    };  };  return result;}static int findnodeMatch;#ifdef __STDC__Junction *findnode1(Node *n)#elseJunction *findnode1(n)  Node  *n;#endif{   Node         *next;   Junction     *j;   Junction     *match;   if (n == NULL) return NULL;   if (n->ntype == nJunction) {     j=(Junction *) n;     if (j->seq == findnodeMatch) return j;     if (j->jtype == EndRule) return NULL;     if (j->jtype != RuleBlk && j->jtype != EndBlk) {       if (j->p2 != NULL && !j->ignore) {          match=findnode1(j->p2);          if (match != NULL) return match;       };     };   };   next=MR_advance(n);   return findnode1(next);}#ifdef __STDC__Junction *findnode(int match)#elseJunction *findnode(match)  int   match;#endif{  Junction  *j;  Junction  *result=NULL;  findnodeMatch=match;  for (j=SynDiag; j != NULL; j=(Junction *)j->p2) {    require (j->ntype == nJunction && j->jtype == RuleBlk,"Not a rule block");    result=findnode1( (Node *) j);    if (result != NULL) break;  };  if (result != NULL) {    d( (Node *) result);  };  return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -