X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/793a58bb66dbb11d5971b2cd3fe9d0827c6c84b6..fcbfa6b01c0222b01254730c66d539ed2c841a4e:/tests/calc.at?ds=sidebyside diff --git a/tests/calc.at b/tests/calc.at index 4399d257..7cf12d39 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -35,15 +35,10 @@ m4_define([_AT_DATA_CALC_Y], [m4_if([$1$2$3], $[1]$[2]$[3], [], [m4_fatal([$0: Invalid arguments: $@])])dnl -AT_DATA([calc.y], +AT_DATA_GRAMMAR([calc.y], [[/* Infix notation calculator--calc */ ]$4[ %{ -#include -/* We don't need perfect functions for these tests. */ -#undef malloc -#undef memcmp -#undef realloc #include #if STDC_HEADERS @@ -51,22 +46,21 @@ AT_DATA([calc.y], # include #endif #include -#include extern void perror (const char *s); /* Exercise pre-prologue dependency to %union. */ -typedef int value_t; +typedef int value; -value_t global_result = 0; -int global_count = 0; +static value global_result = 0; +static int global_count = 0; %} /* Exercise %union. */ %union { - value_t ival; + value ival; }; %{ @@ -100,9 +94,9 @@ static int power (int base, int exponent); /* yyerror receives the location if: - %location & %pure & %glr - %location & %pure & %yacc & %parse-param. */ -static void yyerror (const char *s - ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[ - ]AT_PARAM_IF([, value_t *result, int *count])[ +static void yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[ + ]AT_PARAM_IF([value *result, int *count, ])[ + const char *s ); static int yylex (LEX_FORMALS); static int yygetc (LEX_FORMALS); @@ -151,12 +145,13 @@ exp: ; %% /* The input. */ -FILE *yyin; +static FILE *yyin; static void -yyerror (const char *s - ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[ - ]AT_PARAM_IF([, value_t *result, int *count])[) +yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[ + ]AT_PARAM_IF([value *result, int *count, ])[ + const char *s + ) { ]AT_PARAM_IF([(void) result; (void) count; ])[ ]AT_YYERROR_SEES_LOC_IF([ @@ -293,9 +288,9 @@ power (int base, int exponent) int main (int argc, const char **argv) { - value_t result = 0; + value result = 0; int count = 0; - yyin = NULL; + int status; if (argc == 2) yyin = fopen (argv[1], "r"); @@ -311,11 +306,12 @@ main (int argc, const char **argv) #if YYDEBUG yydebug = 1; #endif - yyparse (]AT_PARAM_IF([&result, &count])[); - assert (global_result == result); - assert (global_count == count); - - return 0; + status = yyparse (]AT_PARAM_IF([&result, &count])[); + if (global_result != result) + abort (); + if (global_count != count) + abort (); + return status; } ]]) ])# _AT_DATA_CALC_Y @@ -353,10 +349,11 @@ m4_bmatch([$1], ]) -# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, [NUM-DEBUG-LINES], +# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT, +# [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. @@ -365,23 +362,23 @@ m4_bmatch([$1], # 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 # is the number of expected lines on stderr. m4_define([_AT_CHECK_CALC_ERROR], -[m4_bmatch([$2], [^/], - [AT_PARSER_CHECK([./calc $2], 0, [], [stderr])], +[m4_bmatch([$3], [^/], + [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])], [AT_DATA([[input]], -[[$2 +[[$3 ]]) -AT_PARSER_CHECK([./calc input], 0, [], [stderr])]) +AT_PARSER_CHECK([./calc input], $2, [], [stderr])]) m4_bmatch([$1], [%debug.*%glr\|%glr.*%debug], [], [%debug], - [AT_CHECK([wc -l at-expout +[[sed 's/syntax error, .*$/syntax error/' expout >at-expout mv at-expout expout]]) # 5. Check AT_CHECK([cat stderr], 0, [expout]) @@ -500,30 +497,30 @@ _AT_CHECK_CALC([$1], (2^2)^3 = 64], [486]) -# Some parse errors. -_AT_CHECK_CALC_ERROR([$1], [0 0], [11], - [1.3-1.4: parse error, unexpected "number"]) -_AT_CHECK_CALC_ERROR([$1], [1//2], [15], - [1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '(']) -_AT_CHECK_CALC_ERROR([$1], [error], [4], - [1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '(']) -_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22], - [1.7-1.8: parse error, unexpected '=']) -_AT_CHECK_CALC_ERROR([$1], +# Some syntax errors. +_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [11], + [1.3-1.4: syntax error, unexpected "number"]) +_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [15], + [1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '(']) +_AT_CHECK_CALC_ERROR([$1], [1], [error], [4], + [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: 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], [/dev/null], [4], - [1.1-1.2: parse error, unexpected "end of input", expecting "number" or '-' or '\n' or '(']) +_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4], + [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], [(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" +_AT_CHECK_CALC_ERROR([$1], [0], [(1 ++ 2) + (0 0) = 1], [82], +[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 @@ -565,7 +562,7 @@ AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param "value_t *result", "result" %parse-param "int *count", "count"]) +AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}]) # ----------------------- # @@ -600,4 +597,4 @@ AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) -AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param "value_t *result", "result" %parse-param "int *count", "count"]) +AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}])