]>
Commit | Line | Data |
---|---|---|
ed8e1f68 | 1 | # Exercising Bison Grammar Sets. -*- Autotest -*- |
318b76e9 | 2 | # Copyright 2001, 2002 Free Software Foundation, Inc. |
ed8e1f68 AD |
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 | ||
318b76e9 AD |
19 | # AT_EXTRACT_SETS(INPUT, OUTPUT) |
20 | # ------------------------------ | |
21 | # Extract the information about the grammar sets from a bison | |
22 | # trace output (INPUT), and save it in OUTPUT. | |
23 | # And remember, there is no alternation in portable sed. | |
24 | m4_define([AT_EXTRACT_SETS], | |
25 | [AT_DATA([extract.sed], | |
26 | [[#n | |
27 | /^NULLABLE$/ { | |
28 | :nullable | |
29 | p | |
30 | n | |
31 | /^[ ]*$/! b nullable | |
32 | } | |
33 | /^FIRSTS$/ { | |
34 | :firsts | |
35 | p | |
36 | n | |
37 | /^[ ]*$/! b firsts | |
38 | } | |
39 | /^FDERIVES$/ { | |
40 | :fderives | |
41 | p | |
42 | n | |
43 | /^[ ]*$/! b fderives | |
44 | } | |
45 | /^DERIVES$/ { | |
46 | :derives | |
47 | p | |
48 | n | |
49 | /^[ ]*$/! b derives | |
50 | } | |
51 | ]]) | |
52 | AT_CHECK([sed -f extract.sed $1], 0, [stdout]) | |
53 | AT_CHECK([mv stdout $2]) | |
54 | ]) | |
55 | ||
56 | ||
57 | ||
ed8e1f68 AD |
58 | AT_BANNER([[Grammar Sets (Firsts etc.).]]) |
59 | ||
60 | ||
61 | ## ---------- ## | |
62 | ## Nullable. ## | |
63 | ## ---------- ## | |
64 | ||
65 | AT_SETUP([Nullable]) | |
66 | ||
67 | # At some point, nullable had been smoking grass, and managed to say: | |
68 | # | |
69 | # Entering set_nullable | |
70 | # NULLABLE | |
71 | # 'e': yes | |
72 | # (null): no | |
73 | # ... | |
74 | ||
75 | AT_DATA([[input.y]], | |
76 | [[%% | |
77 | e: 'e' | /* Nothing */; | |
78 | ]]) | |
79 | ||
30171f79 | 80 | AT_CHECK([[bison --trace input.y]], [], [], [stderr]) |
318b76e9 AD |
81 | AT_EXTRACT_SETS([stderr], [sets]) |
82 | AT_CHECK([[cat sets]], [], | |
83 | [[DERIVES | |
30171f79 | 84 | $axiom derives |
3d4daee3 | 85 | 1: e $ (rule 0) |
ed8e1f68 | 86 | e derives |
3d4daee3 AD |
87 | 2: 'e' (rule 1) |
88 | 3: (rule 2) | |
ed8e1f68 | 89 | NULLABLE |
3d4daee3 | 90 | $axiom: no |
ed8e1f68 | 91 | e: yes |
ed8e1f68 | 92 | FIRSTS |
30171f79 AD |
93 | $axiom firsts |
94 | 4 ($axiom) | |
95 | 5 (e) | |
ed8e1f68 | 96 | e firsts |
30171f79 | 97 | 5 (e) |
ed8e1f68 | 98 | FDERIVES |
30171f79 | 99 | $axiom derives |
29d29c8f AD |
100 | 0: e $ |
101 | 1: 'e' | |
102 | 2: | |
ed8e1f68 | 103 | e derives |
29d29c8f AD |
104 | 1: 'e' |
105 | 2: | |
ed8e1f68 AD |
106 | ]]) |
107 | ||
108 | AT_CLEANUP | |
109 | ||
110 | ||
111 | ## ---------------- ## | |
112 | ## Broken Closure. ## | |
113 | ## ---------------- ## | |
114 | ||
115 | # TC was once broken during a massive `simplification' of the code. | |
116 | # It resulted in bison dumping core on the following grammar (the | |
117 | # computation of FIRSTS uses TC). It managed to produce a pretty | |
118 | # exotic closure: | |
119 | # | |
120 | # TC: Input | |
121 | # | |
122 | # 01234567 | |
123 | # +--------+ | |
124 | # 0| 1 | | |
125 | # 1| 1 | | |
126 | # 2| 1 | | |
127 | # 3| 1 | | |
128 | # 4| 1 | | |
129 | # 5| 1 | | |
130 | # 6| 1| | |
131 | # 7| | | |
132 | # +--------+ | |
133 | # | |
134 | # TC: Output | |
135 | # | |
136 | # 01234567 | |
137 | # +--------+ | |
138 | # 0| 1 | | |
139 | # 1| 111 | | |
140 | # 2| 111 | | |
141 | # 3| 1111 | | |
142 | # 4| 111 1 | | |
143 | # 5| 111 1 | | |
144 | # 6| 111 1| | |
145 | # 7| 111 | | |
146 | # +--------+ | |
147 | # | |
148 | # instead of that below. | |
149 | ||
150 | AT_SETUP([Broken Closure]) | |
151 | ||
152 | AT_DATA([input.y], | |
153 | [[%% | |
e5352bc7 AD |
154 | a: b; |
155 | b: c; | |
156 | c: d; | |
157 | d: e; | |
158 | e: f; | |
159 | f: g; | |
160 | g: h; | |
161 | h: 'h'; | |
ed8e1f68 AD |
162 | ]]) |
163 | ||
30171f79 AD |
164 | AT_CHECK([[bison --trace input.y]], [], [], [stderr]) |
165 | ||
166 | AT_CHECK([[sed -n 's/[ ]*$//;/^TC: Output BEGIN/,/^TC: Output END/p' stderr]], [], | |
ed8e1f68 | 167 | [[TC: Output BEGIN |
30171f79 AD |
168 | |
169 | 012345678 | |
170 | .---------. | |
171 | 0| 11111111| | |
172 | 1| 1111111| | |
173 | 2| 111111| | |
174 | 3| 11111| | |
175 | 4| 1111| | |
176 | 5| 111| | |
177 | 6| 11| | |
178 | 7| 1| | |
179 | 8| | | |
180 | `---------' | |
ed8e1f68 AD |
181 | TC: Output END |
182 | ]]) | |
183 | ||
184 | AT_CLEANUP | |
318b76e9 AD |
185 | |
186 | ||
187 | ||
188 | ## -------- ## | |
189 | ## Firsts. ## | |
190 | ## -------- ## | |
191 | ||
192 | AT_SETUP([Firsts]) | |
193 | ||
194 | AT_DATA([input.y], | |
195 | [[%nonassoc '<' '>' | |
196 | %left '+' '-' | |
197 | %right '^' '=' | |
198 | %% | |
199 | exp: | |
200 | exp '<' exp | |
201 | | exp '>' exp | |
202 | | exp '+' exp | |
203 | | exp '-' exp | |
204 | | exp '^' exp | |
205 | | exp '=' exp | |
206 | | "exp" | |
207 | ; | |
208 | ]]) | |
209 | ||
210 | AT_CHECK([[bison --trace input.y]], [], [], [stderr]) | |
211 | AT_EXTRACT_SETS([stderr], [sets]) | |
212 | AT_CHECK([[cat sets]], [], | |
213 | [[DERIVES | |
214 | $axiom derives | |
215 | 1: exp $ (rule 0) | |
216 | exp derives | |
217 | 2: exp '<' exp (rule 1) | |
218 | 3: exp '>' exp (rule 2) | |
219 | 4: exp '+' exp (rule 3) | |
220 | 5: exp '-' exp (rule 4) | |
221 | 6: exp '^' exp (rule 5) | |
222 | 7: exp '=' exp (rule 6) | |
223 | 8: "exp" (rule 7) | |
224 | NULLABLE | |
225 | $axiom: no | |
226 | exp: no | |
227 | FIRSTS | |
228 | $axiom firsts | |
229 | 10 ($axiom) | |
230 | 11 (exp) | |
231 | exp firsts | |
232 | 11 (exp) | |
233 | FDERIVES | |
234 | $axiom derives | |
235 | 0: exp $ | |
236 | 1: exp '<' exp | |
237 | 2: exp '>' exp | |
238 | 3: exp '+' exp | |
239 | 4: exp '-' exp | |
240 | 5: exp '^' exp | |
241 | 6: exp '=' exp | |
242 | 7: "exp" | |
243 | exp derives | |
244 | 1: exp '<' exp | |
245 | 2: exp '>' exp | |
246 | 3: exp '+' exp | |
247 | 4: exp '-' exp | |
248 | 5: exp '^' exp | |
249 | 6: exp '=' exp | |
250 | 7: "exp" | |
251 | ]]) | |
252 | ||
253 | AT_CLEANUP |