fix derpy bugs in grammar analysis
This commit is contained in:
parent
b28d82bdeb
commit
cd4ce77bec
1 changed files with 9 additions and 13 deletions
|
|
@ -151,7 +151,7 @@ bool h_sequence_derives_epsilon(HCFGrammar *g, HCFChoice **s)
|
||||||
/* Populate the geneps member of g; no-op if called multiple times. */
|
/* Populate the geneps member of g; no-op if called multiple times. */
|
||||||
static void collect_geneps(HCFGrammar *g)
|
static void collect_geneps(HCFGrammar *g)
|
||||||
{
|
{
|
||||||
if(g->geneps == NULL)
|
if(g->geneps != NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g->geneps = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr);
|
g->geneps = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr);
|
||||||
|
|
@ -160,8 +160,9 @@ static void collect_geneps(HCFGrammar *g)
|
||||||
// iterate over the grammar's symbols, the elements of g->nts.
|
// iterate over the grammar's symbols, the elements of g->nts.
|
||||||
// add any we can identify as deriving epsilon to g->geneps.
|
// add any we can identify as deriving epsilon to g->geneps.
|
||||||
// repeat until g->geneps no longer changes.
|
// repeat until g->geneps no longer changes.
|
||||||
size_t prevused = g->nts->used;
|
size_t prevused;
|
||||||
do {
|
do {
|
||||||
|
prevused = g->geneps->used;
|
||||||
size_t i;
|
size_t i;
|
||||||
HHashTableEntry *hte;
|
HHashTableEntry *hte;
|
||||||
for(i=0; i < g->nts->capacity; i++) {
|
for(i=0; i < g->nts->capacity; i++) {
|
||||||
|
|
@ -178,13 +179,13 @@ static void collect_geneps(HCFGrammar *g)
|
||||||
HCFSequence **p;
|
HCFSequence **p;
|
||||||
for(p = symbol->seq; *p != NULL; p++) {
|
for(p = symbol->seq; *p != NULL; p++) {
|
||||||
if(h_sequence_derives_epsilon(g, (*p)->items)) {
|
if(h_sequence_derives_epsilon(g, (*p)->items)) {
|
||||||
h_hashset_put(g->nts, symbol);
|
h_hashset_put(g->geneps, symbol);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while(g->nts->used != prevused);
|
} while(g->geneps->used != prevused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -403,16 +404,11 @@ static void pprint_sequence(FILE *f, const HCFGrammar *g, const HCFSequence *seq
|
||||||
while(*x) {
|
while(*x) {
|
||||||
fputc(' ', f); // separator
|
fputc(' ', f); // separator
|
||||||
|
|
||||||
switch((*x)->type) {
|
if((*x)->type == HCF_CHAR) {
|
||||||
case HCF_CHAR:
|
// condense character strings
|
||||||
x = pprint_string(f, x);
|
x = pprint_string(f, x);
|
||||||
break;
|
} else {
|
||||||
case HCF_END:
|
pprint_symbol(f, g, *x);
|
||||||
fputc('$', f);
|
|
||||||
x++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fputs(nonterminal_name(g, *x), f);
|
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue