add proper parse table type and lookup function

This commit is contained in:
Sven M. Hallberg 2013-05-08 17:04:19 +02:00
parent 1631e9c08f
commit af4971b265

View file

@ -7,23 +7,20 @@
/* LL parse table and associated data */ /* LL parse table and associated data */
typedef struct HLLTable_ { /* Maps each nonterminal (HCFChoice) of the grammar to another hash table that
unsigned int **arr; // Nonterminals numbered from 1, 0 = error. * maps lookahead tokens (HCFToken) to productions (HCFSequence).
} HLLTable; */
typedef HHashTable HLLTable;
typedef struct HLLData_ {
HCFGrammar *grammar;
HLLTable *table;
} HLLData;
#if 0
/* Interface to look up an entry in the parse table. */ /* Interface to look up an entry in the parse table. */
unsigned int h_ll_lookup(const HLLTable *table, unsigned int nonterminal, uint8_t token) const HCFSequence *h_ll_lookup(const HLLTable *table, const HCFChoice *x, HCFToken tok)
{ {
assert(nonterminal > 0); const HHashTable *row = h_hashtable_get(table, x);
return table->arr[n*257+token]; assert(row != NULL); // the table should have one row for each nonterminal
const HCFSequence *production = h_hashtable_get(row, (void *)tok);
return production;
} }
#endif
/* Compute the predict set of production "A -> rhs". */ /* Compute the predict set of production "A -> rhs". */
HHashSet *h_predict(HCFGrammar *g, const HCFChoice *A, const HCFSequence *rhs) HHashSet *h_predict(HCFGrammar *g, const HCFChoice *A, const HCFSequence *rhs)
@ -54,6 +51,7 @@ int h_ll_compile(HAllocator* mm__, const HParser* parser, const void* params)
// XXX generate table and store in parser->data. // XXX generate table and store in parser->data.
// XXX any other data structures needed? // XXX any other data structures needed?
// XXX free grammar and its arena
return -1; // XXX 0 on success return -1; // XXX 0 on success
} }