split out h_pprint_lr_info for debugging purposes
This commit is contained in:
parent
42d35fb883
commit
ff55937e00
3 changed files with 40 additions and 29 deletions
|
|
@ -355,8 +355,6 @@ HParserBackendVTable h__lalr_backend_vtable = {
|
||||||
// dummy!
|
// dummy!
|
||||||
int test_lalr(void)
|
int test_lalr(void)
|
||||||
{
|
{
|
||||||
HAllocator *mm__ = &system_allocator;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
E -> E '-' T
|
E -> E '-' T
|
||||||
| T
|
| T
|
||||||
|
|
@ -371,44 +369,24 @@ int test_lalr(void)
|
||||||
h_bind_indirect(E, E_);
|
h_bind_indirect(E, E_);
|
||||||
HParser *p = E;
|
HParser *p = E;
|
||||||
|
|
||||||
printf("\n==== G R A M M A R ====\n");
|
HCFGrammar *g = h_pprint_lr_info(stdout, p);
|
||||||
HCFGrammar *g = h_cfgrammar_(mm__, h_desugar_augmented(mm__, p));
|
if(!g)
|
||||||
if (g == NULL) {
|
|
||||||
fprintf(stderr, "h_cfgrammar failed\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
h_pprint_grammar(stdout, g, 0);
|
|
||||||
|
|
||||||
printf("\n==== D F A ====\n");
|
fprintf(stdout, "\n==== L A L R T A B L E ====\n");
|
||||||
HLRDFA *dfa = h_lr0_dfa(g);
|
|
||||||
if (dfa) {
|
|
||||||
h_pprint_lrdfa(stdout, g, dfa, 0);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "h_lalr_dfa failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n==== L R ( 0 ) T A B L E ====\n");
|
|
||||||
HLRTable *table0 = h_lr0_table(g, dfa);
|
|
||||||
if (table0) {
|
|
||||||
h_pprint_lrtable(stdout, g, table0, 0);
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "h_lr0_table failed\n");
|
|
||||||
}
|
|
||||||
h_lrtable_free(table0);
|
|
||||||
|
|
||||||
printf("\n==== L A L R T A B L E ====\n");
|
|
||||||
if (h_compile(p, PB_LALR, NULL)) {
|
if (h_compile(p, PB_LALR, NULL)) {
|
||||||
fprintf(stderr, "does not compile\n");
|
fprintf(stdout, "does not compile\n");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
h_pprint_lrtable(stdout, g, (HLRTable *)p->backend_data, 0);
|
h_pprint_lrtable(stdout, g, (HLRTable *)p->backend_data, 0);
|
||||||
|
|
||||||
printf("\n==== P A R S E R E S U L T ====\n");
|
fprintf(stdout, "\n==== P A R S E R E S U L T ====\n");
|
||||||
HParseResult *res = h_parse(p, (uint8_t *)"n-(n-((n)))-n", 13);
|
HParseResult *res = h_parse(p, (uint8_t *)"n-(n-((n)))-n", 13);
|
||||||
if (res) {
|
if (res) {
|
||||||
h_pprint(stdout, res->ast, 0, 2);
|
h_pprint(stdout, res->ast, 0, 2);
|
||||||
} else {
|
} else {
|
||||||
printf("no parse\n");
|
fprintf(stdout, "no parse\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -538,3 +538,35 @@ void h_pprint_lrtable(FILE *f, const HCFGrammar *g, const HLRTable *table,
|
||||||
fputc('\n', f);
|
fputc('\n', f);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HCFGrammar *h_pprint_lr_info(FILE *f, HParser *p)
|
||||||
|
{
|
||||||
|
HAllocator *mm__ = &system_allocator;
|
||||||
|
|
||||||
|
fprintf(f, "\n==== G R A M M A R ====\n");
|
||||||
|
HCFGrammar *g = h_cfgrammar_(mm__, h_desugar_augmented(mm__, p));
|
||||||
|
if (g == NULL) {
|
||||||
|
fprintf(f, "h_cfgrammar failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
h_pprint_grammar(f, g, 0);
|
||||||
|
|
||||||
|
fprintf(f, "\n==== D F A ====\n");
|
||||||
|
HLRDFA *dfa = h_lr0_dfa(g);
|
||||||
|
if (dfa) {
|
||||||
|
h_pprint_lrdfa(f, g, dfa, 0);
|
||||||
|
} else {
|
||||||
|
fprintf(f, "h_lalr_dfa failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "\n==== L R ( 0 ) T A B L E ====\n");
|
||||||
|
HLRTable *table0 = h_lr0_table(g, dfa);
|
||||||
|
if (table0) {
|
||||||
|
h_pprint_lrtable(f, g, table0, 0);
|
||||||
|
} else {
|
||||||
|
fprintf(f, "h_lr0_table failed\n");
|
||||||
|
}
|
||||||
|
h_lrtable_free(table0);
|
||||||
|
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,5 +143,6 @@ void h_pprint_lrdfa(FILE *f, const HCFGrammar *g,
|
||||||
const HLRDFA *dfa, unsigned int indent);
|
const HLRDFA *dfa, unsigned int indent);
|
||||||
void h_pprint_lrtable(FILE *f, const HCFGrammar *g, const HLRTable *table,
|
void h_pprint_lrtable(FILE *f, const HCFGrammar *g, const HLRTable *table,
|
||||||
unsigned int indent);
|
unsigned int indent);
|
||||||
|
HCFGrammar *h_pprint_lr_info(FILE *f, HParser *p);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue