From 8bc3b93e959619708d07f468e3a7dd5037bf28c5 Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Fri, 21 Jun 2013 23:53:47 +0200
Subject: [PATCH] correctly use augmented grammar for test_glr() output

---
 src/backends/glr.c  | 4 +++-
 src/backends/lalr.c | 6 +++---
 src/backends/lr.h   | 1 +
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/backends/glr.c b/src/backends/glr.c
index f7b6f8b1..82ad5c06 100644
--- a/src/backends/glr.c
+++ b/src/backends/glr.c
@@ -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;
diff --git a/src/backends/lalr.c b/src/backends/lalr.c
index 242988ee..93becf31 100644
--- a/src/backends/lalr.c
+++ b/src/backends/lalr.c
@@ -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;
diff --git a/src/backends/lr.h b/src/backends/lr.h
index ca8418e8..1158542b 100644
--- a/src/backends/lr.h
+++ b/src/backends/lr.h
@@ -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);
 
-- 
GitLab