/[bison]/bison/tests/cxx-type.at
ViewVC logotype

Diff of /bison/tests/cxx-type.at

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by hilfinger, Wed Jun 26 22:52:27 2002 UTC revision 1.2 by akim, Sun Jun 30 17:35:06 2002 UTC
# Line 1  Line 1 
1  # Checking the output filenames.                         -*- Autotest -*-  # Checking GLR Parsing.                         -*- Autotest -*-
2  # Copyright 2000, 2001 Free Software Foundation, Inc.  # Copyright 2002 Free Software Foundation, Inc.
3    
4  # This program is free software; you can redistribute it and/or modify  # This program is free software; you can redistribute it and/or modify
5  # it under the terms of the GNU General Public License as published by  # it under the terms of the GNU General Public License as published by
# Line 18  Line 18 
18    
19  AT_BANNER([[C++ Type Syntax (GLR).]])  AT_BANNER([[C++ Type Syntax (GLR).]])
20    
21  # _AT_TEST_GLR_CALC(`$1',DECL, RESOLVE1, RESOLVE2)  # _AT_TEST_GLR_CALC(DECL, RESOLVE1, RESOLVE2)
22  # (first argument is a literal $1; it's a trick).    # -------------------------------------------
23  # Store into types.y the calc program, with DECL inserted as a declaration,  # Store into types.y the calc program, with DECL inserted as a declaration,
24  # and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for  # and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for
25  # stmt.  Then compile the result.  # stmt.  Then compile the result.
26  m4_define([_AT_TEST_GLR_CALC],  m4_define([_AT_TEST_GLR_CALC],
27  [AT_DATA([types.y],  [AT_DATA([types.y],
28  [[/* Simplified C++ Type and Expression Grammar */  [[/* Simplified C++ Type and Expression Grammar.  */
29    
30  $2  $1
31    
32  %{  %{
33    #include <stdio.h>    #include <stdio.h>
34    #define YYSTYPE const char*    #define YYSTYPE const char*
35    static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);    #define YYLTYPE int
36    ]m4_bmatch([$2], [stmtMerge],
37    [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
38    #define YYINITDEPTH 10    #define YYINITDEPTH 10
39      int yyerror (const char *s);
40    
41      #if YYPURE
42    ]m4_bmatch([$1], [location],
43    [  int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);],
44    [  int yylex (YYSTYPE *lvalp);])[
45      #else
46      int yylex (void);
47      #endif
48    
49  %}  %}
50    
51  %token TYPENAME ID  %token TYPENAME ID
# Line 45  $2 Line 57  $2
57    
58  %%  %%
59    
60  prog :  prog :
61       | prog stmt   { printf ("\n"); }       | prog stmt   { printf ("\n"); }
62       ;       ;
63    
64  stmt : expr ';'  $3  stmt : expr ';'  $2
65       | decl      $4       | decl      $3
66       | error ';'       | error ';'
67       | '@'  { YYACCEPT; }       | '@'  { YYACCEPT; }
68       ;       ;
69    
70  expr : ID               { printf ("%s ", $$); }  expr : ID               { printf ("%s ", $$); }
71       | TYPENAME '(' expr ')'         | TYPENAME '(' expr ')'
72                          { printf ("%s <cast> ", $1); }                          { printf ("%s <cast> ", ]$[1); }
73       | expr '+' expr    { printf ("+ "); }       | expr '+' expr    { printf ("+ "); }
74       | expr '=' expr    { printf ("= "); }       | expr '=' expr    { printf ("= "); }
75       ;       ;
76    
77  decl : TYPENAME declarator ';'  decl : TYPENAME declarator ';'
78                          { printf ("%s <declare> ", $1); }                          { printf ("%s <declare> ", ]$[1); }
79       | TYPENAME declarator '=' expr ';'       | TYPENAME declarator '=' expr ';'
80                          { printf ("%s <init-declare> ", $1); }                          { printf ("%s <init-declare> ", ]$[1); }
81       ;       ;
82    
83  declarator : ID         { printf ("\"%s\" ", $1); }  declarator : ID         { printf ("\"%s\" ", ]$[1); }
84       | '(' declarator ')'       | '(' declarator ')'
85       ;       ;
86    
87  %%  %%
88    
89    #include <assert.h>
90  #include <ctype.h>  #include <ctype.h>
91  #include <strings.h>  #include <string.h>
92    
93  main (int argc, char** argv)  int
94    main (int argc, char** argv)
95  {  {
96    freopen (argv[1], "r", stdin);    assert (argc = 2);
97      assert (freopen (argv[1], "r", stdin));
98    exit (yyparse ());    exit (yyparse ());
99  }  }
100    
101  #if YYPURE  #if YYPURE
102  int yylex (YYSTYPE *lvalp)  int
103  #define yylval (*lvalp)  ]m4_bmatch([$1], [location],
104    [yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
105    [yylex (YYSTYPE *lvalp)])[
106  #else  #else
107  int yylex ()  int
108    yylex ()
109  #endif  #endif
110  {  {
111    char buffer[256];    char buffer[256];
112    int c;    int c;
113    
114    #if YYPURE
115    # define yylval (*lvalp)
116    ]m4_bmatch([$1], [location],[  (void) llocp;])[
117    #endif
118    
119    while (1) {    while (1) {
120      c = getchar ();      c = getchar ();
121      switch (c) {      switch (c) {
# Line 118  yyerror (const char *s) Line 142  yyerror (const char *s)
142    return 0;    return 0;
143  }  }
144    
145  static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1)  ]]
146    m4_bmatch([$2], [stmtMerge],
147    [[static YYSTYPE
148    stmtMerge (YYSTYPE x0, YYSTYPE x1)
149  {  {
150      /* Use the arguments. */
151      (void) x0;
152      (void) x1;
153    printf ("<OR> ");    printf ("<OR> ");
154    return "";    return "";
155  }  }
156  ]])  ]])
157    )
158    
159  AT_DATA([test-input],  AT_DATA([test-input],
160  [[  [[
# Line 151  z + q; Line 182  z + q;
182  This is total garbage, but it should be ignored.  This is total garbage, but it should be ignored.
183  ]])  ]])
184    
185  AT_CHECK([bison types.y], 0, [], ignore)  AT_CHECK([bison types.y -o types.c], 0, [], ignore)
186  AT_CHECK([gcc -o types types.tab.c], 0, [], ignore)  AT_COMPILE([types])
187  ])  ])
188    
189  m4_define([_AT_RESOLVED_GLR_OUTPUT],  m4_define([_AT_RESOLVED_GLR_OUTPUT],
# Line 168  z q + Line 199  z q +
199  ]])  ]])
200    
201  m4_define([_AT_AMBIG_GLR_OUTPUT],  m4_define([_AT_AMBIG_GLR_OUTPUT],
202  [[z q +  [[z q +
203  "x" T <declare>  "x" T <declare>
204  "x" y T <init-declare>  "x" y T <init-declare>
205  x y =  x y =
206  x T <cast> y +  x T <cast> y +
207  "x" T <declare> x T <cast> <OR>  "x" T <declare> x T <cast> <OR>
208  "y" z q + T <init-declare> y T <cast> z q + = <OR>  "y" z q + T <init-declare> y T <cast> z q + = <OR>
209  y  y
210  z q +  z q +
211  ]])  ]])
212    
213  m4_define([_AT_GLR_STDERR],  m4_define([_AT_GLR_STDERR],
214  [[parse error  [[parse error
215  ]])  ]])
216    
217  m4_define([_AT_VERBOSE_GLR_STDERR],  m4_define([_AT_VERBOSE_GLR_STDERR],
218  [[parse error, unexpected ID, expecting '=' or '+' or ')'  [[parse error, unexpected ID, expecting '=' or '+' or ')'
219  ]])  ]])
220    
# Line 192  m4_define([_AT_VERBOSE_GLR_STDERR], Line 223  m4_define([_AT_VERBOSE_GLR_STDERR],
223  ## ---------------------------------------------------- ##  ## ---------------------------------------------------- ##
224    
225  AT_SETUP([GLR: Resolve ambiguity, impure, no locations])  AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
226  _AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2])  _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
227  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
228           _AT_GLR_STDERR)           _AT_GLR_STDERR)
229  AT_CLEANUP  AT_CLEANUP
230    
231  AT_SETUP([GLR: Resolve ambiguity, impure, locations])  AT_SETUP([GLR: Resolve ambiguity, impure, locations])
232  _AT_TEST_GLR_CALC([$1],[%locations],[%dprec 1],[%dprec 2])  _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
233  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
234          _AT_GLR_STDERR)          _AT_GLR_STDERR)
235  AT_CLEANUP  AT_CLEANUP
236    
237  AT_SETUP([GLR: Resolve ambiguity, pure, no locations])  AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
238  _AT_TEST_GLR_CALC([$1],[%pure-parser],[%dprec 1],[%dprec 2])  _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
239  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
240           _AT_GLR_STDERR)           _AT_GLR_STDERR)
241  AT_CLEANUP  AT_CLEANUP
242    
243  AT_SETUP([GLR: Resolve ambiguity, pure, locations])  AT_SETUP([GLR: Resolve ambiguity, pure, locations])
244  _AT_TEST_GLR_CALC([$1],[%pure-parser  _AT_TEST_GLR_CALC([%pure-parser
245  %locations],[%dprec 1],[%dprec 2])  %locations],[%dprec 1],[%dprec 2])
246  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
247           _AT_GLR_STDERR)                  _AT_RESOLVED_GLR_OUTPUT,
248                    _AT_GLR_STDERR)
249  AT_CLEANUP  AT_CLEANUP
250    
251  AT_SETUP([GLR: Merge conflicting parses, impure, no locations])  AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
252  _AT_TEST_GLR_CALC([$1],[],[%merge <stmtMerge>],[%merge <stmtMerge>])  _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
253  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_AMBIG_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
254           _AT_GLR_STDERR)                  _AT_AMBIG_GLR_OUTPUT,
255                    _AT_GLR_STDERR)
256  AT_CLEANUP  AT_CLEANUP
257    
258  AT_SETUP([GLR: Merge conflicting parses, impure, locations])  AT_SETUP([GLR: Merge conflicting parses, impure, locations])
259  _AT_TEST_GLR_CALC([$1],[%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])  _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
260  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_AMBIG_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
261           _AT_GLR_STDERR)                  _AT_AMBIG_GLR_OUTPUT,
262                    _AT_GLR_STDERR)
263  AT_CLEANUP  AT_CLEANUP
264    
265  AT_SETUP([GLR: Merge conflicting parses, pure, no locations])  AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
266  _AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])  _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
267  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_AMBIG_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
268           _AT_GLR_STDERR)                  _AT_AMBIG_GLR_OUTPUT,
269                    _AT_GLR_STDERR)
270  AT_CLEANUP  AT_CLEANUP
271  AT_SETUP([GLR: Merge conflicting parses, pure, locations])  AT_SETUP([GLR: Merge conflicting parses, pure, locations])
272  _AT_TEST_GLR_CALC([$1],[%pure-parser  _AT_TEST_GLR_CALC([%pure-parser
273  %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])  %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
274  AT_CHECK([[./types test-input | sed 's/  *$//']], 0, _AT_AMBIG_GLR_OUTPUT,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
275           _AT_GLR_STDERR)                  _AT_AMBIG_GLR_OUTPUT,
276                    _AT_GLR_STDERR)
277  AT_CLEANUP  AT_CLEANUP
278    
279  AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])  AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
280  _AT_TEST_GLR_CALC([$1],[%error-verbose],  _AT_TEST_GLR_CALC([%error-verbose],
281  [%merge <stmtMerge>],[%merge <stmtMerge>])  [%merge <stmtMerge>],[%merge <stmtMerge>])
282  AT_CHECK([[./types test-input | sed 's/  *$//']], 0,  AT_PARSER_CHECK([[./types test-input | sed 's/  *$//']], 0,
283           _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)                  _AT_AMBIG_GLR_OUTPUT,
284                    _AT_VERBOSE_GLR_STDERR)
285  AT_CLEANUP  AT_CLEANUP

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26