mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
Merge remote-tracking branch 'origin/maint'
* origin/maint: (24 commits) tests: calc: modernize the use of locations tests: remove useless location initializations lalr1.cc: always initialize yylval. tests: check that C and C++ objects can be linked together. yacc.c: also disable -Wuninitialized. glr.cc, yacc.c: initialize yylloc properly yacc.c, glr.c: a better YY_LOCATION_PRINT yacc.c: simplify initialization doc: formatting changes c++: fix position operator signatures tests: remove useless location initialization. tests: fix locations in C tests: handle %parse-param in the generated yyerror tests: simplifications grammars: fix display of nul character in error message tests: sort tests: cosmetic changes comment changes autoconf: update gnulib: update ... Conflicts: data/lalr1.cc gnulib src/scan-gram.l submodules/autoconf tests/calc.at
This commit is contained in:
133
tests/actions.at
133
tests/actions.at
@@ -69,6 +69,76 @@ AT_PARSER_CHECK([./input], 0,
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------ ##
|
||||
## Initial location. ##
|
||||
## ------------------ ##
|
||||
|
||||
# AT_TEST(SKELETON-NAME, DIRECTIVES)
|
||||
# ----------------------------------
|
||||
# Check the the initial location is correct.
|
||||
m4_pushdef([AT_TEST],
|
||||
[AT_SETUP([Initial location: $1 $2])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2 %parse-param { int x }])
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
|
||||
%locations
|
||||
%debug
|
||||
%skeleton "$1"
|
||||
$2
|
||||
%parse-param { int x } // Useless, but used to force yyerror purity.
|
||||
%code
|
||||
{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h> // getenv
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
}
|
||||
%%
|
||||
exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
|
||||
[[YY_LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
]AT_YYLEX_PROTOTYPE[
|
||||
{]AT_PURE_IF([
|
||||
YYUSE(lvalp);
|
||||
YYUSE(llocp);], [AT_SKEL_CC_IF([
|
||||
YYUSE(lvalp);
|
||||
YYUSE(llocp);])])[
|
||||
return 'x';
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{]AT_SKEL_CC_IF([[
|
||||
yy::parser p (0);
|
||||
p.set_debug_level (!!getenv("YYDEBUG"));
|
||||
return p.parse ();]], [[
|
||||
yydebug = !!getenv("YYDEBUG");
|
||||
return !!yyparse (0);]])[
|
||||
}
|
||||
]])
|
||||
|
||||
AT_FULL_COMPILE([input])
|
||||
AT_PARSER_CHECK([./input], 1, [],
|
||||
[[1.1
|
||||
1.1: syntax error
|
||||
]])
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
## FIXME: test Java, and iterate over skeletons.
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([yacc.c], [%define api.pure])
|
||||
AT_TEST([yacc.c], [%define api.push-pull both])
|
||||
AT_TEST([yacc.c], [%define api.push-pull both %define api.pure])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
|
||||
|
||||
@@ -159,8 +229,7 @@ main (void)
|
||||
}
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([[-o input.c input.y]])
|
||||
AT_COMPILE([[input]])
|
||||
AT_FULL_COMPILE([input])
|
||||
AT_PARSER_CHECK([[./input]], [[0]],
|
||||
[[6
|
||||
]])
|
||||
@@ -557,7 +626,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
|
||||
# ---------------------------------------------------------------------------
|
||||
m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
|
||||
[AT_SETUP([Printers and Destructors $2: $1])
|
||||
[AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
|
||||
|
||||
$3
|
||||
_AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
|
||||
@@ -595,10 +664,6 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%define parse.error verbose
|
||||
%debug
|
||||
%locations
|
||||
%initial-action {
|
||||
@$.first_line = @$.last_line = 1;
|
||||
@$.first_column = @$.last_column = 1;
|
||||
}
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
@@ -647,8 +712,8 @@ main (void)
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], [], [],
|
||||
[[input.y:27.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:27.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
[[input.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:23.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
AT_PARSER_CHECK([./input], 1,
|
||||
@@ -659,29 +724,29 @@ AT_PARSER_CHECK([./input], 1,
|
||||
]],
|
||||
[[Starting parse
|
||||
Entering state 0
|
||||
Reading a token: Next token is token 'a' (1.1-1.1: <> printer for 'a' @ 1)
|
||||
Shifting token 'a' (1.1-1.1: <> printer for 'a' @ 1)
|
||||
Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
|
||||
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
|
||||
Entering state 1
|
||||
Reading a token: Next token is token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Shifting token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Entering state 3
|
||||
Reading a token: Next token is token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Shifting token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Entering state 5
|
||||
Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4)
|
||||
Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4)
|
||||
Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
|
||||
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
|
||||
Entering state 6
|
||||
Reading a token: Now at end of input.
|
||||
1.5-4: syntax error, unexpected $end, expecting 'e'
|
||||
Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4)
|
||||
1.5: syntax error, unexpected $end, expecting 'e'
|
||||
Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
|
||||
Stack now 0 1 3 5
|
||||
Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||
Stack now 0 1 3
|
||||
Error: popping token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||
Stack now 0 1
|
||||
Error: popping token 'a' (1.1-1.1: <> printer for 'a' @ 1)
|
||||
Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
|
||||
Stack now 0
|
||||
Cleanup: discarding lookahead token $end (1.5-1.5: )
|
||||
Cleanup: discarding lookahead token $end (1.5: )
|
||||
Stack now 0
|
||||
]])
|
||||
|
||||
@@ -835,10 +900,6 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]],
|
||||
[[%define parse.error verbose
|
||||
%debug
|
||||
%locations
|
||||
%initial-action {
|
||||
@$.first_line = @$.last_line = 1;
|
||||
@$.first_column = @$.last_column = 1;
|
||||
}
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
@@ -899,11 +960,11 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
|
||||
[m4_if([$1], [0],
|
||||
[[input0.y:27.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input0.y:27.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
[[input0.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input0.y:23.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
]],
|
||||
[[input1.y:27.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input1.y:27.3-4: warning: useless %printer for type <> [-Wother]
|
||||
[[input1.y:23.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input1.y:23.3-4: warning: useless %printer for type <> [-Wother]
|
||||
]])])
|
||||
|
||||
AT_COMPILE([input$1])
|
||||
@@ -914,16 +975,16 @@ AT_PARSER_CHECK([./input$1], 0,
|
||||
]],
|
||||
[[Starting parse
|
||||
Entering state 0
|
||||
Reducing stack by rule 1 (line 46):
|
||||
-> $$ = nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1)
|
||||
Reducing stack by rule 1 (line 42):
|
||||
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||
Stack now 0
|
||||
Entering state 1
|
||||
Reading a token: Now at end of input.
|
||||
Shifting token END (1.1-1.1: <]]kind[[> for 'E' @ 1)
|
||||
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||
Entering state 2
|
||||
Stack now 0 1 2
|
||||
Cleanup: popping token END (1.1-1.1: <]]kind[[> for 'E' @ 1)
|
||||
Cleanup: popping nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1)
|
||||
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||
]])
|
||||
|
||||
m4_popdef([kind])
|
||||
|
||||
@@ -178,18 +178,7 @@ read_signed_integer (]AT_YYLEX_FORMALS[)
|
||||
|
||||
]AT_YYLEX_PROTOTYPE[
|
||||
{
|
||||
static int init = 1;
|
||||
int c;
|
||||
|
||||
if (init)
|
||||
{
|
||||
init = 0;
|
||||
]AT_LOCATION_IF([
|
||||
AT_LOC_LAST_COLUMN = 1;
|
||||
AT_LOC_LAST_LINE = 1;
|
||||
])[
|
||||
}
|
||||
|
||||
/* Skip current token, then white spaces. */
|
||||
do
|
||||
{
|
||||
@@ -261,6 +250,8 @@ AT_SKEL_CC_IF(
|
||||
{
|
||||
semantic_value ival;
|
||||
};
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyoutput, "%d", $$)]])[; } <ival>;
|
||||
|
||||
%code provides
|
||||
{
|
||||
@@ -280,24 +271,16 @@ AT_SKEL_CC_IF(
|
||||
FILE *input;
|
||||
static int power (int base, int exponent);
|
||||
|
||||
]AT_SKEL_CC_IF(,
|
||||
[static void yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
|
||||
AT_PARAM_IF([semantic_value *result, int *count, ])
|
||||
const char *s
|
||||
);])[
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE_EXTERN[
|
||||
}
|
||||
|
||||
]AT_SKEL_CC_IF([AT_LOCATION_IF([AT_LOCATION_TYPE_IF([], [
|
||||
/* The lalr1.cc skeleton, for backward compatibility, defines
|
||||
a constructor for position that initializes the filename. The
|
||||
glr.cc skeleton does not (and in fact cannot: location/position
|
||||
are stored in a union, from which objects with constructors are
|
||||
excluded in C++). */
|
||||
%initial-action {
|
||||
@$.initialize ();
|
||||
}
|
||||
])])])[
|
||||
]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([[
|
||||
%initial-action
|
||||
{
|
||||
@$.first.l = @$.first.c = 1;
|
||||
@$.last = @$.first;
|
||||
}]])])[
|
||||
|
||||
/* Bison Declarations */
|
||||
%token CALC_EOF 0 "end of input"
|
||||
@@ -365,27 +348,8 @@ power (int base, int exponent)
|
||||
o << '-' << s.last.c - 1;
|
||||
return o;
|
||||
}
|
||||
]])
|
||||
AT_YYERROR_DEFINE],
|
||||
[/* A C error reporting function. */
|
||||
static void
|
||||
yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
|
||||
AT_PARAM_IF([semantic_value *result, int *count, ])
|
||||
const char *s)
|
||||
{
|
||||
AT_PARAM_IF([(void) result; (void) count;])
|
||||
AT_YYERROR_SEES_LOC_IF([
|
||||
fprintf (stderr, "%d.%d",
|
||||
AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);
|
||||
if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE)
|
||||
fprintf (stderr, "-%d.%d",
|
||||
AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1);
|
||||
else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1)
|
||||
fprintf (stderr, "-%d",
|
||||
AT_LOC_LAST_COLUMN - 1);
|
||||
fprintf (stderr, ": ");])
|
||||
fprintf (stderr, "%s\n", s);
|
||||
}])[
|
||||
]])])[
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_DEFINES_IF([],
|
||||
[AT_CALC_LEX
|
||||
AT_CALC_MAIN])])
|
||||
@@ -552,7 +516,7 @@ _AT_CHECK_CALC([$1],
|
||||
[842])
|
||||
|
||||
# Some syntax errors.
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15],
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 2], [15],
|
||||
[1.3: syntax error, unexpected number])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
|
||||
[1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
|
||||
@@ -596,10 +560,10 @@ calc: error: 4444 != 1])
|
||||
|
||||
# The same, but this time exercising explicitly triggered syntax errors.
|
||||
# POSIX says the lookahead causing the error should not be discarded.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1], [102],
|
||||
[1.10: syntax error, unexpected number
|
||||
calc: error: 2222 != 1])
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1], [113],
|
||||
[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
1.12: syntax error, unexpected number
|
||||
calc: error: 2222 != 1])
|
||||
@@ -656,7 +620,7 @@ AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %defi
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
|
||||
# ----------------------- #
|
||||
@@ -694,8 +658,8 @@ AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %defin
|
||||
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
|
||||
# ----------------------------- #
|
||||
@@ -725,10 +689,10 @@ AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-pref
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
AT_CHECK_CALC_LALR1_CC([%pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
|
||||
|
||||
@@ -760,5 +724,5 @@ AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %ve
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix "TOK_" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %defines %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
|
||||
@@ -376,7 +376,7 @@ m4_define([_AT_GLR_STDERR],
|
||||
]])
|
||||
|
||||
m4_define([_AT_GLR_STDERR_WITH_LOC],
|
||||
[[17.5-4: syntax error
|
||||
[[17.5: syntax error
|
||||
]])
|
||||
|
||||
m4_define([_AT_VERBOSE_GLR_STDERR],
|
||||
@@ -384,7 +384,7 @@ m4_define([_AT_VERBOSE_GLR_STDERR],
|
||||
]])
|
||||
|
||||
m4_define([_AT_VERBOSE_GLR_STDERR_WITH_LOC],
|
||||
[[17.5-4: syntax error, unexpected ID, expecting '=' or '+' or ')'
|
||||
[[17.5: syntax error, unexpected ID, expecting '=' or '+' or ')'
|
||||
]])
|
||||
|
||||
## ---------------------------------------------------- ##
|
||||
|
||||
@@ -1545,13 +1545,6 @@ AT_DATA_GRAMMAR([glr-regr17.y],
|
||||
]AT_YYLEX_DECLARE[
|
||||
%}
|
||||
|
||||
%initial-action {
|
||||
@$.first_line = 1;
|
||||
@$.first_column = 1;
|
||||
@$.last_line = 1;
|
||||
@$.last_column = 1;
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
/* Tests the case of an empty RHS that has inherited the location of the
|
||||
|
||||
@@ -241,9 +241,6 @@ AT_TEST([x7], [%define api.push-pull both])
|
||||
AT_TEST([x8], [%define api.pure %define api.push-pull both])
|
||||
#AT_TEST([x5], [%locations %language "c++" %glr-parser])
|
||||
|
||||
AT_COMPILE_CXX([parser], [[x[1-8].o -DCC_IS_CXX=$CC_IS_CXX main.cc]])
|
||||
AT_CHECK([./parser], [0], [[expout]])
|
||||
|
||||
# Check that the headers are self-contained, and protected against
|
||||
# multiple inclusions. While at it, check they are sane for C++.
|
||||
for h in *.h *.hh
|
||||
@@ -257,6 +254,12 @@ EOF
|
||||
AT_COMPILE_CXX([$h.o])
|
||||
done
|
||||
|
||||
# Do this late, so that other checks have been performed.
|
||||
AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
|
||||
|
||||
AT_COMPILE_CXX([parser], [[x[1-8].o -DCC_IS_CXX=$CC_IS_CXX main.cc]])
|
||||
AT_CHECK([./parser], [0], [[expout]])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -20,6 +20,67 @@ AT_BANNER([[Input Processing.]])
|
||||
# Mostly test that we are robust to mistakes.
|
||||
|
||||
|
||||
## ---------------- ##
|
||||
## Invalid inputs. ##
|
||||
## ---------------- ##
|
||||
|
||||
AT_SETUP([Invalid inputs])
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[\000\001\002\377?
|
||||
%%
|
||||
?
|
||||
default: 'a' }
|
||||
%&
|
||||
%a-does-not-exist
|
||||
%-
|
||||
%{
|
||||
]])
|
||||
AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]])
|
||||
|
||||
AT_BISON_CHECK([input.y], [1], [],
|
||||
[[input.y:1.1: error: invalid character: '\0'
|
||||
input.y:1.1: error: invalid character: '\001'
|
||||
input.y:1.1: error: invalid character: '\002'
|
||||
input.y:1.1: error: invalid character: '\377'
|
||||
input.y:1.2: error: invalid character: '?'
|
||||
input.y:3.1: error: invalid character: '?'
|
||||
input.y:4.14: error: invalid character: '}'
|
||||
input.y:5.1: error: invalid character: '%'
|
||||
input.y:5.2: error: invalid character: '&'
|
||||
input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
|
||||
input.y:7.1: error: invalid character: '%'
|
||||
input.y:7.2: error: invalid character: '-'
|
||||
input.y:8.1-9.0: error: missing '%}' at end of file
|
||||
input.y:8.1-9.0: error: syntax error, unexpected %{...%}
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
AT_SETUP([Invalid inputs with {}])
|
||||
|
||||
# We used to SEGV here. See
|
||||
# http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[
|
||||
%destructor
|
||||
%initial-action
|
||||
%lex-param
|
||||
%parse-param
|
||||
%printer
|
||||
%union
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([input.y], [1], [],
|
||||
[[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## ------------ ##
|
||||
## Invalid $n. ##
|
||||
## ------------ ##
|
||||
|
||||
@@ -119,6 +119,7 @@ m4_pushdef([AT_SKEL_CC_IF],
|
||||
[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
|
||||
m4_pushdef([AT_SKEL_JAVA_IF],
|
||||
[m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
|
||||
# The target language: "c", "c++", or "java".
|
||||
m4_pushdef([AT_LANG],
|
||||
[AT_SKEL_JAVA_IF([java],
|
||||
[AT_SKEL_CC_IF([c++],
|
||||
@@ -140,6 +141,13 @@ m4_pushdef([AT_LOCATION_TYPE_IF],
|
||||
[m4_bmatch([$3], [%define \(api\.location\.type\|location_type\)], [$1], [$2])])
|
||||
m4_pushdef([AT_PARAM_IF],
|
||||
[m4_bmatch([$3], [%parse-param], [$1], [$2])])
|
||||
# Comma-terminated list of formals parse-parameters.
|
||||
# E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
|
||||
# FIXME: Support grouped parse-param.
|
||||
m4_pushdef([AT_PARSE_PARAMS])
|
||||
m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}],
|
||||
[m4_append([AT_PARSE_PARAMS], [\1, ])])
|
||||
|
||||
m4_pushdef([AT_PURE_IF],
|
||||
[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
|
||||
[m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])],
|
||||
@@ -250,6 +258,7 @@ m4_popdef([AT_GLR_OR_PARAM_IF])
|
||||
m4_popdef([AT_PURE_AND_LOC_IF])
|
||||
m4_popdef([AT_LOCATION_TYPE_IF])
|
||||
m4_popdef([AT_LOCATION_IF])
|
||||
m4_popdef([AT_PARSE_PARAMS])
|
||||
m4_popdef([AT_PARAM_IF])
|
||||
m4_popdef([AT_LEXPARAM_IF])
|
||||
m4_popdef([AT_YACC_IF])
|
||||
@@ -359,7 +368,7 @@ static
|
||||
# Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
|
||||
m4_define([AT_YYERROR_FORMALS],
|
||||
[m4_case(AT_LANG,
|
||||
[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])[const char *msg]])[]dnl
|
||||
[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])AT_PARSE_PARAMS [const char *msg]])[]dnl
|
||||
])
|
||||
|
||||
m4_define([AT_YYERROR_PROTOTYPE],
|
||||
@@ -383,16 +392,11 @@ m4_define([AT_YYERROR_DEFINE],
|
||||
/* A C error reporting function. */
|
||||
static
|
||||
]AT_YYERROR_PROTOTYPE[
|
||||
{
|
||||
]AT_YYERROR_SEES_LOC_IF([[
|
||||
fprintf (stderr, "%d.%d",
|
||||
]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
|
||||
if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[)
|
||||
fprintf (stderr, "-%d.%d",
|
||||
]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1);
|
||||
else if (]AT_LOC_FIRST_COLUMN[ != ]AT_LOC_LAST_COLUMN[ - 1)
|
||||
fprintf (stderr, "-%d",
|
||||
]AT_LOC_LAST_COLUMN[ - 1);
|
||||
{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
|
||||
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
|
||||
YYUSE(\1);])dnl
|
||||
AT_YYERROR_SEES_LOC_IF([[
|
||||
YY_LOCATION_PRINT (stderr, ]AT_LOC[);
|
||||
fprintf (stderr, ": ");]])[
|
||||
fprintf (stderr, "%s\n", msg);
|
||||
}]],
|
||||
@@ -660,6 +664,44 @@ m4_define([AT_FULL_COMPILE],
|
||||
])
|
||||
|
||||
|
||||
|
||||
# AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
|
||||
# --------------------------------
|
||||
# Check that we can link together C and C++ objects.
|
||||
m4_define([AT_SKIP_IF_CANNOT_LINK_C_AND_CXX],
|
||||
[AT_DATA([c-and-cxx.h],
|
||||
[[#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
int fortytwo (void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
]])
|
||||
AT_DATA([c-only.c],
|
||||
[[#include "c-and-cxx.h"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
return fortytwo () == 42 ? 0 : 1;
|
||||
}
|
||||
]])
|
||||
AT_DATA([cxx-only.cc],
|
||||
[[#include "c-and-cxx.h"
|
||||
int fortytwo ()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
]])
|
||||
AT_COMPILE([c-only.o], [c-only.c])
|
||||
AT_COMPILE_CXX([cxx-only.o], [cxx-only.cc])
|
||||
AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS $LDFLAGS c-only.o cxx-only.o -o c-and-cxx ||
|
||||
exit 77], [ignore], [ignore])
|
||||
AT_CHECK([./c-and-cxx])
|
||||
])
|
||||
|
||||
|
||||
## ---------------------------- ##
|
||||
## Running a generated parser. ##
|
||||
## ---------------------------- ##
|
||||
|
||||
@@ -443,14 +443,19 @@ AT_SETUP([Stray symbols in brackets])
|
||||
AT_DATA_GRAMMAR([test.y],
|
||||
[[
|
||||
%%
|
||||
start: foo[ /* aaa */ *&-.+ ] bar
|
||||
start: foo[ /* aaa */ *&-.+\000\001\002\377 ] bar
|
||||
{ s = $foo; }
|
||||
]])
|
||||
AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y || exit 77]])
|
||||
AT_BISON_CHECK([-o test.c test.y], 1, [],
|
||||
[[test.y:11.23: error: invalid character in bracketed name: '*'
|
||||
test.y:11.24: error: invalid character in bracketed name: '&'
|
||||
test.y:11.25: error: invalid character in bracketed name: '-'
|
||||
test.y:11.27: error: invalid character in bracketed name: '+'
|
||||
test.y:11.28: error: invalid character in bracketed name: '\0'
|
||||
test.y:11.28: error: invalid character in bracketed name: '\001'
|
||||
test.y:11.28: error: invalid character in bracketed name: '\002'
|
||||
test.y:11.28: error: invalid character in bracketed name: '\377'
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
@@ -1590,14 +1590,14 @@ AT_CLEANUP
|
||||
m4_pushdef([AT_TEST],
|
||||
[AT_SETUP([[Lex and parse params: $1]])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1])
|
||||
AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" %parse-param { int x } %parse-param { int y }])
|
||||
|
||||
## FIXME: Improve parsing of parse-param and use the generated
|
||||
## yyerror.
|
||||
AT_DATA_GRAMMAR([input.y],
|
||||
[[%defines
|
||||
%locations
|
||||
%skeleton $1
|
||||
%skeleton "$1"
|
||||
%union { int ival; }
|
||||
%parse-param { int x }
|
||||
// Spaces, tabs, and new lines.
|
||||
@@ -1611,26 +1611,18 @@ AT_DATA_GRAMMAR([input.y],
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
]AT_SKEL_CC_IF([], [[
|
||||
static
|
||||
void
|
||||
yyerror (int x, int y, const char *msg)
|
||||
{
|
||||
fprintf (stderr, "x: %d, y: %d, %s\n", x, y, msg);
|
||||
}]])[
|
||||
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
%}
|
||||
|
||||
%%
|
||||
exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(["a"])[
|
||||
|
||||
]AT_SKEL_CC_IF(
|
||||
[AT_YYERROR_DEFINE
|
||||
|
||||
int
|
||||
[int
|
||||
yyparse (int x, int y)
|
||||
{
|
||||
yy::parser parser(x, y);
|
||||
@@ -1654,9 +1646,9 @@ AT_CLEANUP
|
||||
])
|
||||
|
||||
## FIXME: test Java, and iterate over skeletons.
|
||||
AT_TEST("yacc.c")
|
||||
AT_TEST("glr.c")
|
||||
AT_TEST("lalr1.cc")
|
||||
AT_TEST("glr.cc")
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
Reference in New Issue
Block a user