1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
#include <stdio.h>
#include <ctype.h>
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#ifdef __USE_PROTOS
void dumpset1(set s)
#else
void dumpset1(s)
set s;
#endif
{
if (set_nil(s)) {
fprintf(stderr,"{}");
} else {
s_fprT(stderr,s);
};
}
#ifdef __USE_PROTOS
void dumpset(set s)
#else
void dumpset(s)
set s;
#endif
{
dumpset1(s);
fprintf(stderr,"\n");
}
#ifdef __USE_PROTOS
int isEndRule(Node * p)
#else
int isEndRule(p)
Node * p;
#endif
{
int result=0;
if ( p->ntype == nJunction &&
( (Junction *) p)->jtype == EndRule) {
result=1;
};
return result;
}
#ifdef __USE_PROTOS
void dumppred1(int depth,Predicate *p)
#else
void 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_PROTOS
void dumppred(Predicate *p)
#else
void dumppred(p)
Predicate *p;
#endif
{
fprintf(stderr,"---------------------------------\n");
dumppred1(0,p);
fprintf(stderr,"\n");
}
#ifdef __USE_PROTOS
void dumppredtree(Predicate *p)
#else
void 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_PROTOS
void dumppredexpr(Predicate *p)
#else
void dumppredexpr(p)
Predicate *p;
#endif
{
fprintf(stderr," pred expr \"%s\"\n",p->expr);
}
#ifdef __USE_PROTOS
void dt(Tree *t)
#else
void dt(t)
Tree *t;
#endif
{
MR_dumpTreeF(stderr,0,t,5);
}
#ifdef __USE_PROTOS
void d(Node * p)
#else
void 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_PROTOS
Node * dp1(Node * p)
#else
Node * 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_PROTOS
Node * dp2(Node * p)
#else
Node * 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_PROTOS
Node * dn(Node * p)
#else
Node * 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_PROTOS
void df(Node * p)
#else
void 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_PROTOS
Node * dfn(Node * p,int target)
#else
Node * 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 __USE_PROTOS
Junction *findnode1(Node *n)
#else
Junction *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 __USE_PROTOS
Junction *findnode(int match)
#else
Junction *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;
}
|