correctly use augmented grammar for test_glr() output

This commit is contained in:
Sven M. Hallberg 2013-06-21 23:53:47 +02:00
parent 34c6d868b9
commit 8bc3b93e95
3 changed files with 7 additions and 4 deletions

View file

@ -129,6 +129,8 @@ HParserBackendVTable h__glr_backend_vtable = {
// dummy! // dummy!
int test_glr(void) int test_glr(void)
{ {
HAllocator *mm__ = &system_allocator;
/* /*
E -> E '+' E E -> E '+' E
| 'd' | 'd'
@ -141,7 +143,7 @@ int test_glr(void)
HParser *p = E; HParser *p = E;
printf("\n==== G R A M M A R ====\n"); printf("\n==== G R A M M A R ====\n");
HCFGrammar *g = h_cfgrammar(&system_allocator, p); HCFGrammar *g = h_cfgrammar_(mm__, h_desugar_augmented(mm__, p));
if(g == NULL) { if(g == NULL) {
fprintf(stderr, "h_cfgrammar failed\n"); fprintf(stderr, "h_cfgrammar failed\n");
return 1; return 1;

View file

@ -207,7 +207,7 @@ static bool match_production(HLREnhGrammar *eg, HCFChoice **p,
// desugar parser with a fresh start symbol // desugar parser with a fresh start symbol
// this guarantees that the start symbol will not occur in any productions // this guarantees that the start symbol will not occur in any productions
static HCFChoice *augment(HAllocator *mm__, HParser *parser) HCFChoice *h_desugar_augmented(HAllocator *mm__, HParser *parser)
{ {
HCFChoice *augmented = h_new(HCFChoice, 1); HCFChoice *augmented = h_new(HCFChoice, 1);
@ -231,7 +231,7 @@ int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params)
// build LR(0) table // build LR(0) table
// if necessary, resolve conflicts "by conversion to SLR" // if necessary, resolve conflicts "by conversion to SLR"
HCFGrammar *g = h_cfgrammar_(mm__, augment(mm__, parser)); HCFGrammar *g = h_cfgrammar_(mm__, h_desugar_augmented(mm__, parser));
if(g == NULL) // backend not suitable (language not context-free) if(g == NULL) // backend not suitable (language not context-free)
return -1; return -1;
@ -349,7 +349,7 @@ int test_lalr(void)
HParser *p = E; HParser *p = E;
printf("\n==== G R A M M A R ====\n"); printf("\n==== G R A M M A R ====\n");
HCFGrammar *g = h_cfgrammar_(mm__, augment(mm__, p)); HCFGrammar *g = h_cfgrammar_(mm__, h_desugar_augmented(mm__, p));
if(g == NULL) { if(g == NULL) {
fprintf(stderr, "h_cfgrammar failed\n"); fprintf(stderr, "h_cfgrammar failed\n");
return 1; return 1;

View file

@ -123,6 +123,7 @@ HHashValue h_hash_transition(const void *p);
HLRDFA *h_lr0_dfa(HCFGrammar *g); HLRDFA *h_lr0_dfa(HCFGrammar *g);
HLRTable *h_lr0_table(HCFGrammar *g, const HLRDFA *dfa); HLRTable *h_lr0_table(HCFGrammar *g, const HLRDFA *dfa);
HCFChoice *h_desugar_augmented(HAllocator *mm__, HParser *parser);
int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params); int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params);
void h_lalr_free(HParser *parser); void h_lalr_free(HParser *parser);