commit 6e7d8ba6a7db3460c2cea3e5afd6640043875286 Author: Akim Demaille <[email protected]> Date: Tue Oct 22 10:07:40 2019 +0200 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. diff --git a/src/reader.c b/src/reader.c index a247d07b..0a428234 100644 --- a/src/reader.c +++ b/src/reader.c @@ -700,7 +700,8 @@ packgram (void) if (trace_flag & trace_sets) ritem_print (stderr); } - + + /*------------------------------------------------------------------. | Read in the grammar specification and record it in the format | | described in gram.h. All actions are copied into ACTION_OBSTACK, | @@ -711,25 +712,10 @@ packgram (void) void reader (void) { - /* Initialize the symbol table. */ + /* Set up symbol_table, semantic_type_table, and the built-in + symbols. */ 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__flex_debug = trace_flag & trace_scan; diff --git a/src/symtab.c b/src/symtab.c index 05249d98..1b43ef96 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -805,6 +805,23 @@ symbols_new (void) hash_symbol_hasher, hash_symbol_comparator, 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, NULL, hash_semantic_type_hasher, diff --git a/src/symtab.h b/src/symtab.h index 0cfb13b8..b6e18e61 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -345,7 +345,8 @@ void semantic_type_code_props_set (semantic_type *type, | 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); /** Free all the memory allocated for symbols and semantic types. */
