X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/927f7817082cf856881979f6b80b8dddc96b7d44..fcbfa6b01c0222b01254730c66d539ed2c841a4e:/tests/cxx-type.at diff --git a/tests/cxx-type.at b/tests/cxx-type.at index d41c361d..41ff5604 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -18,13 +18,13 @@ AT_BANNER([[C++ Type Syntax (GLR).]]) -# _AT_TEST_GLR_CALC(DECL, RESOLVE1, RESOLVE2) -# ------------------------------------------- +# _AT_TEST_GLR_CXXTYPES(DECL, RESOLVE1, RESOLVE2) +# ----------------------------------------------- # Store into types.y the calc program, with DECL inserted as a declaration, # and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for # stmt. Then compile the result. -m4_define([_AT_TEST_GLR_CALC], -[AT_DATA([types.y], +m4_define([_AT_TEST_GLR_CXXTYPES], +[AT_DATA_GRAMMAR([types.y], [[/* Simplified C++ Type and Expression Grammar. */ $1 @@ -36,7 +36,12 @@ $1 ]m4_bmatch([$2], [stmtMerge], [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[ #define YYINITDEPTH 10 - int yyerror (const char *s); + int yyerror ( +#if YYPURE && YYLSP_NEEDED + YYLTYPE *yylocation, +#endif + const char *s + ); #if YYPURE ]m4_bmatch([$1], [location], @@ -86,14 +91,15 @@ declarator : ID { printf ("\"%s\" ", ]$[1); } %% -#include #include +#include #include int main (int argc, char** argv) { - assert (argc == 2); + if (argc != 2) + abort (); if (!freopen (argv[1], "r", stdin)) abort (); exit (yyparse ()); @@ -111,34 +117,57 @@ yylex () { char buffer[256]; int c; + unsigned int i; #if YYPURE # define yylval (*lvalp) ]m4_bmatch([$1], [location],[ (void) llocp;])[ #endif - while (1) { - c = getchar (); - switch (c) { - case EOF: - return 0; - case ' ': case '\t': case '\n': case '\f': - break; - default: - if (isalpha (c)) { - ungetc (c, stdin); - scanf ("%[A-Za-z0-9_]", buffer); - yylval = strdup (buffer); - return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; - } - return c; + while (1) + { + c = getchar (); + switch (c) + { + case EOF: + return 0; + case ' ': case '\t': case '\n': case '\f': + break; + default: + if (isalpha (c)) + { + i = 0; + + do + { + buffer[i++] = c; + if (i == sizeof buffer - 1) + abort (); + c = getchar (); + } + while (isalnum (c) || c == '_'); + + ungetc (c, stdin); + buffer[i++] = 0; + yylval = strcpy (malloc (i), buffer); + return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; + } + return c; + } } - } } int -yyerror (const char *s) +yyerror ( +#if YYPURE && YYLSP_NEEDED + YYLTYPE *yylocation, +#endif + const char *s + ) { +#if YYPURE && YYLSP_NEEDED + (void) *yylocation; +#endif fprintf (stderr, "%s\n", s); return 0; } @@ -183,7 +212,7 @@ z + q; This is total garbage, but it should be ignored. ]]) -AT_CHECK([bison types.y -o types.c], 0, [], ignore) +AT_CHECK([bison -o types.c types.y], 0, [], ignore) AT_COMPILE([types]) ]) @@ -212,11 +241,11 @@ z q + ]]) m4_define([_AT_GLR_STDERR], -[[parse error +[[syntax error ]]) m4_define([_AT_VERBOSE_GLR_STDERR], -[[parse error, unexpected ID, expecting '=' or '+' or ')' +[[syntax error, unexpected ID, expecting '=' or '+' or ')' ]]) ## ---------------------------------------------------- ## @@ -224,63 +253,62 @@ m4_define([_AT_VERBOSE_GLR_STDERR], ## ---------------------------------------------------- ## AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) -_AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +_AT_TEST_GLR_CXXTYPES([], + [%dprec 1], [%dprec 2]) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, impure, locations]) -_AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +_AT_TEST_GLR_CXXTYPES([%locations],[%dprec 1],[%dprec 2]) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, no locations]) -_AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +_AT_TEST_GLR_CXXTYPES([%pure-parser], + [%dprec 1], [%dprec 2]) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, locations]) -_AT_TEST_GLR_CALC([%pure-parser -%locations],[%dprec 1],[%dprec 2]) +_AT_TEST_GLR_CXXTYPES([%pure-parser %locations], + [%dprec 1], [%dprec 2]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) -_AT_TEST_GLR_CALC([],[%merge ],[%merge ]) +_AT_TEST_GLR_CXXTYPES([], + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, locations]) -_AT_TEST_GLR_CALC([%locations],[%merge ],[%merge ]) +_AT_TEST_GLR_CXXTYPES([%locations], + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) -_AT_TEST_GLR_CALC([%pure-parser],[%merge ],[%merge ]) +_AT_TEST_GLR_CXXTYPES([%pure-parser], + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, locations]) -_AT_TEST_GLR_CALC([%pure-parser -%locations],[%merge ],[%merge ]) +_AT_TEST_GLR_CXXTYPES([%pure-parser %locations], + [%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) -_AT_TEST_GLR_CALC([%error-verbose], -[%merge ],[%merge ]) +_AT_TEST_GLR_CXXTYPES([%error-verbose], + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_VERBOSE_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) AT_CLEANUP