]> git.saurik.com Git - bison.git/blame - tests/cxx-type.at
* src/vcg.c (quote): Use slot 2, since we often pass symbol tag
[bison.git] / tests / cxx-type.at
CommitLineData
12bebc04
PH
1# Checking the output filenames. -*- Autotest -*-
2# Copyright 2000, 2001 Free Software Foundation, Inc.
3
4# 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
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
18
19AT_BANNER([[C++ Type Syntax (GLR).]])
20
21# _AT_TEST_GLR_CALC(`$1',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,
24# and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for
25# stmt. Then compile the result.
26m4_define([_AT_TEST_GLR_CALC],
27[AT_DATA([types.y],
28[[/* Simplified C++ Type and Expression Grammar */
29
30$2
31
32%{
33 #include <stdio.h>
34 #define YYSTYPE const char*
35 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
36 #define YYINITDEPTH 10
37%}
38
39%token TYPENAME ID
40
41%right '='
42%left '+'
43
44%glr-parser
45
46%%
47
48prog :
49 | prog stmt { printf ("\n"); }
50 ;
51
52stmt : expr ';' $3
53 | decl $4
54 | error ';'
55 | '@' { YYACCEPT; }
56 ;
57
58expr : ID { printf ("%s ", $$); }
59 | TYPENAME '(' expr ')'
60 { printf ("%s <cast> ", $1); }
61 | expr '+' expr { printf ("+ "); }
62 | expr '=' expr { printf ("= "); }
63 ;
64
65decl : TYPENAME declarator ';'
66 { printf ("%s <declare> ", $1); }
67 | TYPENAME declarator '=' expr ';'
68 { printf ("%s <init-declare> ", $1); }
69 ;
70
71declarator : ID { printf ("\"%s\" ", $1); }
72 | '(' declarator ')'
73 ;
74
75%%
76
77#include <ctype.h>
78#include <strings.h>
79
80main (int argc, char** argv)
81{
82 freopen (argv[1], "r", stdin);
83 exit (yyparse ());
84}
85
86#if YYPURE
87int yylex (YYSTYPE *lvalp)
88#define yylval (*lvalp)
89#else
90int yylex ()
91#endif
92{
93 char buffer[256];
94 int c;
95 while (1) {
96 c = getchar ();
97 switch (c) {
98 case EOF:
99 return 0;
100 case ' ': case '\t': case '\n': case '\f':
101 break;
102 default:
103 if (isalpha (c)) {
104 ungetc (c, stdin);
105 scanf ("%[A-Za-z0-9_]", buffer);
106 yylval = strdup (buffer);
107 return isupper (buffer[0]) ? TYPENAME : ID;
108 }
109 return c;
110 }
111 }
112}
113
114int
115yyerror (const char *s)
116{
117 fprintf (stderr, "%s\n", s);
118 return 0;
119}
120
121static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1)
122{
123 printf ("<OR> ");
124 return "";
125}
126]])
127
128AT_DATA([test-input],
129[[
130
131z + q;
132
133T x;
134
135T x = y;
136
137x = y;
138
139T (x) + y;
140
141T (x);
142
143T (y) = z + q;
144
145T (y y) = z + q;
146
147z + q;
148
149@
150
151This is total garbage, but it should be ignored.
152]])
153
154AT_CHECK([bison types.y], 0, [], ignore)
155AT_CHECK([gcc -o types types.tab.c], 0, [], ignore)
156])
157
158m4_define([_AT_RESOLVED_GLR_OUTPUT],
159[[z q +
160"x" T <declare>
161"x" y T <init-declare>
162x y =
163x T <cast> y +
164"x" T <declare>
165"y" z q + T <init-declare>
166y
167z q +
168]])
169
170m4_define([_AT_AMBIG_GLR_OUTPUT],
171[[z q +
172"x" T <declare>
173"x" y T <init-declare>
174x y =
175x T <cast> y +
176"x" T <declare> x T <cast> <OR>
177"y" z q + T <init-declare> y T <cast> z q + = <OR>
178y
179z q +
180]])
181
182m4_define([_AT_GLR_STDERR],
183[[parse error
184]])
185
186m4_define([_AT_VERBOSE_GLR_STDERR],
187[[parse error, unexpected ID, expecting '=' or '+' or ')'
188]])
189
190## ---------------------------------------------------- ##
191## Compile the grammar described in the documentation. ##
192## ---------------------------------------------------- ##
193
194AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
195_AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2])
196AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
197 _AT_GLR_STDERR)
198AT_CLEANUP
199
200AT_SETUP([GLR: Resolve ambiguity, impure, locations])
201_AT_TEST_GLR_CALC([$1],[%locations],[%dprec 1],[%dprec 2])
202AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
203 _AT_GLR_STDERR)
204AT_CLEANUP
205
206AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
207_AT_TEST_GLR_CALC([$1],[%pure-parser],[%dprec 1],[%dprec 2])
208AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
209 _AT_GLR_STDERR)
210AT_CLEANUP
211
212AT_SETUP([GLR: Resolve ambiguity, pure, locations])
213_AT_TEST_GLR_CALC([$1],[%pure-parser
214%locations],[%dprec 1],[%dprec 2])
215AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
216 _AT_GLR_STDERR)
217AT_CLEANUP
218
219AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
220_AT_TEST_GLR_CALC([$1],[],[%merge <stmtMerge>],[%merge <stmtMerge>])
221AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
222 _AT_GLR_STDERR)
223AT_CLEANUP
224
225AT_SETUP([GLR: Merge conflicting parses, impure, locations])
226_AT_TEST_GLR_CALC([$1],[%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
227AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
228 _AT_GLR_STDERR)
229AT_CLEANUP
230
231AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
232_AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
233AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
234 _AT_GLR_STDERR)
235AT_CLEANUP
236AT_SETUP([GLR: Merge conflicting parses, pure, locations])
237_AT_TEST_GLR_CALC([$1],[%pure-parser
238%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
239AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT,
240 _AT_GLR_STDERR)
241AT_CLEANUP
242
243AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
244_AT_TEST_GLR_CALC([$1],[%error-verbose],
245[%merge <stmtMerge>],[%merge <stmtMerge>])
246AT_CHECK([[./types test-input | sed 's/ *$//']], 0,
247 _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR)
248AT_CLEANUP