X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/12bebc0445dd46e15376edced8596bae96be78b6..6d5aa694aacbae8e330a195327cf3763b01da202:/tests/cxx-type.at diff --git a/tests/cxx-type.at b/tests/cxx-type.at index c1555aef..9583b8fd 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -1,5 +1,5 @@ -# Checking the output filenames. -*- Autotest -*- -# Copyright 2000, 2001 Free Software Foundation, Inc. +# Checking GLR Parsing. -*- Autotest -*- +# Copyright (C) 2002, 2003 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 @@ -18,22 +18,39 @@ AT_BANNER([[C++ Type Syntax (GLR).]]) -# _AT_TEST_GLR_CALC(`$1',DECL, RESOLVE1, RESOLVE2) -# (first argument is a literal $1; it's a trick). +# _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], -[[/* Simplified C++ Type and Expression Grammar */ +m4_define([_AT_TEST_GLR_CXXTYPES], +[AT_DATA_GRAMMAR([types.y], +[[/* Simplified C++ Type and Expression Grammar. */ -$2 +$1 %{ #include #define YYSTYPE const char* - static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1); + #define YYLTYPE int +]m4_bmatch([$2], [stmtMerge], +[ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[ #define YYINITDEPTH 10 + int yyerror ( +#if YYPURE && YYLSP_NEEDED + YYLTYPE *yylocation, +#endif + const char *s + ); + + #if YYPURE +]m4_bmatch([$1], [location], +[ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);], +[ int yylex (YYSTYPE *lvalp);])[ + #else + int yylex (void); + #endif + %} %token TYPENAME ID @@ -45,85 +62,129 @@ $2 %% -prog : +prog : | prog stmt { printf ("\n"); } ; -stmt : expr ';' $3 - | decl $4 +stmt : expr ';' $2 + | decl $3 | error ';' | '@' { YYACCEPT; } ; -expr : ID { printf ("%s ", $$); } - | TYPENAME '(' expr ')' - { printf ("%s ", $1); } +expr : ID { printf ("%s ", ]$[1); } + | TYPENAME '(' expr ')' + { printf ("%s ", ]$[1); } | expr '+' expr { printf ("+ "); } | expr '=' expr { printf ("= "); } ; -decl : TYPENAME declarator ';' - { printf ("%s ", $1); } +decl : TYPENAME declarator ';' + { printf ("%s ", ]$[1); } | TYPENAME declarator '=' expr ';' - { printf ("%s ", $1); } + { printf ("%s ", ]$[1); } ; -declarator : ID { printf ("\"%s\" ", $1); } +declarator : ID { printf ("\"%s\" ", ]$[1); } | '(' declarator ')' ; %% #include -#include +#include +#include -main (int argc, char** argv) +int +main (int argc, char** argv) { - freopen (argv[1], "r", stdin); + if (argc != 2) + abort (); + if (!freopen (argv[1], "r", stdin)) + abort (); exit (yyparse ()); } #if YYPURE -int yylex (YYSTYPE *lvalp) -#define yylval (*lvalp) +int +]m4_bmatch([$1], [location], +[yylex (YYSTYPE *lvalp, YYLTYPE *llocp)], +[yylex (YYSTYPE *lvalp)])[ #else -int yylex () +int +yylex () #endif { char buffer[256]; int c; - 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 (buffer[0]) ? TYPENAME : ID; - } - return 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)) + { + 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; } -static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1) +]] +m4_bmatch([$2], [stmtMerge], +[[static YYSTYPE +stmtMerge (YYSTYPE x0, YYSTYPE x1) { + /* Use the arguments. */ + (void) x0; + (void) x1; printf (" "); return ""; } ]]) +) AT_DATA([test-input], [[ @@ -151,8 +212,8 @@ z + q; This is total garbage, but it should be ignored. ]]) -AT_CHECK([bison types.y], 0, [], ignore) -AT_CHECK([gcc -o types types.tab.c], 0, [], ignore) +AT_CHECK([bison -o types.c types.y], 0, [], ignore) +AT_COMPILE([types]) ]) m4_define([_AT_RESOLVED_GLR_OUTPUT], @@ -168,23 +229,23 @@ z q + ]]) m4_define([_AT_AMBIG_GLR_OUTPUT], -[[z q + -"x" T -"x" y T -x y = -x T y + -"x" T x T -"y" z q + T y T z q + = +[[z q + +"x" T +"x" y T +x y = +x T y + +"x" T x T +"y" z q + T y T z q + = y z q + ]]) -m4_define([_AT_GLR_STDERR], -[[parse error +m4_define([_AT_GLR_STDERR], +[[syntax error ]]) -m4_define([_AT_VERBOSE_GLR_STDERR], -[[parse error, unexpected ID, expecting '=' or '+' or ')' +m4_define([_AT_VERBOSE_GLR_STDERR], +[[syntax error, unexpected ID, expecting '=' or '+' or ')' ]]) ## ---------------------------------------------------- ## @@ -192,57 +253,62 @@ m4_define([_AT_VERBOSE_GLR_STDERR], ## ---------------------------------------------------- ## AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) -_AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2]) -AT_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([$1],[%locations],[%dprec 1],[%dprec 2]) -AT_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([$1],[%pure-parser],[%dprec 1],[%dprec 2]) -AT_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([$1],[%pure-parser -%locations],[%dprec 1],[%dprec 2]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +_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_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) -_AT_TEST_GLR_CALC([$1],[],[%merge ],[%merge ]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) +_AT_TEST_GLR_CXXTYPES([], + [%merge ], [%merge ]) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, locations]) -_AT_TEST_GLR_CALC([$1],[%locations],[%merge ],[%merge ]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) +_AT_TEST_GLR_CXXTYPES([%locations], + [%merge ], [%merge ]) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) -_AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge ],[%merge ]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) +_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_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, locations]) -_AT_TEST_GLR_CALC([$1],[%pure-parser -%locations],[%merge ],[%merge ]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) +_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_CLEANUP AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) -_AT_TEST_GLR_CALC([$1],[%error-verbose], -[%merge ],[%merge ]) -AT_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) +_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_CLEANUP