reader: let symtab deal with the symbols

* src/reader.c (reader): Move the setting up of the builtin symbols to...
* src/symtab.c (symbols_new): here.
This commit is contained in:
Akim Demaille
2019-10-22 10:07:40 +02:00
parent c680300a29
commit 6e7d8ba6a7
3 changed files with 23 additions and 19 deletions

View File

@@ -700,7 +700,8 @@ packgram (void)
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
ritem_print (stderr); ritem_print (stderr);
} }
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Read in the grammar specification and record it in the format | | Read in the grammar specification and record it in the format |
| described in gram.h. All actions are copied into ACTION_OBSTACK, | | described in gram.h. All actions are copied into ACTION_OBSTACK, |
@@ -711,25 +712,10 @@ packgram (void)
void void
reader (void) reader (void)
{ {
/* Initialize the symbol table. */ /* Set up symbol_table, semantic_type_table, and the built-in
symbols. */
symbols_new (); symbols_new ();
/* Construct the accept symbol. */
accept = symbol_get ("$accept", empty_loc);
accept->content->class = nterm_sym;
accept->content->number = nvars++;
/* Construct the error token */
errtoken = symbol_get ("error", empty_loc);
errtoken->content->class = token_sym;
errtoken->content->number = ntokens++;
/* Construct a token that represents all undefined literal tokens.
It is always token number 2. */
undeftoken = symbol_get ("$undefined", empty_loc);
undeftoken->content->class = token_sym;
undeftoken->content->number = ntokens++;
gram_in = xfopen (grammar_file, "r"); gram_in = xfopen (grammar_file, "r");
gram__flex_debug = trace_flag & trace_scan; gram__flex_debug = trace_flag & trace_scan;

View File

@@ -805,6 +805,23 @@ symbols_new (void)
hash_symbol_hasher, hash_symbol_hasher,
hash_symbol_comparator, hash_symbol_comparator,
symbol_free); symbol_free);
/* Construct the accept symbol. */
accept = symbol_get ("$accept", empty_loc);
accept->content->class = nterm_sym;
accept->content->number = nvars++;
/* Construct the error token */
errtoken = symbol_get ("error", empty_loc);
errtoken->content->class = token_sym;
errtoken->content->number = ntokens++;
/* Construct a token that represents all undefined literal tokens.
It is always token number 2. */
undeftoken = symbol_get ("$undefined", empty_loc);
undeftoken->content->class = token_sym;
undeftoken->content->number = ntokens++;
semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY, semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY,
NULL, NULL,
hash_semantic_type_hasher, hash_semantic_type_hasher,

View File

@@ -345,7 +345,8 @@ void semantic_type_code_props_set (semantic_type *type,
| Symbol and semantic type tables. | | Symbol and semantic type tables. |
`----------------------------------*/ `----------------------------------*/
/** Create the symbol and semantic type tables. */ /** Create the symbol and semantic type tables, and the built-in
symbols. */
void symbols_new (void); void symbols_new (void);
/** Free all the memory allocated for symbols and semantic types. */ /** Free all the memory allocated for symbols and semantic types. */