+2002-11-15 Paul Eggert <eggert@twinsun.com>
+
+ * data/glr.c, data/lalr1.cc, data/yacc.cc, doc/bison.texinfo,
+ src/conflicts.c, src/parse-gram.y, src/tables.c, src/tables.h,
+ tests/action.at, tests/calc.at, tests/conflicts.at,
+ tests/cxx-type.at, tests/regression.at:
+ "parse error" -> "syntax error" for POSIX compatibility.
+ "parsing stack overflow..." -> "parser stack overflow" so
+ that code matches Bison documentation.
+
2002-11-15 Akim Demaille <akim@epita.fr>
* src/parse-gram.y (declaration): Have %parse-param and %lex-param
----------
Changes in version 1.75c:
+* "parse error" -> "syntax error"
+ Bison now uniformly uses the term "syntax error"; formerly, the code
+ and manual sometimes used the term "parse error" instead. POSIX
+ requires "syntax error" in diagnostics, and it was thought better to
+ be consistent.
+
+* "parsing stack overflow..." -> "parser stack overflow"
+ GLR parsers now report "parser stack overflow" as per the Bison manual.
+
* GLR and inline
Users of Bison have to decide how they handle the portability of the
C keyword `inline'.
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says.
- If YYTABLE_NINF, parse error. */
+ If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF ]b4_table_ninf[
static const ]b4_int_type_for([b4_table])[ yytable[] =
{
size_t yyn;
yysize = yystack->yynextFree - yystack->yyitems;
if (YYMAXDEPTH <= yysize)
- yyFail (yystack][]b4_pure_args[,
- "parsing stack overflow (%d items)", yysize);
+ yyFail (yystack][]b4_pure_args[, "parser stack overflow");
yynewSize = 2*yysize;
if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH;
#else
- yyFail (yystack][]b4_lpure_args[,
- "parsing stack overflow (%d items)", yysize);
+ yyFail (yystack][]b4_lpure_args[, "parser stack overflow");
#endif
}
yycount = 0;
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */
- yysize = sizeof ("parse error, unexpected ")
+ yysize = sizeof ("syntax error, unexpected ")
+ strlen (yytokenName (*yytokenp));
yyprefix = ", expecting ";
for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
yycount += 1, yyprefix = " or ";
yymsg = yyp = (char*) malloc (yysize);
- sprintf (yyp, "parse error, unexpected %s", yytokenName (*yytokenp));
+ sprintf (yyp, "syntax error, unexpected %s",
+ yytokenName (*yytokenp));
yyp += strlen (yyp);
if (yycount < 5)
{
}
else
#endif
- yyerror (]b4_lyyerror_args["parse error");
+ yyerror (]b4_lyyerror_args["syntax error");
yynerrs += 1;
}
}
{
yyundeleteLastStack (&yystack);
if (yystack.yytops.yysize == 0)
- yyFail (&yystack][]b4_lpure_args[, "parse error");
+ yyFail (&yystack][]b4_lpure_args[, "syntax error");
YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
yyreportParseError (&yystack, yylvalp, yyllocp]b4_user_args[);
n_ = pact_[[state_]];
if (pact_ninf_ < n_ && n_ < last_)
{
- message = "parse error, unexpected ";
+ message = "syntax error, unexpected ";
message += name_[[ilooka_]];
{
int count = 0;
}
else
#endif
- message = "parse error";
+ message = "syntax error";
error_ ();
}
goto yyerrlab1;
/* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says.
- If YYTABLE_NINF, parse error. */
+ If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF b4_table_ninf
static const b4_int_type_for([b4_table]) yytable[[]] =
{
/* The semantic value of the lookahead symbol. */
YYSTYPE yylval;
-/* Number of parse errors so far. */
+/* Number of syntax errors so far. */
int yynerrs;b4_location_if([
/* Location data for the lookahead symbol. */
YYLTYPE yylloc;])
yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
yysize += yystrlen (yytname[yyx]) + 15, yycount++;
- yysize += yystrlen ("parse error, unexpected ") + 1;
+ yysize += yystrlen ("syntax error, unexpected ") + 1;
yysize += yystrlen (yytname[yytype]);
yymsg = (char *) YYSTACK_ALLOC (yysize);
if (yymsg != 0)
{
- char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
+ char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
yyp = yystpcpy (yyp, yytname[yytype]);
if (yycount < 5)
YYSTACK_FREE (yymsg);
}
else
- yyerror (]b4_yyerror_args["parse error; also virtual memory exhausted");
+ yyerror (]b4_yyerror_args["syntax error; also virtual memory exhausted");
}
else
#endif /* YYERROR_VERBOSE */
- yyerror (]b4_yyerror_args["parse error");
+ yyerror (]b4_yyerror_args["syntax error");
}
goto yyerrlab1;
When @code{yyparse} detects a syntax error, it calls the error reporting
function @code{yyerror} to print an error message (usually but not
-always @code{"parse error"}). It is up to the programmer to supply
+always @code{"syntax error"}). It is up to the programmer to supply
@code{yyerror} (@pxref{Interface, ,Parser C-Language Interface}), so
here is the definition we will use:
@end example
This addition to the grammar allows for simple error recovery in the
-event of a parse error. If an expression that cannot be evaluated is
+event of a syntax error. If an expression that cannot be evaluated is
read, the error will be recognized by the third rule for @code{line},
and parsing will continue. (The @code{yyerror} function is still called
upon to print its message as well.) The action executes the statement
,Special Features for Use in Actions}). This mode is enabled as soon as
the grammar uses the special @samp{@@@var{n}} tokens, but if your
grammar does not use it, using @samp{%locations} allows for more
-accurate parse error messages.
+accurate syntax error messages.
@end deffn
@deffn {Directive} %name-prefix="@var{prefix}"
@cindex parse error
@cindex syntax error
-The Bison parser detects a @dfn{parse error} or @dfn{syntax error}
+The Bison parser detects a @dfn{syntax error} or @dfn{parse error}
whenever it reads a token which cannot satisfy any syntax rule. An
action in the grammar can also explicitly proclaim an error, using the
macro @code{YYERROR} (@pxref{Action Features, ,Special Features for Use
The Bison parser expects to report the error by calling an error
reporting function named @code{yyerror}, which you must supply. It is
called by @code{yyparse} whenever a syntax error is found, and it
-receives one argument. For a parse error, the string is normally
-@w{@code{"parse error"}}.
+receives one argument. For a syntax error, the string is normally
+@w{@code{"syntax error"}}.
@findex %error-verbose
If you invoke the directive @code{%error-verbose} in the Bison
declarations section (@pxref{Bison Declarations, ,The Bison Declarations
Section}), then Bison provides a more verbose and specific error message
-string instead of just plain @w{@code{"parse error"}}.
+string instead of just plain @w{@code{"syntax error"}}.
The parser can detect one other kind of error: stack overflow. This
happens when the input contains constructions that are very deeply
@cindex error recovery
@cindex recovery from errors
-It is not usually acceptable to have a program terminate on a parse
+It is not usually acceptable to have a program terminate on a syntax
error. For example, a compiler should recover sufficiently to parse the
rest of the input file and check it for errors; a calculator should accept
another expression.
this token. Write the statement @samp{yyclearin;} in the error rule's
action.
-For example, suppose that on a parse error, an error handling routine is
+For example, suppose that on a syntax error, an error handling routine is
called that advances the input stream to some point where parsing should
once again commence. The next symbol returned by the lexical scanner is
probably correct. The previous look-ahead token ought to be discarded
flow jumps to state 2. If there is no such transition on a nonterminal
symbol, and the lookahead is a @code{NUM}, then this token is shifted on
the parse stack, and the control flow jumps to state 1. Any other
-lookahead triggers a parse error.''
+lookahead triggers a syntax error.''
@cindex core, item set
@cindex item set core
@samp{+}, it will be shifted on the parse stack, and the automaton
control will jump to state 4, corresponding to the item @samp{exp -> exp
'+' . exp}. Since there is no default action, any other token than
-those listed above will trigger a parse error.
+those listed above will trigger a syntax error.
The state 3 is named the @dfn{final state}, or the @dfn{accepting
state}:
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
the grammar without halting the process. In effect, a sentence
-containing an error may be recognized as valid. On a parse error, the
+containing an error may be recognized as valid. On a syntax error, the
token @code{error} becomes the current look-ahead token. Actions
corresponding to @code{error} are then executed, and the look-ahead
token is reset to the token that originally caused the violation.
@deffn {Macro} yyerrok
Macro to cause parser to recover immediately to its normal mode
-after a parse error. @xref{Error Recovery}.
+after a syntax error. @xref{Error Recovery}.
@end deffn
@deffn {Function} yyerror
@end deffn
@deffn {Variable} yynerrs
-Global variable which Bison increments each time there is a parse error.
+Global variable which Bison increments each time there is a syntax error.
(In a pure parser, it is a local variable within @code{yyparse}.)
@xref{Error Reporting, ,The Error Reporting Function @code{yyerror}}.
@end deffn
be expressed through rules in terms of smaller constructs; in other
words, a construct that is not a token. @xref{Symbols}.
-@item Parse error
-An error encountered during parsing of an input stream due to invalid
-syntax. @xref{Error Recovery}.
-
@item Parser
A function that recognizes valid sentences of a language by analyzing
the syntax structure of a set of tokens passed to it from a lexical
during parsing to allow for recognition and use of existing
information in repeated uses of a symbol. @xref{Multi-function Calc}.
+@item Syntax error
+An error encountered during parsing of an input stream due to invalid
+syntax. @xref{Error Recovery}.
+
@item Token
A basic, grammatically indivisible unit of a language. The symbol
that describes a token in the grammar is a terminal symbol.
| Solve the S/R conflicts of STATE using the |
| precedence/associativity, and flag it inconsistent if it still has |
| conflicts. ERRS can be used as storage to compute the list of |
-| lookaheads on which this STATE raises a parse error (%nonassoc). |
+| lookaheads on which this STATE raises a syntax error (%nonassoc). |
`-------------------------------------------------------------------*/
static void
conflicts_solve (void)
{
state_number_t i;
- /* List of lookaheads on which we explicitly raise a parse error. */
+ /* List of lookaheads on which we explicitly raise a syntax error. */
symbol_t **errs = XMALLOC (symbol_t *, ntokens + 1);
conflicts = XCALLOC (char, nstates);
#include "reader.h"
#include "conflicts.h"
-/* Produce verbose parse errors. */
+/* Produce verbose syntax errors. */
#define YYERROR_VERBOSE 1
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
correctly typed access to it. */
#define yycontrol ((gram_control_t *) gram_control)
-/* Request detailed parse error messages, and pass them to GRAM_ERROR.
+/* Request detailed syntax error messages, and pass them to GRAM_ERROR.
FIXME: depends on the undocumented availability of YYLLOC.t */
#undef yyerror
#define yyerror(Msg) \
/* For a given state, N = ACTROW[SYMBOL]:
If N = 0, stands for `run the default action'.
- If N = MIN, stands for `raise a parse error'.
+ If N = MIN, stands for `raise a syntax error'.
If N > 0, stands for `shift SYMBOL and go to n'.
If N < 0, stands for `reduce -N'. */
typedef short action_t;
static size_t table_size = 32768;
base_t *table = NULL;
base_t *check = NULL;
-/* The value used in TABLE to denote explicit parse errors
+/* The value used in TABLE to denote explicit syntax errors
(%nonassoc), a negative infinite. First defaults to ACTION_MIN,
but in order to keep small tables, renumbered as TABLE_ERROR, which
is the smallest (non error) value minus 1. */
extern base_t *table;
extern base_t *check;
-/* The value used in TABLE to denote explicit parse errors
+/* The value used in TABLE to denote explicit syntax errors
(%nonassoc), a negative infinite. */
extern base_t table_ninf;
sending: 'x' (value = 2, line 20)
thing(2@20): 'x'(2@20)
sending: 'x' (value = 3, line 30)
-30: parse error, unexpected 'x', expecting ';'
+30: syntax error, unexpected 'x', expecting ';'
Freeing nterm thing (2@20)
Freeing nterm thing (1@10)
Freeing nterm thing (0@0)
sending: ';' (value = 11, line 110)
line(10@100): thing(10@100) ';'
sending: 'y' (value = 12, line 120)
-120: parse error, unexpected $undefined, expecting $end or 'x'
+120: syntax error, unexpected $undefined, expecting $end or 'x'
sending: EOF
Freeing nterm line (10@100)
Freeing nterm line (7@70)
# [NUM-DEBUG-LINES],
# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
# ---------------------------------------------------------
-# Run `calc' on INPUT, and expect a `parse error' message.
+# Run `calc' on INPUT, and expect a `syntax error' message.
#
# If INPUT starts with a slash, it is used as absolute input file name,
# otherwise as contents.
# is correctly output on stderr.
#
# If BISON-OPTIONS contains `%error-verbose', then make sure the
-# IF-YYERROR-VERBOSE message is properly output after `parse error, '
+# IF-YYERROR-VERBOSE message is properly output after `syntax error, '
# on STDERR.
#
# If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES
mv at-expout expout]])
# 4. If error-verbose is not used, strip the`, unexpected....' part.
m4_bmatch([$1], [%error-verbose], [],
-[[sed 's/parse error, .*$/parse error/' expout >at-expout
+[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout]])
# 5. Check
AT_CHECK([cat stderr], 0, [expout])
(2^2)^3 = 64],
[486])
-# Some parse errors.
+# Some syntax errors.
_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [11],
- [1.3-1.4: parse error, unexpected "number"])
+ [1.3-1.4: syntax error, unexpected "number"])
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [15],
- [1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
+ [1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('])
_AT_CHECK_CALC_ERROR([$1], [1], [error], [4],
- [1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '('])
+ [1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('])
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [22],
- [1.7-1.8: parse error, unexpected '='])
+ [1.7-1.8: syntax error, unexpected '='])
_AT_CHECK_CALC_ERROR([$1], [1],
[
+1],
[14],
- [2.1-2.2: parse error, unexpected '+'])
+ [2.1-2.2: syntax error, unexpected '+'])
# Exercise error messages with EOF: work on an empty file.
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
- [1.1-1.2: parse error, unexpected "end of input", expecting "number" or '-' or '\n' or '('])
+ [1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('])
# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
_AT_CHECK_CALC_ERROR([$1], [0], [(1 ++ 2) + (0 0) = 1], [82],
-[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
-1.15-1.16: parse error, unexpected "number"
+[1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
+1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1])
AT_CHECK_POPDEFS
# no one has ever spotted it! The messages are *wrong*: there should
# be nothing there, it should be expected eof.
AT_PARSER_CHECK([./input '0<0<0'], [1], [],
- [parse error, unexpected '<', expecting '<' or '>'
+ [syntax error, unexpected '<', expecting '<' or '>'
])
AT_PARSER_CHECK([./input '0>0'])
AT_PARSER_CHECK([./input '0>0>0'], [1], [],
- [parse error, unexpected '>', expecting '<' or '>'
+ [syntax error, unexpected '>', expecting '<' or '>'
])
AT_PARSER_CHECK([./input '0<0>0'], [1], [],
- [parse error, unexpected '>', expecting '<' or '>'
+ [syntax error, unexpected '>', expecting '<' or '>'
])
AT_CLEANUP
]])
m4_define([_AT_GLR_STDERR],
-[[parse error
+[[syntax error
]])
m4_define([_AT_VERBOSE_GLR_STDERR],
-[[parse error, unexpected ID, expecting '=' or '+' or ')'
+[[syntax error, unexpected ID, expecting '=' or '+' or ')'
]])
## ---------------------------------------------------- ##
input.y:6.1: invalid character: `%'
input.y:6.2: invalid character: `-'
input.y:7.1-8.0: missing `%}' at end of file
-input.y:7.1-8.0: parse error, unexpected "%{...%}", expecting ";" or "|"
+input.y:7.1-8.0: syntax error, unexpected "%{...%}", expecting ";" or "|"
]])
AT_CLEANUP