add h_cfgrammar_free()
This commit is contained in:
parent
65ee3593bd
commit
9f5c32e205
2 changed files with 18 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
/* Context-free grammar representation and analysis */
|
/* Context-free grammar representation and analysis */
|
||||||
|
|
||||||
#include "cfgrammar.h"
|
#include "cfgrammar.h"
|
||||||
|
#include "allocator.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
@ -10,6 +11,7 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__)
|
||||||
HCFGrammar *g = h_new(HCFGrammar, 1);
|
HCFGrammar *g = h_new(HCFGrammar, 1);
|
||||||
assert(g != NULL);
|
assert(g != NULL);
|
||||||
|
|
||||||
|
g->mm__ = mm__;
|
||||||
g->arena = h_new_arena(mm__, 0); // default blocksize
|
g->arena = h_new_arena(mm__, 0); // default blocksize
|
||||||
g->nts = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr);
|
g->nts = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr);
|
||||||
g->geneps = NULL;
|
g->geneps = NULL;
|
||||||
|
|
@ -19,6 +21,16 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__)
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Frees the given grammar and associated data.
|
||||||
|
* Does *not* free parsers' CFG forms as created by h_desugar.
|
||||||
|
*/
|
||||||
|
void h_cfgrammar_free(HCFGrammar *g)
|
||||||
|
{
|
||||||
|
HAllocator *mm__ = g->mm__;
|
||||||
|
h_delete_arena(g->arena);
|
||||||
|
h_free(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol);
|
static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ typedef struct HCFGrammar_ {
|
||||||
HHashTable *first; // memoized first sets of the grammar's symbols
|
HHashTable *first; // memoized first sets of the grammar's symbols
|
||||||
HHashTable *follow; // memoized follow sets of the grammar's NTs
|
HHashTable *follow; // memoized follow sets of the grammar's NTs
|
||||||
HArena *arena;
|
HArena *arena;
|
||||||
|
HAllocator *mm__;
|
||||||
} HCFGrammar;
|
} HCFGrammar;
|
||||||
|
|
||||||
/* mapping input bytes or end to tokens
|
/* mapping input bytes or end to tokens
|
||||||
|
|
@ -29,6 +30,11 @@ static const HCFToken end_token = 0x200;
|
||||||
*/
|
*/
|
||||||
HCFGrammar *h_cfgrammar(HAllocator* mm__, const HParser *parser);
|
HCFGrammar *h_cfgrammar(HAllocator* mm__, const HParser *parser);
|
||||||
|
|
||||||
|
/* Frees the given grammar and associated data.
|
||||||
|
* Does *not* free parsers' CFG forms as created by h_desugar.
|
||||||
|
*/
|
||||||
|
void h_cfgrammar_free(HCFGrammar *g);
|
||||||
|
|
||||||
/* Does the given symbol derive the empty string (under g)? */
|
/* Does the given symbol derive the empty string (under g)? */
|
||||||
bool h_symbol_derives_epsilon(HCFGrammar *g, const HCFChoice *symbol);
|
bool h_symbol_derives_epsilon(HCFGrammar *g, const HCFChoice *symbol);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue