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