mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
Use $accept and $end, as BYacc and BTYacc do, instead of $axiom and $.
* src/symtab.h, src/symtab.c (eoftoken, axiom): Rename as... (endtoken, accept): these. * src/reader.c (reader): Set endtoken's default tag to "$end". Set undeftoken's tag to "$undefined" instead of "$undefined.". * doc/bison.texinfo (Table of Symbols): Mention $accept and $end. Adjust.
This commit is contained in:
@@ -63,7 +63,7 @@ state_list_append (symbol_number_t symbol,
|
||||
fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n",
|
||||
nstates, symbol, symbols[symbol]->tag);
|
||||
|
||||
/* If this is the eoftoken, and this is not the initial state, then
|
||||
/* If this is the endtoken, and this is not the initial state, then
|
||||
this is the final state. */
|
||||
if (symbol == 0 && first_state)
|
||||
final_state = state;
|
||||
@@ -283,7 +283,7 @@ save_reductions (state_t *state)
|
||||
int i;
|
||||
|
||||
/* If this is the final state, we want it to have no reductions at
|
||||
all, although it has one for `START_SYMBOL EOF .'. */
|
||||
all, although it has one for `START_SYMBOL $end .'. */
|
||||
if (final_state && state->number == final_state->number)
|
||||
return;
|
||||
|
||||
|
||||
16
src/gram.h
16
src/gram.h
@@ -36,16 +36,16 @@
|
||||
|
||||
The rules receive rule numbers 1 to NRULES in the order they are
|
||||
written. More precisely Bison augments the grammar with the
|
||||
initial rule, `$axiom: START-SYMBOL EOF', which is numbered 1, all
|
||||
the user rules are 2, 3 etc. Each time a rule number is presented
|
||||
to the user, we subtract 1, so *displayed* rule numbers are 0, 1,
|
||||
2...
|
||||
initial rule, `$accept: START-SYMBOL $end', which is numbered 1,
|
||||
all the user rules are 2, 3 etc. Each time a rule number is
|
||||
presented to the user, we subtract 1, so *displayed* rule numbers
|
||||
are 0, 1, 2...
|
||||
|
||||
Internally, we cannot use the number 0 for a rule because for
|
||||
instance RITEM stores both symbol (the RHS) and rule numbers: the
|
||||
symbols are shorts >= 0, and rule number are stored negative.
|
||||
Therefore 0 cannot be used, since it would be both the rule number
|
||||
0, and the token EOF).
|
||||
0, and the token $end).
|
||||
|
||||
Actions are accessed via the rule number.
|
||||
|
||||
@@ -68,9 +68,11 @@
|
||||
|
||||
RULES[R].assoc -- the associativity of R.
|
||||
|
||||
RULES[R].dprec -- the dynamic precedence level of R (for GLR parsing).
|
||||
RULES[R].dprec -- the dynamic precedence level of R (for GLR
|
||||
parsing).
|
||||
|
||||
RULES[R].merger -- index of merging function for R (for GLR parsing).
|
||||
RULES[R].merger -- index of merging function for R (for GLR
|
||||
parsing).
|
||||
|
||||
RULES[R].line -- the line where R was defined.
|
||||
|
||||
|
||||
28
src/reader.c
28
src/reader.c
@@ -475,10 +475,10 @@ reader (void)
|
||||
/* Initialize the symbol table. */
|
||||
symbols_new ();
|
||||
|
||||
/* Construct the axiom symbol. */
|
||||
axiom = symbol_get ("$axiom", empty_location);
|
||||
axiom->class = nterm_sym;
|
||||
axiom->number = nvars++;
|
||||
/* Construct the accept symbol. */
|
||||
accept = symbol_get ("$accept", empty_location);
|
||||
accept->class = nterm_sym;
|
||||
accept->number = nvars++;
|
||||
|
||||
/* Construct the error token */
|
||||
errtoken = symbol_get ("error", empty_location);
|
||||
@@ -487,7 +487,7 @@ reader (void)
|
||||
|
||||
/* Construct a token that represents all undefined literal tokens.
|
||||
It is always token number 2. */
|
||||
undeftoken = symbol_get ("$undefined.", empty_location);
|
||||
undeftoken = symbol_get ("$undefined", empty_location);
|
||||
undeftoken->class = token_sym;
|
||||
undeftoken->number = ntokens++;
|
||||
|
||||
@@ -515,25 +515,25 @@ reader (void)
|
||||
/* Report any undefined symbols and consider them nonterminals. */
|
||||
symbols_check_defined ();
|
||||
|
||||
/* If the user did not define her EOFTOKEN, do it now. */
|
||||
if (!eoftoken)
|
||||
/* If the user did not define her ENDTOKEN, do it now. */
|
||||
if (!endtoken)
|
||||
{
|
||||
eoftoken = symbol_get ("$", empty_location);
|
||||
eoftoken->class = token_sym;
|
||||
eoftoken->number = 0;
|
||||
endtoken = symbol_get ("$end", empty_location);
|
||||
endtoken->class = token_sym;
|
||||
endtoken->number = 0;
|
||||
/* Value specified by POSIX. */
|
||||
eoftoken->user_token_number = 0;
|
||||
endtoken->user_token_number = 0;
|
||||
}
|
||||
|
||||
/* Insert the initial rule, which line is that of the first rule
|
||||
(not that of the start symbol):
|
||||
|
||||
axiom: %start EOF. */
|
||||
accept: %start EOF. */
|
||||
{
|
||||
symbol_list_t *p = symbol_list_new (axiom, empty_location);
|
||||
symbol_list_t *p = symbol_list_new (accept, empty_location);
|
||||
p->location = grammar->location;
|
||||
p->next = symbol_list_new (startsymbol, empty_location);
|
||||
p->next->next = symbol_list_new (eoftoken, empty_location);
|
||||
p->next->next = symbol_list_new (endtoken, empty_location);
|
||||
p->next->next->next = symbol_list_new (NULL, empty_location);
|
||||
p->next->next->next->next = grammar;
|
||||
nrules += 1;
|
||||
|
||||
10
src/reduce.c
10
src/reduce.c
@@ -161,9 +161,9 @@ inaccessable_symbols (void)
|
||||
Pp = bitset_create (nrules, BITSET_FIXED);
|
||||
|
||||
/* If the start symbol isn't useful, then nothing will be useful. */
|
||||
if (bitset_test (N, axiom->number - ntokens))
|
||||
if (bitset_test (N, accept->number - ntokens))
|
||||
{
|
||||
bitset_set (V, axiom->number);
|
||||
bitset_set (V, accept->number);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -194,7 +194,7 @@ inaccessable_symbols (void)
|
||||
V = Vp;
|
||||
|
||||
/* Tokens 0, 1, and 2 are internal to Bison. Consider them useful. */
|
||||
bitset_set (V, eoftoken->number); /* end-of-input token */
|
||||
bitset_set (V, endtoken->number); /* end-of-input token */
|
||||
bitset_set (V, errtoken->number); /* error token */
|
||||
bitset_set (V, undeftoken->number); /* some undefined token */
|
||||
|
||||
@@ -333,7 +333,7 @@ nonterminals_reduce (void)
|
||||
if (ISVAR (*rhsp))
|
||||
*rhsp = symbol_number_as_item_number (nontermmap[*rhsp]);
|
||||
}
|
||||
axiom->number = nontermmap[axiom->number];
|
||||
accept->number = nontermmap[accept->number];
|
||||
}
|
||||
|
||||
nsyms -= nuseless_nonterminals;
|
||||
@@ -438,7 +438,7 @@ reduce_grammar (void)
|
||||
|
||||
reduce_print ();
|
||||
|
||||
if (!bitset_test (N, axiom->number - ntokens))
|
||||
if (!bitset_test (N, accept->number - ntokens))
|
||||
fatal_at (startsymbol_location,
|
||||
_("start symbol %s does not derive any sentence"),
|
||||
startsymbol->tag);
|
||||
|
||||
@@ -122,7 +122,7 @@ reductions_new (int num, rule_number_t *reductions)
|
||||
|
||||
state_number_t nstates = 0;
|
||||
/* FINAL_STATE is properly set by new_state when it recognizes its
|
||||
accessing symbol: EOF. */
|
||||
accessing symbol: $end. */
|
||||
state_t *final_state = NULL;
|
||||
|
||||
#define STATE_ALLOC(Nitems) \
|
||||
|
||||
16
src/symtab.c
16
src/symtab.c
@@ -32,8 +32,8 @@
|
||||
|
||||
symbol_t *errtoken = NULL;
|
||||
symbol_t *undeftoken = NULL;
|
||||
symbol_t *eoftoken = NULL;
|
||||
symbol_t *axiom = NULL;
|
||||
symbol_t *endtoken = NULL;
|
||||
symbol_t *accept = NULL;
|
||||
symbol_t *startsymbol = NULL;
|
||||
location_t startsymbol_location;
|
||||
|
||||
@@ -181,11 +181,11 @@ symbol_user_token_number_set (symbol_t *symbol,
|
||||
symbol->tag);
|
||||
|
||||
symbol->user_token_number = user_token_number;
|
||||
/* User defined EOF token? */
|
||||
/* User defined $end token? */
|
||||
if (user_token_number == 0)
|
||||
{
|
||||
eoftoken = symbol;
|
||||
eoftoken->number = 0;
|
||||
endtoken = symbol;
|
||||
endtoken->number = 0;
|
||||
/* It is always mapped to 0, so it was already counted in
|
||||
NTOKENS. */
|
||||
--ntokens;
|
||||
@@ -322,7 +322,7 @@ symbol_pack (symbol_t *this)
|
||||
prec and assoc fields and make both the same */
|
||||
if (this->number == NUMBER_UNDEFINED)
|
||||
{
|
||||
if (this == eoftoken || this->alias == eoftoken)
|
||||
if (this == endtoken || this->alias == endtoken)
|
||||
this->number = this->alias->number = 0;
|
||||
else
|
||||
{
|
||||
@@ -540,8 +540,8 @@ symbols_token_translations_init (void)
|
||||
token_translations = XCALLOC (symbol_number_t, max_user_token_number + 1);
|
||||
|
||||
/* Initialize all entries for literal tokens to 2, the internal
|
||||
token number for $undefined., which represents all invalid
|
||||
inputs. */
|
||||
token number for $undefined, which represents all invalid inputs.
|
||||
*/
|
||||
for (i = 0; i < max_user_token_number + 1; i++)
|
||||
token_translations[i] = undeftoken->number;
|
||||
symbols_do (symbol_translation, NULL);
|
||||
|
||||
@@ -127,8 +127,8 @@ void symbol_user_token_number_set PARAMS ((symbol_t *symbol,
|
||||
*/
|
||||
extern symbol_t *errtoken;
|
||||
extern symbol_t *undeftoken;
|
||||
extern symbol_t *eoftoken;
|
||||
extern symbol_t *axiom;
|
||||
extern symbol_t *endtoken;
|
||||
extern symbol_t *accept;
|
||||
extern symbol_t *startsymbol;
|
||||
extern location_t startsymbol_location;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user