Merge remote-tracking branch 'origin/maint'

* origin/maint:
  yacc.c: always initialize yylloc
  scanner: issue a single error for groups of invalid characters
  tests: formatting changes
  doc: one of the fixes for an ambiguous grammar was ambiguous too
  doc: fix the dangling else with precedence directives
  doc: prefer "token" to TOKEN
  doc: formatting changes
  scanner: use explicit "ignore" statements

Conflicts:
	src/scan-gram.l
This commit is contained in:
Akim Demaille
2012-11-26 09:14:51 +01:00
8 changed files with 224 additions and 86 deletions

View File

@@ -73,8 +73,8 @@ AT_CLEANUP
## Initial location. ##
## ------------------ ##
# AT_TEST(SKELETON-NAME, DIRECTIVES)
# ----------------------------------
# AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
# -----------------------------------------------------------------------
# Check that the initial location is correct.
m4_pushdef([AT_TEST],
[AT_SETUP([Initial location: $1 $2])
@@ -85,7 +85,8 @@ AT_DATA_GRAMMAR([[input.y]],
%locations
%debug
%skeleton "$1"
$2
]$2[
]$3[
%parse-param { int x } // Useless, but used to force yyerror purity.
%code
{
@@ -122,8 +123,8 @@ main (void)
AT_FULL_COMPILE([input])
AT_PARSER_CHECK([./input], 1, [],
[[1.1
1.1: syntax error
[m4_default([$4], [1.1])
m4_default([$4], [1.1])[: syntax error
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -138,6 +139,36 @@ AT_TEST([glr.c])
AT_TEST([lalr1.cc])
AT_TEST([glr.cc])
## A very different test, based on PostgreSQL's implementation of the
## locations. See
## http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
##
## Weirdly enough, to trigger the warning with GCC 4.7, we must not
## use fprintf, so run the test twice: once to check the warning
## (absence thereof), and another time to check the value.
AT_TEST([yacc.c], [%define api.pure],
[[%{
# define YYLTYPE int
# define YY_LOCATION_PRINT(Stream, Loc) \
(void) (Loc)
# define YYLLOC_DEFAULT(Current, Rhs, N) \
(Current) = ((Rhs)[N ? 1 : 0])
%}
]],
[@&t@])
AT_TEST([yacc.c], [%define api.pure],
[[%{
# define YYLTYPE int
# define YY_LOCATION_PRINT(Stream, Loc) \
fprintf ((Stream), "%d", (Loc))
# define YYLLOC_DEFAULT(Current, Rhs, N) \
(Current) = ((Rhs)[N ? 1 : 0])
%}
]],
[0])
m4_popdef([AT_TEST])

View File

@@ -39,11 +39,7 @@ default: 'a' }
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:1.1-2: error: invalid characters: '\0\001\002\377?'
input.y:3.1: error: invalid character: '?'
input.y:4.14: error: invalid character: '}'
input.y:5.1: error: invalid character: '%'

View File

@@ -55,12 +55,12 @@ static int power (int base, int exponent);
%%
input:
line
| input line { }
| input line {}
;
line:
'\n'
| exp '\n' { }
| exp '\n' {}
;
exp:
@@ -72,12 +72,12 @@ exp:
$$ = $l;
}
| exp[x] '+' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>l + $r; }
| exp[l] '-' exp[r] { $$ = $l - $r; }
| exp[l] '*' exp[r] { $$ = $l * $r; }
| exp[l] '-' exp[r] { $$ = $l - $r; }
| exp[l] '*' exp[r] { $$ = $l * $r; }
| exp[l] '/' exp[r] { $$ = $l / $r; }
| '-' exp %prec NEG { $$ = -$2; }
| exp[l] '^' exp[r] { $$ = power ($l, $r); }
| '(' exp[e] ')' { $$ = $e; }
| exp[l] '^' exp[r] { $$ = power ($l, $r); }
| '(' exp[e] ')' { $$ = $e; }
| '(' error ')' { $$ = 1111; yyerrok; }
| '!' { $$ = 0; YYERROR; }
| '-' error { $$ = 0; YYERROR; }
@@ -220,12 +220,12 @@ static int power (int base, int exponent);
%%
input:
line
| input line { }
| input line {}
;
line:
'\n'
| exp '\n' { }
| exp '\n' {}
;
exp:
@@ -241,7 +241,7 @@ exp:
| exp[x] '*' { $<ival>$ = $x; } [l] exp[r] { $$ = $l * $r; }
| exp[l] '/' exp[r] { $$ = $l / $r; }
| '-' exp %prec NEG { $$ = -$2; }
| exp[l] '^' exp[r] { $$ = power ($l, $r12); }
| exp[l] '^' exp[r] { $$ = power ($l, $r12); }
| '(' exp ')' { $$ = $expo; }
| '(' error ')' { $$ = 1111; yyerrok; }
| '!' { $$ = 0; YYERROR; }
@@ -258,8 +258,8 @@ test.y:42.1-3: refers to: $exp at $$
test.y:51.7: possibly meant: $x, hiding $exp at $1
test.y:51.41: possibly meant: $r, hiding $exp at $4
test.y:52.51-52: error: $l of 'exp' has no declared type
test.y:55.46-49: error: invalid reference: '$r12'
test.y:55.3-53: symbol not found in production: r12
test.y:55.40-43: error: invalid reference: '$r12'
test.y:55.3-47: symbol not found in production: r12
test.y:56.29-33: error: invalid reference: '$expo'
test.y:56.3-46: symbol not found in production: expo
]])
@@ -443,19 +443,14 @@ AT_SETUP([Stray symbols in brackets])
AT_DATA_GRAMMAR([test.y],
[[
%%
start: foo[ /* aaa */ *&-.+\000\001\002\377 ] 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'
[[test.y:11.13: error: invalid character in bracketed name: '%'
test.y:11.25-27: error: invalid characters in bracketed name: '*&-'
test.y:11.29-30: error: invalid characters in bracketed name: '+\0\001\002\377'
]])
AT_CLEANUP