#if STATISTICS int iterationcount = 0; int itemlistcount; int notviable = 0; int search = 0; int nosearch = 0; int nosearch_b = 0; int nosearch_h = 0; /* no_search == 1: *noneedtocallSEARCHbecausenoitemwithsamehashcode
*/ int foundsame = 0; int foundnew = 0; int completerstep = 0; int truecompleterstep = 0; int calls_additem = 0; int itemsadded = 0; int rules_rej = 0; /* rules rejected by 'lookup_dirset' (predictor) */ int tokens_rej = 0; /* tokens rejected by 'is_viable' (kernel/completer) */ int nonterms_rej = 0; /* nonterms rejected by 'is_viable' (kernel/completer) */
int GOOD = 0; /* number of items with dot preceeding a token */ /* that contribute to the next kernel */ int BAD = 0; /* number of items with dot preceeding a token */ /* that don't contribute to the next kernel */ #endif
PRIVATE print_item(p) int p; /* *printtheitemwithindexp
*/
{ int i, b, e, l, k;
i = dot[p];
printf(" %d: ", p); if (dot[p] == 0 && sub[p] == 0) {
printf("[ separator-item ]\n"); return;
} if (i <= 5) {
b = 1;
} else {
b = i-1; while(yygrammar[b] >= 0) b--;
b += 2;
} /* b points to the start of the rule */
e = i; while(yygrammar[e] >= 0) e++; /* e points to the end of the rule, i.e. the lhscode */
l = - yygrammar[e]; /* l is the lhs */
printf("%s :", yyprintname(l));
k = b+1; /* k points to the first member */ while(yygrammar[k] > 0) { if (k == i) printf(" *"); /* print member yygrammar[k] */ if (yygrammar[k] == eofsym) {
printf(" <EOF>");
} elseif (yygrammar[k] > term_base) { if (yygrammar[k] < term_base+max_char+1) {
printf(" '%c'", yygrammar[k]-term_base);
} else
printf(" %s", yyprintname(yygrammar[k]));
} else {
printf(" %s", yyprintname(yygrammar[k]));
}
k++;
} if (yygrammar[i] <= 0) printf(" *");
printf(" (back:%d sub:%d left:%d)\n", back[p], sub[p], left[p]);
}
PRIVATE print_coordinate(i) int i; /* *printsourcecoordinate(ofgrammarfile)withcodei *thenumberencodesboth,lineandcolumninformation
*/
{ int pos = yycoordinate[i]; int l = pos / 1000; int c = pos % 1000;
PRIVATE print_tree(i) int i; /* *printtreeforitemwithindexi
*/
{ staticint indent = 0; int k;
/* rule number if item at end of rule */ if (yygrammar[dot[i]] < 0 ) { /* end of rule */ for (k = 1; k <= indent; k++) printf(" ");
printf("%s alternative at ", yyprintname(-yygrammar[dot[i]]));
print_coordinate(dot[i]+1);
printf(" {\n");
indent++;
}
/* left brothers */
if (left[i]) print_tree(left[i]);
/* this son */
if (left[i]) { int sym = yygrammar[dot[i]-1];
if (sym > term_base) { for (k = 1; k <= indent; k++) printf(" "); if (sym < term_base+max_char+1)
printf("'%c'\n", yygrammar[dot[i]-1]-term_base); else
printf("%s\n", yyprintname(sym));
}
}
/* subtree for this son */
if (sub[i]) print_tree(sub[i]);
if (yygrammar[dot[i]] < 0 ) { /* end of rule */
indent--; for (k = 1; k <= indent; k++) printf(" ");
printf("}\n");
}
}
/*============================================================================*/ /* DIRECTOR SETS */ /*============================================================================*/
PRIVATEint lookup_dirset(ruleptr) long ruleptr; /* *Let'rule'betherulebetheruleintowhich'ruleptr'points. *Let'tkn'bethecodeofthenexttoken. *Return('tkn'isinthedirectorsetof'rule').
*/
{ int p; int rule; int tkn;
/* find rule number */
p = ruleptr; while (yygrammar[p] >= 0) p++;
p++;
rule = yygrammar[p];
start = yygrammar[d]; /* start points to the first rule for the nonterm */ do { int p; int rule;
p = start+1; while (yygrammar[p] >= 0) {
p++;
} /* p now points to negative lhs encoding */
rule = yygrammar[p+1]; if (yydirset(rule, lookaheadsym-term_base)) { return1;
}
start = yygrammar[start];
} while (start);
/* subptr points to an item */ /* return the prio of corresponding rule */
{ int i;
/* find end of rule */
i = dot[subptr]; while (yygrammar[i] > 0) i++; /* i points to the negative lhs encoding */
i++; /* i now points to the rule number, this is also the index of the prio */
PRIVATEint test_for_cycle(subtree, container) int subtree; int container; /* *returntrueif *thetreetowhich'container'(a"subpointer"ofanitem)points *containsthetreetowhich'subtree'(alsoa"subpointer")points
*/
{ if (container < subtree) { /* an earlier item cannot refer a later one */ return0;
} if (container == subtree) { return1;
} if (sub[container]) { if (test_for_cycle(subtree, sub[container])) return1;
} if (left[container]) { if (test_for_cycle(subtree, left[container])) return1;
} return0;
}
{ int k;
k = dot[i]; while (yygrammar[k] > 0) k++;
printf("There are two different parses\n");
printf("for the beginning of ``%s'', alternative at ",
yyprintname(-yygrammar[k]));
print_coordinate(k+1);
printf(",\n");
}
printf("upto and containing ``%s'' at ", yyprintname(yygrammar[d-1]));
print_coordinate(d-1);
printf(".\n");
printf("\n");
printf("For ``%s'' at ", yyprintname(yygrammar[d-1]));
print_coordinate(d-1);
printf(",\n"); if (left1 > left2) {
printf("use %%short annotation to select first parse,\n");
printf("use %%long annotation to select second parse.\n");
} else {
printf("use %%long annotation to select first parse,\n");
printf("use %%short annotation to select second parse.\n");
}
printf("\nEND OF GRAMMAR DEBUG INFORMATION\n\n");
yyerror("source text uncovers unhandled grammar ambiguity"); exit(1);
printf("\n");
printf("GRAMMAR DEBUG INFORMATION\n");
printf("\n");
printf("Grammar ambiguity detected.\n");
printf
("Two different ``%s'' derivation trees for the same phrase.\n",
yyprintname(yygrammar[d-1]));
if (test_for_cycle(s, sub[i])) { /* not possible */
printf("Tree 1 contains tree 2 as subtree.\n");
printf
("Use %%prio annotation to select the second tree.\n");
printf("An annotation selecting the first tree\n");
printf("would not resolve the ambiguity.\n");
} elseif (test_for_cycle(sub[i], s)) {
printf("Tree 2 contains tree 1 as subtree.\n");
printf
("Use %%prio annotation to select the first tree.\n");
printf("An annotation selecting the second tree\n");
printf("would not resolve the ambiguity.\n");
} else {
printf("Use %%prio annotation to select an alternative.\n");
}
printf("\nEND OF GRAMMAR DEBUG INFORMATION\n\n");
yyerror("source text uncovers unhandled grammar ambiguity"); exit(1);
} elseif (prio1 > prio2) { #if TRACE
printf("old value wins\n"); #endif
} else { #if TRACE
printf("new value wins\n");
printf("sub[%d] was %d\n", i, sub[i]);
printf("sub[%d] becomes %d\n", i, s); #endif
#if DYNAMICCYCLECHECK if (s >= i) { if (test_for_cycle(i, s)) {
printf("\n");
printf("GRAMMAR DEBUG INFORMATION\n");
printf("\n");
printf("Annotation for ``%s'' allows cyclic derivation.\n",
yyprintname(yygrammar[d-1]));
printf("\nEND OF GRAMMAR DEBUG INFORMATION\n\n");
yyerror("source text uncovers unhandled grammar ambiguity"); exit(1);
}
} #endif
sub[i] = s;
}
}
#if HASHING if (! hashed(d, b)) { #if STATISTICS
nosearch_h++; #endif #if BIGHASH
DHITS[d] = thislist;
BHITS[b] = thislist; #endif
last_item++; if (last_item==(ITEMLIMIT-2)) table_full();
sethash(d, b);
} else { #endif #if BIGHASH if (DHITS[d] == thislist) { /* there may be already an item with code d */ if (BHITS[b] == thislist) { /* there may be already an item with code b */ #if STATISTICS
search++; #endif
SEARCH(d, b, l, s);
} else
{ /* no search necessary: no item with code b entered til now */
#if STATISTICS
nosearch_b++; #endif
BHITS[b] = thislist;
last_item++; if (last_item==(ITEMLIMIT-2)) table_full(); #if HASHING
sethash(d, b); #endif
}
} else { /* no search necessary: no item with code d entered til now */
PUBLICint yyselect() /* *returnthenextrulenumber(fortheleft-derivation) * *thisfunctioniscalledbythegeneratedtreewalker * *thestackalwayscontainspointerstoitemsthatstillmustbeprocessed *toproducealeft-derivation *thetopelementmustbeprocessedfirst *ifthedotappearsinsidearule *M:alphaN*beta *thentheitemsrepresentingtheparseforbetaarealreadyonthestack *andtheitemsrepresentingalphaNmustbepushed *theyarerepresentedbythesubpointeroftheitem *(correspondingtotheparseforN) *andtheleftpointeroftheitem *(correspondingtotheparseforalpha) *iftheitemhastheform *M:gamma* *(i.e.therulehasbeencompleted) *firsttheitemsrepresentinggammaarepushed *thentherulenumberisreturned *subsequentcallswillprocesstheitems *representinggamma *
*/
{ int i; while (1) {
i = pop(); if (sub[i]) push(sub[i]); if (left[i]) push(left[i]); if (yygrammar[dot[i]] < 0 ) { return yygrammar[dot[i]+1];
}
}
}
/*============================================================================*/ /* MAIN FUNCTION YYPARSE */ /*============================================================================*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.