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