]>
Commit | Line | Data |
---|---|---|
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 | ||
19 | AT_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. | |
26 | m4_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 | ||
48 | prog : | |
49 | | prog stmt { printf ("\n"); } | |
50 | ; | |
51 | ||
52 | stmt : expr ';' $3 | |
53 | | decl $4 | |
54 | | error ';' | |
55 | | '@' { YYACCEPT; } | |
56 | ; | |
57 | ||
58 | expr : ID { printf ("%s ", $$); } | |
59 | | TYPENAME '(' expr ')' | |
60 | { printf ("%s <cast> ", $1); } | |
61 | | expr '+' expr { printf ("+ "); } | |
62 | | expr '=' expr { printf ("= "); } | |
63 | ; | |
64 | ||
65 | decl : TYPENAME declarator ';' | |
66 | { printf ("%s <declare> ", $1); } | |
67 | | TYPENAME declarator '=' expr ';' | |
68 | { printf ("%s <init-declare> ", $1); } | |
69 | ; | |
70 | ||
71 | declarator : ID { printf ("\"%s\" ", $1); } | |
72 | | '(' declarator ')' | |
73 | ; | |
74 | ||
75 | %% | |
76 | ||
77 | #include <ctype.h> | |
78 | #include <strings.h> | |
79 | ||
80 | main (int argc, char** argv) | |
81 | { | |
82 | freopen (argv[1], "r", stdin); | |
83 | exit (yyparse ()); | |
84 | } | |
85 | ||
86 | #if YYPURE | |
87 | int yylex (YYSTYPE *lvalp) | |
88 | #define yylval (*lvalp) | |
89 | #else | |
90 | int 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 | ||
114 | int | |
115 | yyerror (const char *s) | |
116 | { | |
117 | fprintf (stderr, "%s\n", s); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1) | |
122 | { | |
123 | printf ("<OR> "); | |
124 | return ""; | |
125 | } | |
126 | ]]) | |
127 | ||
128 | AT_DATA([test-input], | |
129 | [[ | |
130 | ||
131 | z + q; | |
132 | ||
133 | T x; | |
134 | ||
135 | T x = y; | |
136 | ||
137 | x = y; | |
138 | ||
139 | T (x) + y; | |
140 | ||
141 | T (x); | |
142 | ||
143 | T (y) = z + q; | |
144 | ||
145 | T (y y) = z + q; | |
146 | ||
147 | z + q; | |
148 | ||
149 | @ | |
150 | ||
151 | This is total garbage, but it should be ignored. | |
152 | ]]) | |
153 | ||
154 | AT_CHECK([bison types.y], 0, [], ignore) | |
155 | AT_CHECK([gcc -o types types.tab.c], 0, [], ignore) | |
156 | ]) | |
157 | ||
158 | m4_define([_AT_RESOLVED_GLR_OUTPUT], | |
159 | [[z q + | |
160 | "x" T <declare> | |
161 | "x" y T <init-declare> | |
162 | x y = | |
163 | x T <cast> y + | |
164 | "x" T <declare> | |
165 | "y" z q + T <init-declare> | |
166 | y | |
167 | z q + | |
168 | ]]) | |
169 | ||
170 | m4_define([_AT_AMBIG_GLR_OUTPUT], | |
171 | [[z q + | |
172 | "x" T <declare> | |
173 | "x" y T <init-declare> | |
174 | x y = | |
175 | x T <cast> y + | |
176 | "x" T <declare> x T <cast> <OR> | |
177 | "y" z q + T <init-declare> y T <cast> z q + = <OR> | |
178 | y | |
179 | z q + | |
180 | ]]) | |
181 | ||
182 | m4_define([_AT_GLR_STDERR], | |
183 | [[parse error | |
184 | ]]) | |
185 | ||
186 | m4_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 | ||
194 | AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) | |
195 | _AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2]) | |
196 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, | |
197 | _AT_GLR_STDERR) | |
198 | AT_CLEANUP | |
199 | ||
200 | AT_SETUP([GLR: Resolve ambiguity, impure, locations]) | |
201 | _AT_TEST_GLR_CALC([$1],[%locations],[%dprec 1],[%dprec 2]) | |
202 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, | |
203 | _AT_GLR_STDERR) | |
204 | AT_CLEANUP | |
205 | ||
206 | AT_SETUP([GLR: Resolve ambiguity, pure, no locations]) | |
207 | _AT_TEST_GLR_CALC([$1],[%pure-parser],[%dprec 1],[%dprec 2]) | |
208 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, | |
209 | _AT_GLR_STDERR) | |
210 | AT_CLEANUP | |
211 | ||
212 | AT_SETUP([GLR: Resolve ambiguity, pure, locations]) | |
213 | _AT_TEST_GLR_CALC([$1],[%pure-parser | |
214 | %locations],[%dprec 1],[%dprec 2]) | |
215 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, | |
216 | _AT_GLR_STDERR) | |
217 | AT_CLEANUP | |
218 | ||
219 | AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) | |
220 | _AT_TEST_GLR_CALC([$1],[],[%merge <stmtMerge>],[%merge <stmtMerge>]) | |
221 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, | |
222 | _AT_GLR_STDERR) | |
223 | AT_CLEANUP | |
224 | ||
225 | AT_SETUP([GLR: Merge conflicting parses, impure, locations]) | |
226 | _AT_TEST_GLR_CALC([$1],[%locations],[%merge <stmtMerge>],[%merge <stmtMerge>]) | |
227 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, | |
228 | _AT_GLR_STDERR) | |
229 | AT_CLEANUP | |
230 | ||
231 | AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) | |
232 | _AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>]) | |
233 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, | |
234 | _AT_GLR_STDERR) | |
235 | AT_CLEANUP | |
236 | AT_SETUP([GLR: Merge conflicting parses, pure, locations]) | |
237 | _AT_TEST_GLR_CALC([$1],[%pure-parser | |
238 | %locations],[%merge <stmtMerge>],[%merge <stmtMerge>]) | |
239 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, | |
240 | _AT_GLR_STDERR) | |
241 | AT_CLEANUP | |
242 | ||
243 | AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) | |
244 | _AT_TEST_GLR_CALC([$1],[%error-verbose], | |
245 | [%merge <stmtMerge>],[%merge <stmtMerge>]) | |
246 | AT_CHECK([[./types test-input | sed 's/ *$//']], 0, | |
247 | _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) | |
248 | AT_CLEANUP |