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 */
|
||||
|
||||
#include "cfgrammar.h"
|
||||
#include "allocator.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__)
|
|||
HCFGrammar *g = h_new(HCFGrammar, 1);
|
||||
assert(g != NULL);
|
||||
|
||||
g->mm__ = mm__;
|
||||
g->arena = h_new_arena(mm__, 0); // default blocksize
|
||||
g->nts = h_hashset_new(g->arena, h_eq_ptr, h_hash_ptr);
|
||||
g->geneps = NULL;
|
||||
|
|
@ -19,6 +21,16 @@ HCFGrammar *h_cfgrammar_new(HAllocator *mm__)
|
|||
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
|
||||
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 *follow; // memoized follow sets of the grammar's NTs
|
||||
HArena *arena;
|
||||
HAllocator *mm__;
|
||||
} HCFGrammar;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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)? */
|
||||
bool h_symbol_derives_epsilon(HCFGrammar *g, const HCFChoice *symbol);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue