correctly use augmented grammar for test_glr() output
This commit is contained in:
parent
34c6d868b9
commit
8bc3b93e95
3 changed files with 7 additions and 4 deletions
|
|
@ -129,6 +129,8 @@ HParserBackendVTable h__glr_backend_vtable = {
|
|||
// dummy!
|
||||
int test_glr(void)
|
||||
{
|
||||
HAllocator *mm__ = &system_allocator;
|
||||
|
||||
/*
|
||||
E -> E '+' E
|
||||
| 'd'
|
||||
|
|
@ -141,7 +143,7 @@ int test_glr(void)
|
|||
HParser *p = E;
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "h_cfgrammar failed\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ static bool match_production(HLREnhGrammar *eg, HCFChoice **p,
|
|||
|
||||
// desugar parser with a fresh start symbol
|
||||
// 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);
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ int h_lalr_compile(HAllocator* mm__, HParser* parser, const void* params)
|
|||
// build LR(0) table
|
||||
// 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)
|
||||
return -1;
|
||||
|
||||
|
|
@ -349,7 +349,7 @@ int test_lalr(void)
|
|||
HParser *p = E;
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "h_cfgrammar failed\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ HHashValue h_hash_transition(const void *p);
|
|||
HLRDFA *h_lr0_dfa(HCFGrammar *g);
|
||||
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);
|
||||
void h_lalr_free(HParser *parser);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue