Skip to content

Commit

Permalink
reader: let symtab deal with the symbols
Browse files Browse the repository at this point in the history
* src/reader.c (reader): Move the setting up of the builtin symbols to...
* src/symtab.c (symbols_new): here.
  • Loading branch information
akimd committed Oct 25, 2019
1 parent c680300 commit 6e7d8ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
22 changes: 4 additions & 18 deletions src/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, |
Expand All @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 6e7d8ba

Please sign in to comment.