* 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>
+
+ 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,
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
* 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?
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
%%
@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:
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
@example
Terminals, with rules where they appear
-$ (0) 0
+$end (0) 0
'*' (42) 3
'+' (43) 1
'-' (45) 2
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
@example
state 0
- $axiom -> . exp $ (rule 0)
+ $accept -> . exp $ (rule 0)
NUM shift, and go to state 1
@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)
@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)
@example
state 3
- $axiom -> exp $ . (rule 0)
+ $accept -> exp $ . (rule 0)
$default accept
@end example
@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
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
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;
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;
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.
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.
/* 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);
/* 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++;
/* 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;
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)
{
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 */
if (ISVAR (*rhsp))
*rhsp = symbol_number_as_item_number (nontermmap[*rhsp]);
}
- axiom->number = nontermmap[axiom->number];
+ accept->number = nontermmap[accept->number];
}
nsyms -= nuseless_nonterminals;
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);
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) \
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;
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;
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
{
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);
*/
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;
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)
_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],
Grammar
- 0 $axiom: exp $
+ 0 $accept: exp $end
1 exp: exp OP exp
2 | NUM
Terminals, with rules where they appear
-$ (0) 0
+$end (0) 0
error (256)
NUM (258) 2
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
state 0
- 0 $axiom: . exp $
+ 0 $accept: . exp $end
1 exp: . exp OP exp
2 | . NUM
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
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
AT_CHECK([cat input.output], [],
[[Grammar
- 0 $axiom: exp $
+ 0 $accept: exp $end
1 exp: exp OP exp
2 | NUM
Terminals, with rules where they appear
-$ (0) 0
+$end (0) 0
error (256)
NUM (258) 2
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
state 0
- 0 $axiom: . exp $
+ 0 $accept: . exp $end
1 exp: . exp OP exp
2 | . NUM
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
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).
# 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
Grammar
- 0 $axiom: exp $
+ 0 $accept: exp $end
1 exp: num
2 | id
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
state 0
- 0 $axiom: . exp $
+ 0 $accept: . exp $end
1 exp: . num
2 | . id
3 num: . '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
state 5
- 0 $axiom: exp $ .
+ 0 $accept: exp $end .
$default accept
]])
AT_CHECK([cat input.output], [],
[[Grammar
- 0 $axiom: expr $
+ 0 $accept: expr $end
1 @1: /* empty */
Terminals, with rules where they appear
-$ (0) 0
+$end (0) 0
'a' (97) 2
'b' (98) 2
'c' (99) 4
Nonterminals, with rules where they appear
-$axiom (6)
+$accept (6)
on left: 0
expr (7)
on left: 2 4, on right: 0
state 0
- 0 $axiom: . expr $
+ 0 $accept: . expr $end
'a' shift, and go to 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
state 5
- 0 $axiom: expr $ .
+ 0 $accept: expr $end .
$default accept
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
Terminals, with rules where they appear
-$ (0) 0
+$end (0) 0
';' (59) 5
'=' (61) 5
error (256)
Nonterminals, with rules where they appear
-$axiom (7)
+$accept (7)
on left: 0
CONST_DEC_PART (8)
on left: 1, on right: 0
state 0
- 0 $axiom: . CONST_DEC_PART $
+ 0 $accept: . CONST_DEC_PART $end
$default reduce using rule 4 (@1)
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
state 5
- 0 $axiom: CONST_DEC_PART $ .
+ 0 $accept: CONST_DEC_PART $end .
$default accept
};
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[] =
{
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
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
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