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:
Akim Demaille
2002-07-29 17:30:33 +00:00
parent 1bfb97dba5
commit 88bce5a2ef
15 changed files with 163 additions and 131 deletions

View File

@@ -1,3 +1,14 @@
2002-07-29 Akim Demaille <akim@epita.fr>
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.
2002-07-29 Akim Demaille <akim@epita.fr>
* src/reduce.c (reduce_grammar): When the language is empty,

12
TODO
View File

@@ -4,6 +4,11 @@
Write a first documentation for C++ output.
* Documentation
Before releasing, make sure the documentation refers to the current
`output' format.
* Error messages
Some are really funky. For instance
@@ -121,13 +126,6 @@ this issue. Does anybody have it?
* Documentation
** Vocabulary
Explain $axiom (and maybe change its name: BTYacc names it `goal',
byacc `$accept' probably based on AT&T Yacc, Meta `Start'...).
Complete the glossary (item, axiom, ?). Should we also rename `$'?
BYacc uses `$end'. `$eof' is attracting, but after all we may be
parsing a string, a stream etc.
** History/Bibliography
Some history of Bison and some bibliography would be most welcome.
Are there any Texinfo standards for bibliography?

View File

@@ -3553,9 +3553,9 @@ Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure
Generate an array of token names in the parser file. The name of the
array is @code{yytname}; @code{yytname[@var{i}]} is the name of the
token whose internal Bison token code number is @var{i}. The first
three elements of @code{yytname} are always @code{"$"}, @code{"error"},
and @code{"$undefined."}; after these come the symbols defined in the
grammar file.
three elements of @code{yytname} are always @code{"$end"},
@code{"error"}, and @code{"$undefined"}; after these come the symbols
defined in the grammar file.
For single-character literal tokens and literal string tokens, the name
in the table includes the single-quote or double-quote characters: for
@@ -5276,12 +5276,19 @@ useless: STR;
%%
@end example
@command{bison} reports that @samp{calc.y contains 1 useless nonterminal
and 1 useless rule} and that @samp{calc.y contains 7 shift/reduce
conflicts}. When given @option{--report=state}, in addition to
@file{calc.tab.c}, it creates a file @file{calc.output} with contents
detailed below. The order of the output and the exact presentation
might vary, but the interpretation is the same.
@command{bison} reports:
@example
calc.y: warning: 1 useless nonterminal and 1 useless rule
calc.y:11.1-7: warning: useless nonterminal: useless
calc.y:11.8-12: warning: useless rule: useless: STR
calc.y contains 7 shift/reduce conflicts.
@end example
When given @option{--report=state}, in addition to @file{calc.tab.c}, it
creates a file @file{calc.output} with contents detailed below. The
order of the output and the exact presentation might vary, but the
interpretation is the same.
The first section includes details on conflicts that were solved thanks
to precedence and/or associativity:
@@ -5334,7 +5341,7 @@ The next section reproduces the exact grammar that Bison used:
Grammar
Number, Line, Rule
0 5 $axiom -> exp $
0 5 $accept -> exp $end
1 5 exp -> exp '+' exp
2 6 exp -> exp '-' exp
3 7 exp -> exp '*' exp
@@ -5348,7 +5355,7 @@ and reports the uses of the symbols:
@example
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
'*' (42) 3
'+' (43) 1
'-' (45) 2
@@ -5358,7 +5365,7 @@ NUM (258) 5
Nonterminals, with rules where they appear
$axiom (8)
$accept (8)
on left: 0
exp (9)
on left: 1 2 3 4 5, on right: 0 1 2 3 4
@@ -5376,7 +5383,7 @@ that the input cursor.
@example
state 0
$axiom -> . exp $ (rule 0)
$accept -> . exp $ (rule 0)
NUM shift, and go to state 1
@@ -5407,7 +5414,7 @@ be derived:
@example
state 0
$axiom -> . exp $ (rule 0)
$accept -> . exp $ (rule 0)
exp -> . exp '+' exp (rule 1)
exp -> . exp '-' exp (rule 2)
exp -> . exp '*' exp (rule 3)
@@ -5439,7 +5446,7 @@ jump to state 2 (@samp{exp: go to state 2}).
@example
state 2
$axiom -> exp . $ (rule 0)
$accept -> exp . $ (rule 0)
exp -> exp . '+' exp (rule 1)
exp -> exp . '-' exp (rule 2)
exp -> exp . '*' exp (rule 3)
@@ -5466,7 +5473,7 @@ state}:
@example
state 3
$axiom -> exp $ . (rule 0)
$accept -> exp $ . (rule 0)
$default accept
@end example
@@ -6006,7 +6013,7 @@ would instead be named @file{foo_tab.c}.
@table @code
@item @@$
In an action, the location of the left-hand side of the rule.
@xref{Locations, , Locations Overview}.
@xref{Locations, , Locations Overview}.
@item @@@var{n}
In an action, the location of the @var{n}-th symbol of the right-hand
@@ -6020,6 +6027,20 @@ In an action, the semantic value of the left-hand side of the rule.
In an action, the semantic value of the @var{n}-th symbol of the
right-hand side of the rule. @xref{Actions}.
@item $accept
The predefined nonterminal whose only rule is @samp{$accept: @var{start}
$end}, where @var{start} is the start symbol. @xref{Start Decl, , The
Start-Symbol}. It cannot be used in the grammar.
@item $end
The predefined token marking the end of the token stream. It cannot be
used in the grammar.
@item $undefined
The predefined token onto which all undefined values returned by
@code{yylex} are mapped. It cannot be used in the grammar, rather, use
@code{error}.
@item error
A token name reserved for error recovery. This token may be used in
grammar rules so as to allow the Bison parser to recognize an error in

