diff --git a/tests/actions.at b/tests/actions.at index bfb0e43c..94cf6f74 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -64,6 +64,55 @@ AT_PARSER_CHECK([./input], 0, AT_CLEANUP +## ------------------------ ## +## Typed mid-rule actions. ## +## ------------------------ ## + +AT_SETUP([Typed mid-rule actions]) + +AT_BISON_OPTION_PUSHDEFS +AT_DATA_GRAMMAR([[input.y]], +[[%define parse.error verbose +%debug +%code { +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ +} +%union { + int ival; +} +%type exp +%% +exp: { $$ = 0; } + '1' { $$ = 1; } + '2' { $$ = 2; } + '3' { $$ = 3; } + '4' { $$ = 4; } + '5' { $$ = 5; } + '6' { $$ = 6; } + '7' { $$ = 7; } + '8' { $$ = 8; } + '9' { $$ = 9; } { $$ = 10; } { $$ = 11; } + { + $$ = $1 + $3 + $5 + $7 + $9 + $11 + $13 + $15 + $17 + $19 + $20 + $21; + printf ("%d\n", $$); + } +; +%% +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE(["123456789"])[ +]AT_MAIN_DEFINE[ +]]) +AT_BISON_OPTION_POPDEFS + +AT_BISON_CHECK([-d -v -o input.c input.y]) +AT_COMPILE([input]) +AT_PARSER_CHECK([./input], 0, +[[66 +]]) + +AT_CLEANUP + ## ----------------------- ## ## Implicitly empty rule. ## ## ----------------------- ## diff --git a/tests/input.at b/tests/input.at index 41e84dfd..037a9afe 100644 --- a/tests/input.at +++ b/tests/input.at @@ -168,7 +168,7 @@ AT_CLEANUP # declarations for the unused values tests. m4_define([_AT_UNUSED_VALUES_DECLARATIONS], [[[%token INT; -%type a b c d e f g h i j k l; +%type a b c d e f g h i j k l m n o; %destructor { destroy ($$); } ;]]]) @@ -189,7 +189,7 @@ start: 'a' a { $][2; } | 'b' b { $][2; } | 'c' c { $][2; } | 'd' d { $][2; } | 'e' e { $][2; } | 'f' f { $][2; } | 'g' g { $][2; } | 'h' h { $][2; } | 'i' i { $][2; } | 'j' j { $][2; } | 'k' k { $][2; } | 'l' l { $][2; } - +| 'm' m { $][2; } | 'n' n { $][2; } | 'o' o { $][2; } ; a: INT | INT { } INT { } INT { }; @@ -204,6 +204,9 @@ i: INT | INT INT { } { $][$ = $][1 + $][2; }; j: INT | INT INT { $$ = 1; } { $][$ = $][1 + $][2; }; k: INT | INT INT { $$; } { $$ = $3; } { }; l: INT | INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; }; +m: INT | INT { $][$ = $][1; } INT { $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; }; +n: INT | INT { } INT { } INT { }; +o: INT | INT { } INT { } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; }; ]]m4_ifval($1, [ _AT_UNUSED_VALUES_DECLARATIONS]) ) @@ -309,7 +312,37 @@ input.y:22.14-16: warning: unused value: $][2 [-Wother] ]]m4_ifval($2, [[[input.y:22.35-64: warning: unused value: $][4 [-Wmidrule-values] k: INT | INT INT { $$; } { $$ = $3; } { }; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -]]])) +]]])[[input.y:25.23-25: warning: unset value: $][$ [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.40-42: warning: unset value: $][$ [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.10-50: warning: unset value: $][$ [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +input.y:25.10-12: warning: unused value: $][1 [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.23-25: warning: unused value: $][2 [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.27-29: warning: unused value: $][3 [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.40-42: warning: unused value: $][4 [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:25.44-46: warning: unused value: $][5 [-Wother] + n: INT | INT { } INT { } INT { }; + ^^^ +input.y:26.23-25: warning: unset value: $][$ [-Wother] + o: INT | INT { } INT { } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; }; + ^^^ +input.y:26.40-42: warning: unset value: $][$ [-Wother] + o: INT | INT { } INT { } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; }; + ^^^ +]]) ]) ## --------------- ## diff --git a/tests/report.at b/tests/report.at index fc6629a9..c84fe024 100644 --- a/tests/report.at +++ b/tests/report.at @@ -53,7 +53,7 @@ id: "identifier"; exp: - "incr" exp { $$ = 1; } { $$ = 10; } exp { $$ = $2 + $3 + $4 + $5; } + "incr" exp { $$ = 1; } { $$ = 10; } exp { $$ = $2 + $3 + $4 + $5; } | "(" exp ")" { std::swap ($$, $2); } | "identifier" { $$ = driver.variables[$1]; } | "number" { std::swap ($$, $1); }; @@ -113,9 +113,9 @@ id (13) on left: 5, on right: 4 exp (14) on left: 8 9 10 11, on right: 1 4 8 9 -@1 (15) +@1 (15) on left: 6, on right: 8 -@2 (16) +@2 (16) on left: 7, on right: 8