X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8ea6525e3a092b76256fbed7d6edbb0a1861aee1..df1ca1b0de2d99879f7b41e64d8bf285f163b1aa:/tests/conflicts.at diff --git a/tests/conflicts.at b/tests/conflicts.at index 37c54050..92e4ae87 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -1,6 +1,6 @@ # Exercising Bison on conflicts. -*- Autotest -*- -# Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc. +# Copyright (C) 2002-2005, 2007-2013 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,6 +17,180 @@ AT_BANNER([[Conflicts.]]) +## ------------------------------ ## +## Useless associativity warning. ## +## ------------------------------ ## + +AT_SETUP([Useless associativity warning]) + +AT_DATA([[input.y]], +[[%token T +%left A B +%right C +%nonassoc D +%precedence E + +%% +e: T A T + | T B T + | T C T + | T D T + | T E T +; +]]) + +AT_BISON_CHECK([input.y], 0, [], +[[input.y:5.13: warning: useless precedence for E [-Wother] +input.y:2.7: warning: useless associativity for A [-Wother] +input.y:2.9: warning: useless associativity for B [-Wother] +input.y:3.8: warning: useless associativity for C [-Wother] +input.y:4.11: warning: useless associativity for D [-Wother] +]]) + +AT_CLEANUP + + +## ------------------------ ## +## Token declaration order. ## +## ------------------------ ## + +# This test checks that token are declared left to right when in a precedence +# statement. + +AT_SETUP([Token declaration order]) + +AT_BISON_OPTION_PUSHDEFS + +AT_DATA_GRAMMAR([[input.y]], +[[%code { + #include + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ +} +%token A B C +%token D +%right E F G +%right H I +%right J +%left K +%left L M N +%nonassoc O P Q +%precedence R S T U +%precedence V W +%% +exp: A +%% +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE[ +int main (void) +{ + assert (A < B); + assert (B < C); + assert (C < D); + assert (D < E); + assert (E < F); + assert (F < G); + assert (G < H); + assert (H < I); + assert (I < J); + assert (J < K); + assert (K < L); + assert (L < M); + assert (M < N); + assert (N < O); + assert (O < P); + assert (P < Q); + assert (Q < R); + assert (R < S); + assert (S < T); + assert (T < U); + assert (U < V); + assert (V < W); + return 0; +} +]]) + +AT_BISON_CHECK([-o input.c input.y], [], [], +[[input.y:24.13: warning: useless precedence for R [-Wother] +input.y:24.15: warning: useless precedence for S [-Wother] +input.y:24.17: warning: useless precedence for T [-Wother] +input.y:24.19: warning: useless precedence for U [-Wother] +input.y:25.13: warning: useless precedence for V [-Wother] +input.y:25.15: warning: useless precedence for W [-Wother] +input.y:18.8: warning: useless associativity for E [-Wother] +input.y:18.10: warning: useless associativity for F [-Wother] +input.y:18.12: warning: useless associativity for G [-Wother] +input.y:19.8: warning: useless associativity for H [-Wother] +input.y:19.10: warning: useless associativity for I [-Wother] +input.y:20.8: warning: useless associativity for J [-Wother] +input.y:21.8: warning: useless associativity for K [-Wother] +input.y:22.8: warning: useless associativity for L [-Wother] +input.y:22.10: warning: useless associativity for M [-Wother] +input.y:22.12: warning: useless associativity for N [-Wother] +input.y:23.11: warning: useless associativity for O [-Wother] +input.y:23.13: warning: useless associativity for P [-Wother] +input.y:23.15: warning: useless associativity for Q [-Wother] +]]) +AT_COMPILE([input]) + +AT_PARSER_CHECK([./input]) + +AT_BISON_OPTION_POPDEFS + +AT_CLEANUP + + +## ---------------------------- ## +## Useless precedence warning. ## +## ---------------------------- ## + +AT_SETUP([Useless precedence warning]) + +AT_DATA([[input.y]], +[[%token A B +%precedence Z +%left X +%precedence Y +%left W +%right V +%nonassoc U +%% +a: b + | a U b + | f +; +b: c + | b V c +; +c: d + | c W d +; +d: A + | d X d + | d Y A +; +f: B + | f Z B +; +]]) + +AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [], +[[input.y:2.13: warning: useless precedence for Z [-Wother] + %precedence Z + ^ +input.y:5.7: warning: useless associativity for W [-Wother] + %left W + ^ +input.y:6.8: warning: useless associativity for V [-Wother] + %right V + ^ +input.y:7.11: warning: useless associativity for U [-Wother] + %nonassoc U + ^ +]]) + +AT_CLEANUP + ## ---------------- ## ## S/R in initial. ## @@ -40,6 +214,12 @@ AT_BISON_CHECK([-o input.c input.y], 0, [], [[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */ [-Wother] ]]) +AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [], +[[input.y:4.9: warning: rule useless in parser due to conflicts [-Wother] + e: 'e' | /* Nothing. */; + ^ +]]) + AT_CLEANUP @@ -215,30 +395,9 @@ public Object getLVal () /*-------. | main. | -`-------*/]AT_SKEL_JAVA_IF([[ - -class input -{ - public static void main (String args[]) throws IOException - { - YYParser p = new YYParser (); - p.parse (); - } -}]], [AT_SKEL_CC_IF([[ - -int -main (void) -{ - yy::parser parser; - return parser.parse (); -}]], [[ - -int -main (void) -{ - return yyparse (); -}]])])[ -]]) +`-------*/ +]AT_MAIN_DEFINE +]) AT_FULL_COMPILE([[input]]) @@ -486,13 +645,8 @@ reduce-nonassoc: %prec 'a'; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["aaa"])[ - -int -main (void) -{ - return yyparse (); -} -]]) +]AT_MAIN_DEFINE +]) AT_BISON_OPTION_POPDEFS # Show canonical LR's failure. @@ -574,7 +728,7 @@ exp (6) on left: 1 2, on right: 0 1 -state 0 +State 0 0 $accept: . exp $end 1 exp: . exp OP exp @@ -585,14 +739,14 @@ state 0 exp go to state 2 -state 1 +State 1 2 exp: NUM . $default reduce using rule 2 (exp) -state 2 +State 2 0 $accept: exp . $end 1 exp: exp . OP exp @@ -601,14 +755,14 @@ state 2 OP shift, and go to state 4 -state 3 +State 3 0 $accept: exp $end . $default accept -state 4 +State 4 1 exp: . exp OP exp 1 | exp OP . exp @@ -619,7 +773,7 @@ state 4 exp go to state 5 -state 5 +State 5 1 exp: exp . OP exp 1 | exp OP exp . [$end, OP] @@ -677,7 +831,7 @@ exp (6) on left: 1 2, on right: 0 1 -state 0 +State 0 0 $accept: . exp $end 1 exp: . exp OP exp @@ -688,14 +842,14 @@ state 0 exp go to state 2 -state 1 +State 1 2 exp: NUM . $default reduce using rule 2 (exp) -state 2 +State 2 0 $accept: exp . $end 1 exp: exp . OP exp @@ -704,14 +858,14 @@ state 2 OP shift, and go to state 4 -state 3 +State 3 0 $accept: exp $end . $default accept -state 4 +State 4 1 exp: . exp OP exp 1 | exp OP . exp @@ -722,7 +876,7 @@ state 4 exp go to state 5 -state 5 +State 5 1 exp: exp . OP exp 1 | exp OP exp . [$end, OP] @@ -873,7 +1027,7 @@ id (7) on left: 4, on right: 2 -state 0 +State 0 0 $accept: . exp $end 1 exp: . num @@ -888,7 +1042,7 @@ state 0 id go to state 4 -state 1 +State 1 3 num: '0' . [$end] 4 id: '0' . [$end] @@ -898,28 +1052,28 @@ state 1 $default reduce using rule 3 (num) -state 2 +State 2 0 $accept: exp . $end $end shift, and go to state 5 -state 3 +State 3 1 exp: num . $default reduce using rule 1 (exp) -state 4 +State 4 2 exp: id . $default reduce using rule 2 (exp) -state 5 +State 5 0 $accept: exp $end . @@ -1044,6 +1198,8 @@ e: e '+' e AT_BISON_CHECK([-o input.c input.y], 0, [], [[input.y: warning: 4 shift/reduce conflicts [-Wconflicts-sr] +input.y:1.7-9: warning: useless associativity for '+' [-Wother] +input.y:2.7-9: warning: useless associativity for '*' [-Wother] ]]) AT_CLEANUP @@ -1218,7 +1374,7 @@ reported_conflicts (9) on left: 8 9 10, on right: 1 -state 0 +State 0 0 $accept: . start $end 1 start: . resolved_conflict 'a' reported_conflicts 'a' @@ -1233,28 +1389,28 @@ state 0 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a'). -state 1 +State 1 0 $accept: start . $end $end shift, and go to state 3 -state 2 +State 2 1 start: resolved_conflict . 'a' reported_conflicts 'a' 'a' shift, and go to state 4 -state 3 +State 3 0 $accept: start $end . $default accept -state 4 +State 4 1 start: resolved_conflict 'a' . reported_conflicts 'a' 8 reported_conflicts: . 'a' @@ -1268,7 +1424,7 @@ state 4 reported_conflicts go to state 6 -state 5 +State 5 8 reported_conflicts: 'a' . ['a'] 9 | 'a' . ['a'] @@ -1278,14 +1434,14 @@ state 5 $default reduce using rule 8 (reported_conflicts) -state 6 +State 6 1 start: resolved_conflict 'a' reported_conflicts . 'a' 'a' shift, and go to state 7 -state 7 +State 7 1 start: resolved_conflict 'a' reported_conflicts 'a' . @@ -1340,8 +1496,8 @@ empty_c2: %prec 'c' ; empty_c3: %prec 'd' ; ]]) AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore]) -AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0, -[[state 0 +AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0, +[[State 0 0 $accept: . start $end 1 start: . 'a' @@ -1377,7 +1533,7 @@ AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0, Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd'). -state 1 +State 1 ]]) AT_CLEANUP @@ -1416,8 +1572,8 @@ empty_c3: %prec 'c' ; ]]) AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore]) -AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0, -[[state 0 +AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0, +[[State 0 0 $accept: . start $end 1 start: . 'a' @@ -1453,7 +1609,7 @@ AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0, Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c'). -state 1 +State 1 ]]) AT_CLEANUP