View File

@@ -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;

View File

@@ -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.

View File

@@ -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;

View File

@@ -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);

View File

@@ -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) \

View File

@@ -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);

View File

@@ -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;

View File

@@ -327,7 +327,7 @@ thing(10): 'x'(10)
sending: ';' (value = 11, line 110)
line(10): thing(10) ';'
sending: 'y' (value = 12, line 120)
120: parse error, unexpected $undefined., expecting $ or error or 'x'
120: parse error, unexpected $undefined, expecting $end or error or 'x'
sending: EOF
Freeing nterm line (10 from 100)
Freeing nterm line (7 from 70)

View File

@@ -396,7 +396,7 @@ _AT_CHECK_CALC_ERROR([$1], [0 0], [11],
_AT_CHECK_CALC_ERROR([$1], [1//2], [15],
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
_AT_CHECK_CALC_ERROR([$1], [error], [4],
[1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
[1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '('])
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22],
[1.7-1.8: parse error, unexpected '='])
_AT_CHECK_CALC_ERROR([$1],

View File

@@ -150,7 +150,7 @@ AT_CHECK([cat input.output], [],
Grammar
0 $axiom: exp $
0 $accept: exp $end
1 exp: exp OP exp
2 | NUM
@@ -158,7 +158,7 @@ Grammar
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
error (256)
NUM (258) 2
OP (259) 1
@@ -166,7 +166,7 @@ OP (259) 1
Nonterminals, with rules where they appear
$axiom (5)
$accept (5)
on left: 0
exp (6)
on left: 1 2, on right: 0 1
@@ -174,7 +174,7 @@ exp (6)
state 0
0 $axiom: . exp $
0 $accept: . exp $end
1 exp: . exp OP exp
2 | . NUM
@@ -192,16 +192,16 @@ state 1
state 2
0 $axiom: exp . $
0 $accept: exp . $end
1 exp: exp . OP exp
$ shift, and go to state 3
OP shift, and go to state 4
$end shift, and go to state 3
OP shift, and go to state 4
state 3
0 $axiom: exp $ .
0 $accept: exp $end .
$default accept
@@ -219,8 +219,8 @@ state 4
state 5
1 exp: exp . OP exp [$, OP]
1 | exp OP exp . [$, OP]
1 exp: exp . OP exp [$end, OP]
1 | exp OP exp . [$end, OP]
OP shift, and go to state 4
@@ -253,7 +253,7 @@ AT_CHECK([bison input.y -o input.c --report=all])
AT_CHECK([cat input.output], [],
[[Grammar
0 $axiom: exp $
0 $accept: exp $end
1 exp: exp OP exp
2 | NUM
@@ -261,7 +261,7 @@ AT_CHECK([cat input.output], [],
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
error (256)
NUM (258) 2
OP (259) 1
@@ -269,7 +269,7 @@ OP (259) 1
Nonterminals, with rules where they appear
$axiom (5)
$accept (5)
on left: 0
exp (6)
on left: 1 2, on right: 0 1
@@ -277,7 +277,7 @@ exp (6)
state 0
0 $axiom: . exp $
0 $accept: . exp $end
1 exp: . exp OP exp
2 | . NUM
@@ -295,16 +295,16 @@ state 1
state 2
0 $axiom: exp . $
0 $accept: exp . $end
1 exp: exp . OP exp
$ shift, and go to state 3
OP shift, and go to state 4
$end shift, and go to state 3
OP shift, and go to state 4
state 3
0 $axiom: exp $ .
0 $accept: exp $end .
$default accept
@@ -322,8 +322,8 @@ state 4
state 5
1 exp: exp . OP exp [$, OP]
1 | exp OP exp . [$, OP]
1 exp: exp . OP exp [$end, OP]
1 | exp OP exp . [$end, OP]
$default reduce using rule 1 (exp)
Conflict between rule 1 and token OP resolved as reduce (%left OP).
@@ -339,19 +339,19 @@ AT_CLEANUP
# When there are RR conflicts, some rules are disabled. Usually it is
# simply displayed as:
#
# $ reduce using rule 3 (num)
# $ [reduce using rule 4 (id)]
# $end reduce using rule 3 (num)
# $end [reduce using rule 4 (id)]
#
# But when `reduce 3' is the default action, we'd produce:
#
# $ [reduce using rule 4 (id)]
# $end [reduce using rule 4 (id)]
# $default reduce using rule 3 (num)
#
# In this precise case (a reduction is masked by the default
# reduction), we make the `reduce 3' explicit:
#
# $ reduce using rule 3 (num)
# $ [reduce using rule 4 (id)]
# $end reduce using rule 3 (num)
# $end [reduce using rule 4 (id)]
# $default reduce using rule 3 (num)
#
# Maybe that's not the best display, but then, please propose something
@@ -379,7 +379,7 @@ AT_CHECK([cat input.output], [],
Grammar
0 $axiom: exp $
0 $accept: exp $end
1 exp: num
2 | id
@@ -391,14 +391,14 @@ Grammar
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
'0' (48) 3 4
error (256)
Nonterminals, with rules where they appear
$axiom (4)
$accept (4)
on left: 0
exp (5)
on left: 1 2, on right: 0
@@ -410,7 +410,7 @@ id (7)
state 0
0 $axiom: . exp $
0 $accept: . exp $end
1 exp: . num
2 | . id
3 num: . '0'
@@ -425,19 +425,19 @@ state 0
state 1
3 num: '0' . [$]
4 id: '0' . [$]
3 num: '0' . [$end]
4 id: '0' . [$end]
$ reduce using rule 3 (num)
$ [reduce using rule 4 (id)]
$end reduce using rule 3 (num)
$end [reduce using rule 4 (id)]
$default reduce using rule 3 (num)
state 2
0 $axiom: exp . $
0 $accept: exp . $end
$ shift, and go to state 5
$end shift, and go to state 5
state 3
@@ -456,7 +456,7 @@ state 4
state 5
0 $axiom: exp $ .
0 $accept: exp $end .
$default accept
]])

View File

@@ -150,7 +150,7 @@ AT_CHECK([bison input.y -o input.c -v])
AT_CHECK([cat input.output], [],
[[Grammar
0 $axiom: expr $
0 $accept: expr $end
1 @1: /* empty */
@@ -163,7 +163,7 @@ AT_CHECK([cat input.output], [],
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
'a' (97) 2
'b' (98) 2
'c' (99) 4
@@ -172,7 +172,7 @@ error (256)
Nonterminals, with rules where they appear
$axiom (6)
$accept (6)
on left: 0
expr (7)
on left: 2 4, on right: 0
@@ -184,7 +184,7 @@ expr (7)
state 0
0 $axiom: . expr $
0 $accept: . expr $end
'a' shift, and go to state 1
@@ -205,9 +205,9 @@ state 1
state 2
0 $axiom: expr . $
0 $accept: expr . $end
$ shift, and go to state 5
$end shift, and go to state 5
state 3
@@ -226,7 +226,7 @@ state 4
state 5
0 $axiom: expr $ .
0 $accept: expr $end .
$default accept
@@ -371,7 +371,7 @@ AT_CHECK([bison -v input.y])
AT_CHECK([cat input.output], 0,
[[Grammar
0 $axiom: CONST_DEC_PART $
0 $accept: CONST_DEC_PART $end
1 CONST_DEC_PART: CONST_DEC_LIST
@@ -385,7 +385,7 @@ AT_CHECK([cat input.output], 0,
Terminals, with rules where they appear
$ (0) 0
$end (0) 0
';' (59) 5
'=' (61) 5
error (256)
@@ -395,7 +395,7 @@ const_id_tok (259) 5
Nonterminals, with rules where they appear
$axiom (7)
$accept (7)
on left: 0
CONST_DEC_PART (8)
on left: 1, on right: 0
@@ -409,7 +409,7 @@ CONST_DEC (10)
state 0
0 $axiom: . CONST_DEC_PART $
0 $accept: . CONST_DEC_PART $end
$default reduce using rule 4 (@1)
@@ -421,9 +421,9 @@ state 0
state 1
0 $axiom: CONST_DEC_PART . $
0 $accept: CONST_DEC_PART . $end
$ shift, and go to state 5
$end shift, and go to state 5
state 2
@@ -454,7 +454,7 @@ state 4
state 5
0 $axiom: CONST_DEC_PART $ .
0 $accept: CONST_DEC_PART $end .
$default accept
@@ -584,8 +584,8 @@ static const unsigned char yyrline[] =
};
static const char *const yytname[] =
{
"$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
"\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
"$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
"\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
};
static const unsigned short yytoknum[] =
{

View File

@@ -82,23 +82,23 @@ AT_CHECK([[bison --trace input.y]], [], [], [stderr])
AT_EXTRACT_SETS([stderr], [sets])
AT_CHECK([[cat sets]], [],
[[DERIVES
$axiom derives
0 e $
$accept derives
0 e $end
e derives
1 'e'
2 /* empty */
NULLABLE
$axiom: no
$accept: no
e: yes
FIRSTS
$axiom firsts
$axiom
$accept firsts
$accept
e
e firsts
e
FDERIVES
$axiom derives
0 e $
$accept derives
0 e $end
1 'e'
2 /* empty */
e derives
@@ -212,8 +212,8 @@ AT_CHECK([[bison --trace input.y]], [], [], [stderr])
AT_EXTRACT_SETS([stderr], [sets])
AT_CHECK([[cat sets]], [],
[[DERIVES
$axiom derives
0 exp $
$accept derives
0 exp $end
exp derives
1 exp '<' exp
2 exp '>' exp
@@ -223,17 +223,17 @@ AT_CHECK([[cat sets]], [],
6 exp '=' exp
7 "exp"
NULLABLE
$axiom: no
$accept: no
exp: no
FIRSTS
$axiom firsts
$axiom
$accept firsts
$accept
exp
exp firsts
exp
FDERIVES
$axiom derives
0 exp $
$accept derives
0 exp $end
1 exp '<' exp
2 exp '>' exp
3 exp '+' exp