mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* src/reader.c (token_translations_init): 256 is now the default
value for the error token, i.e., it will be assigned another number if the user assigned 256 to one of her tokens. (reader): Don't force 256 to error. * doc/bison.texinfo (Symbols): Adjust. * tests/torture.at (AT_DATA_HORIZONTAL_GRAMMAR) (AT_DATA_TRIANGULAR_GRAMMAR): Number the tokens as 1, 2, 3 etc. instead of 10, 20, 30 (which was used to `jump' over error (256) and undefined (2)).
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2002-04-22 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/reader.c (token_translations_init): 256 is now the default
|
||||||
|
value for the error token, i.e., it will be assigned another
|
||||||
|
number if the user assigned 256 to one of her tokens.
|
||||||
|
(reader): Don't force 256 to error.
|
||||||
|
* doc/bison.texinfo (Symbols): Adjust.
|
||||||
|
* tests/torture.at (AT_DATA_HORIZONTAL_GRAMMAR)
|
||||||
|
(AT_DATA_TRIANGULAR_GRAMMAR): Number the tokens as 1, 2, 3
|
||||||
|
etc. instead of 10, 20, 30 (which was used to `jump' over error
|
||||||
|
(256) and undefined (2)).
|
||||||
|
|
||||||
2002-04-22 Akim Demaille <akim@epita.fr>
|
2002-04-22 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
Propagate more token_number_t.
|
Propagate more token_number_t.
|
||||||
|
|||||||
6
NEWS
6
NEWS
@@ -11,6 +11,12 @@ Changes in version 1.49a:
|
|||||||
If yylex returned a code out of range, yyparse could die. This is
|
If yylex returned a code out of range, yyparse could die. This is
|
||||||
no longer the case.
|
no longer the case.
|
||||||
|
|
||||||
|
* Error token
|
||||||
|
According to POSIX, the error token should be numbered as 256.
|
||||||
|
Bison extends this requirement by making it a preference: *if* the
|
||||||
|
user specified that one of her tokens is numbered 256, then error
|
||||||
|
will be mapped onto another number.
|
||||||
|
|
||||||
* Large grammars
|
* Large grammars
|
||||||
Are now supported (large token numbers, large grammar size (= sum of
|
Are now supported (large token numbers, large grammar size (= sum of
|
||||||
the LHS and RHS lengths).
|
the LHS and RHS lengths).
|
||||||
|
|||||||
@@ -2218,11 +2218,9 @@ files before compiling them.
|
|||||||
|
|
||||||
The symbol @code{error} is a terminal symbol reserved for error recovery
|
The symbol @code{error} is a terminal symbol reserved for error recovery
|
||||||
(@pxref{Error Recovery}); you shouldn't use it for any other purpose.
|
(@pxref{Error Recovery}); you shouldn't use it for any other purpose.
|
||||||
In particular, @code{yylex} should never return this value.
|
In particular, @code{yylex} should never return this value. The default
|
||||||
The default value of the error token is 256, so in the
|
value of the error token is 256, unless you explicitly assigned 256 to
|
||||||
unlikely event that you need to use a character token with numeric
|
one of your tokens with a @code{%token} declaration.
|
||||||
value 256 you must reassign the error token's value with a
|
|
||||||
@code{%token} declaration.
|
|
||||||
|
|
||||||
@node Rules
|
@node Rules
|
||||||
@section Syntax of Grammar Rules
|
@section Syntax of Grammar Rules
|
||||||
|
|||||||
30
src/reader.c
30
src/reader.c
@@ -1678,15 +1678,37 @@ read_additionnal_code (void)
|
|||||||
static void
|
static void
|
||||||
token_translations_init (void)
|
token_translations_init (void)
|
||||||
{
|
{
|
||||||
int last_user_token_number = 256;
|
int num_256_available_p = TRUE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Set the user numbers. */
|
/* Find the highest user token number, and whether 256, the POSIX
|
||||||
|
preferred user token number for the error token, is used. */
|
||||||
|
max_user_token_number = 0;
|
||||||
|
for (i = 0; i < ntokens; ++i)
|
||||||
|
{
|
||||||
|
symbol_t *this = symbols[i];
|
||||||
|
if (this->user_token_number != SUNDEF)
|
||||||
|
{
|
||||||
|
if (this->user_token_number > max_user_token_number)
|
||||||
|
max_user_token_number = this->user_token_number;
|
||||||
|
if (this->user_token_number == 256)
|
||||||
|
num_256_available_p = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If 256 is not used, assign it to error, to follow POSIX. */
|
||||||
|
if (num_256_available_p && errtoken->user_token_number == SUNDEF)
|
||||||
|
errtoken->user_token_number = 256;
|
||||||
|
|
||||||
|
/* Set the missing user numbers. */
|
||||||
|
if (max_user_token_number < 256)
|
||||||
|
max_user_token_number = 256;
|
||||||
|
|
||||||
for (i = 0; i < ntokens; ++i)
|
for (i = 0; i < ntokens; ++i)
|
||||||
{
|
{
|
||||||
symbol_t *this = symbols[i];
|
symbol_t *this = symbols[i];
|
||||||
if (this->user_token_number == SUNDEF)
|
if (this->user_token_number == SUNDEF)
|
||||||
this->user_token_number = ++last_user_token_number;
|
this->user_token_number = ++max_user_token_number;
|
||||||
if (this->user_token_number > max_user_token_number)
|
if (this->user_token_number > max_user_token_number)
|
||||||
max_user_token_number = this->user_token_number;
|
max_user_token_number = this->user_token_number;
|
||||||
}
|
}
|
||||||
@@ -1698,7 +1720,6 @@ token_translations_init (void)
|
|||||||
inputs. */
|
inputs. */
|
||||||
for (i = 0; i < max_user_token_number + 1; i++)
|
for (i = 0; i < max_user_token_number + 1; i++)
|
||||||
token_translations[i] = undeftoken->number;
|
token_translations[i] = undeftoken->number;
|
||||||
|
|
||||||
symbols_do (symbol_translation, NULL);
|
symbols_do (symbol_translation, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1824,7 +1845,6 @@ reader (void)
|
|||||||
errtoken = getsym ("error");
|
errtoken = getsym ("error");
|
||||||
errtoken->class = token_sym;
|
errtoken->class = token_sym;
|
||||||
errtoken->number = ntokens++;
|
errtoken->number = ntokens++;
|
||||||
errtoken->user_token_number = 256; /* Value specified by POSIX. */
|
|
||||||
|
|
||||||
/* Construct a token that represents all undefined literal tokens.
|
/* Construct a token that represents all undefined literal tokens.
|
||||||
It is always token number 2. */
|
It is always token number 2. */
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ EOF
|
|||||||
|
|
||||||
for my $size (1 .. $max)
|
for my $size (1 .. $max)
|
||||||
{
|
{
|
||||||
print "%token \"$size\" ", $size * 10, "\n";
|
print "%token \"$size\" ", $size, "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
print <<EOF;
|
print <<EOF;
|
||||||
@@ -100,7 +100,7 @@ yylex (void)
|
|||||||
++outer;
|
++outer;
|
||||||
return END;
|
return END;
|
||||||
}
|
}
|
||||||
return inner++ * 10;
|
return inner++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -170,7 +170,7 @@ EOF
|
|||||||
|
|
||||||
for my $size (1 .. $max)
|
for my $size (1 .. $max)
|
||||||
{
|
{
|
||||||
print "%token \"$size\" ", $size * 10, "\n";
|
print "%token \"$size\" ", $size, "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
print <<EOF;
|
print <<EOF;
|
||||||
@@ -192,7 +192,7 @@ yylex (void)
|
|||||||
if (counter > $max)
|
if (counter > $max)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return counter++ * 10;
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user