Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 79... Line 109...
79
 *	``grammar_factor''
109
 *	``grammar_factor''
80
 *
110
 *
81
 * This function applies the ``rule_factor'' function to all of the rules in
111
 * This function applies the ``rule_factor'' function to all of the rules in
82
 * the grammar.  The function does a number of transformations on the rules to
112
 * the grammar.  The function does a number of transformations on the rules to
83
 * make them more likely to be LL(1).  See the file "rule-factor.c" for more
113
 * make them more likely to be LL(1).  See the file "rule-factor.c" for more
84
 * details.
114
 * details.
85
 *
115
 *
86
 *	``grammar_simplify''
116
 *	``grammar_simplify''
87
 *
117
 *
88
 * This function calls the ``rule_remove_duplicates'' function on the grammar,
118
 * This function calls the ``rule_remove_duplicates'' function on the grammar,
89
 * to remove any rules that have identical form.  See the file "rule-simp.c"
119
 * to remove any rules that have identical form.  See the file "rule-simp.c"
90
 * for more details.
120
 * for more details.
91
 *
121
 *
Line 141... Line 171...
141
#include "type.h"
171
#include "type.h"
142
 
172
 
143
/*--------------------------------------------------------------------------*/
173
/*--------------------------------------------------------------------------*/
144
 
174
 
145
static void
175
static void
146
grammar_trace_ignored PROTO_N ((entry, gclosure))
176
grammar_trace_ignored(EntryP entry, GenericP gclosure)
147
		      PROTO_T (EntryP   entry X
-
 
148
			       GenericP gclosure)
-
 
149
{
177
{
150
    UNUSED (gclosure);
178
    UNUSED(gclosure);
151
    if (entry_is_basic (entry)) {
179
    if (entry_is_basic(entry)) {
152
	BasicP basic = entry_get_basic (entry);
180
	BasicP basic = entry_get_basic(entry);
153
 
181
 
154
	if (basic_get_ignored (basic)) {
182
	if (basic_get_ignored(basic)) {
155
	    entry_iter (entry, TRUE,
183
	    entry_iter(entry, TRUE,
156
			NIL (void (*) PROTO_S ((EntryP, GenericP))),
184
			NIL(void(*)(EntryP, GenericP)), NIL(GenericP));
157
			NIL (GenericP));
-
 
158
	}
185
	}
159
    }
186
    }
160
}
187
}
161
 
188
 
162
static void
189
static void
163
grammar_check_1 PROTO_N ((entry, gclosure))
190
grammar_check_1(EntryP entry, GenericP gclosure)
164
		PROTO_T (EntryP   entry X
-
 
165
			 GenericP gclosure)
-
 
166
{
191
{
167
    UNUSED (gclosure);
192
    UNUSED(gclosure);
168
    switch (entry_type (entry)) EXHAUSTIVE {
193
    switch (entry_type(entry))EXHAUSTIVE {
169
      case ET_RULE:
194
      case ET_RULE:
170
	if (!rule_is_defined (entry_get_rule (entry))) {
195
	if (!rule_is_defined(entry_get_rule(entry))) {
171
	    E_rule_not_defined (entry_key (entry));
196
	    E_rule_not_defined(entry_key(entry));
172
	}
197
	}
173
	if (!entry_is_traced (entry)) {
198
	if (!entry_is_traced(entry)) {
174
	    E_rule_not_used (entry_key (entry));
199
	    E_rule_not_used(entry_key(entry));
175
	}
200
	}
176
	break;
201
	break;
177
      case ET_BASIC:
202
      case ET_BASIC:
178
	if (!entry_is_traced (entry)) {
203
	if (!entry_is_traced(entry)) {
179
	    E_basic_not_used (entry_key (entry));
204
	    E_basic_not_used(entry_key(entry));
180
	}
205
	}
181
	break;
206
	break;
182
      case ET_ACTION:
207
      case ET_ACTION:
183
	if (!entry_is_traced (entry)) {
208
	if (!entry_is_traced(entry)) {
184
	    E_action_not_used (entry_key (entry));
209
	    E_action_not_used(entry_key(entry));
185
	}
210
	}
186
	break;
211
	break;
187
      case ET_TYPE:
212
      case ET_TYPE:
188
	if (!entry_is_traced (entry)) {
213
	if (!entry_is_traced(entry)) {
189
	    E_type_not_used (entry_key (entry));
214
	    E_type_not_used(entry_key(entry));
190
	}
215
	}
191
	break;
216
	break;
192
      case ET_NON_LOCAL:
217
      case ET_NON_LOCAL:
193
	if (!entry_is_traced (entry)) {
218
	if (!entry_is_traced(entry)) {
194
	    E_non_local_not_used (entry_key (entry));
219
	    E_non_local_not_used(entry_key(entry));
195
	}
220
	}
196
	break;
221
	break;
197
      case ET_NAME:
222
      case ET_NAME:
198
      case ET_RENAME:
223
      case ET_RENAME:
199
	break;
224
	break;
200
      case ET_PREDICATE:
225
      case ET_PREDICATE:
201
	UNREACHED;
226
	UNREACHED;
202
    }
227
    }
203
}
228
}
204
 
229
 
205
static void
230
static void
206
grammar_find_cycles PROTO_N ((grammar, type))
231
grammar_find_cycles(GrammarP grammar, CycleTypeT type)
207
		    PROTO_T (GrammarP   grammar X
-
 
208
			     CycleTypeT type)
-
 
209
{
232
{
210
    TableP     table         = grammar_table (grammar);
233
    TableP     table         = grammar_table(grammar);
211
    EntryP     predicate_id  = grammar_get_predicate_id (grammar);
234
    EntryP     predicate_id  = grammar_get_predicate_id(grammar);
212
    RuleP      dfs_list_head = NIL (RuleP);
235
    RuleP      dfs_list_head = NIL(RuleP);
213
    RuleListT  root_list;
236
    RuleListT  root_list;
214
    RuleP      rule;
237
    RuleP      rule;
215
 
238
 
216
    rule_list_init (&root_list);
239
    rule_list_init(&root_list);
217
    table_iter (table, rule_build_root_list, (GenericP) &root_list);
240
    table_iter(table, rule_build_root_list, (GenericP)&root_list);
218
    rule_list_terminate (&root_list);
241
    rule_list_terminate(&root_list);
219
    for (rule = rule_list_head (&root_list); rule;
242
    for (rule = rule_list_head(&root_list); rule;
220
	 rule = rule_next_in_root_list (rule)) {
243
	 rule = rule_next_in_root_list(rule)) {
221
	rule_compute_reverse_list (rule, type);
244
	rule_compute_reverse_list(rule, type);
222
	rule_compute_dfs (rule, type, &dfs_list_head);
245
	rule_compute_dfs(rule, type, &dfs_list_head);
223
    }
246
    }
224
    for (rule = rule_list_head (&root_list); rule;
247
    for (rule = rule_list_head(&root_list); rule;
225
	 rule = rule_next_in_root_list (rule)) {
248
	 rule = rule_next_in_root_list(rule)) {
226
	rule_set_dfs_state (rule, DFS_UNTRACED);
249
	rule_set_dfs_state(rule, DFS_UNTRACED);
227
    }
250
    }
228
    for (rule = dfs_list_head; rule; rule = rule_get_next_in_dfs (rule)) {
251
    for (rule = dfs_list_head; rule; rule = rule_get_next_in_dfs(rule)) {
229
	if (!rule_has_no_cycles (rule)) {
252
	if (!rule_has_no_cycles(rule)) {
230
	    RuleP reverse_dfs_list_head = NIL (RuleP);
253
	    RuleP reverse_dfs_list_head = NIL(RuleP);
231
 
254
 
232
	    rule_compute_reverse_dfs (rule, rule, &reverse_dfs_list_head);
255
	    rule_compute_reverse_dfs(rule, rule, &reverse_dfs_list_head);
233
	    if (reverse_dfs_list_head) {
256
	    if (reverse_dfs_list_head) {
234
		switch (type) EXHAUSTIVE {
257
		switch (type)EXHAUSTIVE {
235
		  case CT_LEFT:
258
		  case CT_LEFT:
236
		    rule_remove_left_cycle (reverse_dfs_list_head,
259
		    rule_remove_left_cycle(reverse_dfs_list_head,
237
					    predicate_id, table);
260
					    predicate_id, table);
238
		    break;
261
		    break;
239
		  case CT_TAIL:
262
		  case CT_TAIL:
240
		    rule_handle_tails (reverse_dfs_list_head);
263
		    rule_handle_tails(reverse_dfs_list_head);
241
		    break;
264
		    break;
242
		  case CT_ALL:
265
		  case CT_ALL:
243
		    rule_handle_need_functions (reverse_dfs_list_head);
266
		    rule_handle_need_functions(reverse_dfs_list_head);
244
		    break;
267
		    break;
245
		  case CT_MUTATE:
268
		  case CT_MUTATE:
246
		    UNREACHED;
269
		    UNREACHED;
247
		}
270
		}
248
	    }
271
	    }
249
	}
272
	}
250
    }
273
    }
251
    for (rule = rule_list_head (&root_list); rule;
274
    for (rule = rule_list_head(&root_list); rule;
252
	 rule = rule_next_in_root_list (rule)) {
275
	 rule = rule_next_in_root_list(rule)) {
253
	rule_reinit_reverse_list (rule);
276
	rule_reinit_reverse_list(rule);
254
    }
277
    }
255
}
278
}
256
 
279
 
257
static void
280
static void
258
write_grammar_1 PROTO_N ((entry, gclosure))
281
write_grammar_1(EntryP entry, GenericP gclosure)
259
		PROTO_T (EntryP   entry X
-
 
260
			 GenericP gclosure)
-
 
261
{
282
{
262
    OStreamP ostream = (OStreamP) gclosure;
283
    OStreamP ostream = (OStreamP)gclosure;
263
 
284
 
264
    if (entry_is_rule (entry)) {
285
    if (entry_is_rule(entry)) {
265
	write_rule (ostream, entry_get_rule (entry));
286
	write_rule(ostream, entry_get_rule(entry));
266
	write_newline (ostream);
287
	write_newline(ostream);
267
    }
288
    }
268
}
289
}
269
 
290
 
270
/*--------------------------------------------------------------------------*/
291
/*--------------------------------------------------------------------------*/
271
 
292
 
272
void
293
void
273
grammar_init PROTO_N ((grammar))
294
grammar_init(GrammarP grammar)
274
	     PROTO_T (GrammarP grammar)
-
 
275
{
295
{
276
    TableP table = grammar_table (grammar);
296
    TableP table = grammar_table(grammar);
277
 
297
 
278
    table_init (table);
298
    table_init(table);
279
    entry_list_init (grammar_entry_list (grammar));
299
    entry_list_init(grammar_entry_list(grammar));
280
    grammar->terminal       = 0;
300
    grammar->terminal       = 0;
281
    grammar->predicate_type = NIL (EntryP);
301
    grammar->predicate_type = NIL(EntryP);
282
    grammar->predicate_id   = table_add_generated_name (table);
302
    grammar->predicate_id   = table_add_generated_name(table);
283
}
303
}
284
 
304
 
285
#ifdef FS_FAST
305
#ifdef FS_FAST
286
#undef grammar_table
306
#undef grammar_table
287
#endif /* defined (FS_FAST) */
307
#endif /* defined (FS_FAST) */
288
TableP
308
TableP
289
grammar_table PROTO_N ((grammar))
309
grammar_table(GrammarP grammar)
290
	      PROTO_T (GrammarP grammar)
-
 
291
{
310
{
292
    return (&(grammar->table));
311
    return(&(grammar->table));
293
}
312
}
294
#ifdef FS_FAST
313
#ifdef FS_FAST
295
#define grammar_table(g) (&((g)->table))
314
#define grammar_table(g)	(&((g)->table))
296
#endif /* defined (FS_FAST) */
315
#endif /* defined (FS_FAST) */
297
 
316
 
298
#ifdef FS_FAST
317
#ifdef FS_FAST
299
#undef grammar_entry_list
318
#undef grammar_entry_list
300
#endif /* defined (FS_FAST) */
319
#endif /* defined (FS_FAST) */
301
EntryListP
320
EntryListP
302
grammar_entry_list PROTO_N ((grammar))
321
grammar_entry_list(GrammarP grammar)
303
		   PROTO_T (GrammarP grammar)
-
 
304
{
322
{
305
    return (&(grammar->entry_list));
323
    return(&(grammar->entry_list));
306
}
324
}
307
#ifdef FS_FAST
325
#ifdef FS_FAST
308
#define grammar_entry_list(g) (&((g)->entry_list))
326
#define grammar_entry_list(g)	(&((g)->entry_list))
309
#endif /* defined (FS_FAST) */
327
#endif /* defined (FS_FAST) */
310
 
328
 
311
#ifdef FS_FAST
329
#ifdef FS_FAST
312
#undef grammar_max_terminal
330
#undef grammar_max_terminal
313
#endif /* defined (FS_FAST) */
331
#endif /* defined (FS_FAST) */
314
unsigned
332
unsigned
315
grammar_max_terminal PROTO_N ((grammar))
333
grammar_max_terminal(GrammarP grammar)
316
		     PROTO_T (GrammarP grammar)
-
 
317
{
334
{
318
    return (grammar->terminal);
335
    return(grammar->terminal);
319
}
336
}
320
#ifdef FS_FAST
337
#ifdef FS_FAST
321
#define grammar_max_terminal(g) ((g)->terminal)
338
#define grammar_max_terminal(g)	((g)->terminal)
322
#endif /* defined (FS_FAST) */
339
#endif /* defined (FS_FAST) */
323
 
340
 
324
unsigned
341
unsigned
325
grammar_next_terminal PROTO_N ((grammar))
342
grammar_next_terminal(GrammarP grammar)
326
		      PROTO_T (GrammarP grammar)
-
 
327
{
343
{
328
    if (grammar->terminal == UINT_MAX) {
344
    if (grammar->terminal == UINT_MAX) {
329
	E_too_many_terminals ();
345
	E_too_many_terminals();
330
	UNREACHED;
346
	UNREACHED;
331
    }
347
    }
332
    return (grammar->terminal ++);
348
    return(grammar->terminal++);
333
}
349
}
334
 
350
 
335
#ifdef FS_FAST
351
#ifdef FS_FAST
336
#undef grammar_get_predicate_type
352
#undef grammar_get_predicate_type
337
#endif /* defined (FS_FAST) */
353
#endif /* defined (FS_FAST) */
338
EntryP
354
EntryP
339
grammar_get_predicate_type PROTO_N ((grammar))
355
grammar_get_predicate_type(GrammarP grammar)
340
			   PROTO_T (GrammarP grammar)
-
 
341
{
356
{
342
    return (grammar->predicate_type);
357
    return(grammar->predicate_type);
343
}
358
}
344
#ifdef FS_FAST
359
#ifdef FS_FAST
345
#define grammar_get_predicate_type(g) ((g)->predicate_type)
360
#define grammar_get_predicate_type(g)	((g)->predicate_type)
346
#endif /* defined (FS_FAST) */
361
#endif /* defined (FS_FAST) */
347
 
362
 
348
#ifdef FS_FAST
363
#ifdef FS_FAST
349
#undef grammar_set_predicate_type
364
#undef grammar_set_predicate_type
350
#endif /* defined (FS_FAST) */
365
#endif /* defined (FS_FAST) */
351
void
366
void
352
grammar_set_predicate_type PROTO_N ((grammar, type))
367
grammar_set_predicate_type(GrammarP grammar, EntryP type)
353
			   PROTO_T (GrammarP grammar X
-
 
354
				    EntryP   type)
-
 
355
{
368
{
356
    grammar->predicate_type = type;
369
    grammar->predicate_type = type;
357
}
370
}
358
#ifdef FS_FAST
371
#ifdef FS_FAST
359
#define grammar_set_predicate_type(g, t) ((g)->predicate_type = (t))
372
#define grammar_set_predicate_type(g, t)	((g)->predicate_type = (t))
360
#endif /* defined (FS_FAST) */
373
#endif /* defined (FS_FAST) */
361
 
374
 
362
#ifdef FS_FAST
375
#ifdef FS_FAST
363
#undef grammar_get_predicate_id
376
#undef grammar_get_predicate_id
364
#endif /* defined (FS_FAST) */
377
#endif /* defined (FS_FAST) */
365
EntryP
378
EntryP
366
grammar_get_predicate_id PROTO_N ((grammar))
379
grammar_get_predicate_id(GrammarP grammar)
367
			 PROTO_T (GrammarP grammar)
-
 
368
{
380
{
369
    return (grammar->predicate_id);
381
    return(grammar->predicate_id);
370
}
382
}
371
#ifdef FS_FAST
383
#ifdef FS_FAST
372
#define grammar_get_predicate_id(g) ((g)->predicate_id)
384
#define grammar_get_predicate_id(g)	((g)->predicate_id)
373
#endif /* defined (FS_FAST) */
385
#endif /* defined (FS_FAST) */
374
 
386
 
375
void
387
void
376
grammar_check_complete PROTO_N ((grammar))
388
grammar_check_complete(GrammarP grammar)
377
		       PROTO_T (GrammarP grammar)
-
 
378
{
389
{
379
    TableP     table      = grammar_table (grammar);
390
    TableP     table      = grammar_table(grammar);
380
    EntryListP entry_list = grammar_entry_list (grammar);
391
    EntryListP entry_list = grammar_entry_list(grammar);
381
 
392
 
382
    table_untrace (table);
393
    table_untrace(table);
383
    entry_list_iter_table (entry_list, TRUE,
394
    entry_list_iter_table(entry_list, TRUE, NIL(void(*)(EntryP, GenericP)),
384
			   NIL (void (*) PROTO_S ((EntryP, GenericP))),
-
 
385
			   NIL (GenericP));
395
			  NIL(GenericP));
386
    table_iter (table, grammar_trace_ignored, NIL (GenericP));
396
    table_iter(table, grammar_trace_ignored, NIL(GenericP));
387
    table_iter (table, grammar_check_1, NIL (GenericP));
397
    table_iter(table, grammar_check_1, NIL(GenericP));
388
}
398
}
389
 
399
 
390
void
400
void
391
grammar_remove_left_recursion PROTO_N ((grammar))
401
grammar_remove_left_recursion(GrammarP grammar)
392
			      PROTO_T (GrammarP grammar)
-
 
393
{
402
{
394
    grammar_find_cycles (grammar, CT_LEFT);
403
    grammar_find_cycles(grammar, CT_LEFT);
395
}
404
}
396
 
405
 
397
void
406
void
398
grammar_compute_first_sets PROTO_N ((grammar))
407
grammar_compute_first_sets(GrammarP grammar)
399
			   PROTO_T (GrammarP grammar)
-
 
400
{
408
{
401
    TableP table = grammar_table (grammar);
409
    TableP table = grammar_table(grammar);
402
 
410
 
403
    table_iter (table, rule_compute_first_set, NIL (GenericP));
411
    table_iter(table, rule_compute_first_set, NIL(GenericP));
404
}
412
}
405
 
413
 
406
void
414
void
407
grammar_factor PROTO_N ((grammar))
415
grammar_factor(GrammarP grammar)
408
	       PROTO_T (GrammarP grammar)
-
 
409
{
416
{
410
    TableP         table      = grammar_table (grammar);
417
    TableP         table      = grammar_table(grammar);
411
    EntryListP     entry_list = grammar_entry_list (grammar);
418
    EntryListP     entry_list = grammar_entry_list(grammar);
412
    FactorClosureT closure;
419
    FactorClosureT closure;
413
 
420
 
414
    bitvec_init (&(closure.bitvec1));
421
    bitvec_init(&(closure.bitvec1));
415
    bitvec_init (&(closure.bitvec2));
422
    bitvec_init(&(closure.bitvec2));
416
    closure.table        = table;
423
    closure.table        = table;
417
    closure.predicate_id = grammar_get_predicate_id (grammar);
424
    closure.predicate_id = grammar_get_predicate_id(grammar);
418
    table_untrace (table);
425
    table_untrace(table);
419
    entry_list_iter_table (entry_list, FALSE, rule_factor,
426
    entry_list_iter_table(entry_list, FALSE, rule_factor, (GenericP)&closure);
420
			   (GenericP) &closure);
-
 
421
    table_unlink_untraced_rules (table);
427
    table_unlink_untraced_rules(table);
422
    bitvec_destroy (&(closure.bitvec1));
428
    bitvec_destroy(&(closure.bitvec1));
423
    bitvec_destroy (&(closure.bitvec2));
429
    bitvec_destroy(&(closure.bitvec2));
424
}
430
}
425
 
431
 
426
void
432
void
427
grammar_simplify PROTO_N ((grammar))
433
grammar_simplify(GrammarP grammar)
428
		 PROTO_T (GrammarP grammar)
-
 
429
{
434
{
430
    TableP       table        = grammar_table (grammar);
435
    TableP       table        = grammar_table(grammar);
431
    EntryListP   entry_list   = grammar_entry_list (grammar);
436
    EntryListP   entry_list   = grammar_entry_list(grammar);
432
    EntryP       predicate_id = grammar_get_predicate_id (grammar);
437
    EntryP       predicate_id = grammar_get_predicate_id(grammar);
433
 
438
 
434
    rule_remove_duplicates (table, predicate_id);
439
    rule_remove_duplicates(table, predicate_id);
435
    table_untrace (table);
440
    table_untrace(table);
436
    entry_list_iter_table (entry_list, FALSE,
441
    entry_list_iter_table(entry_list, FALSE, NIL(void(*)(EntryP, GenericP)),
437
			   NIL (void (*) PROTO_S ((EntryP, GenericP))),
-
 
438
			   NIL (GenericP));
442
			  NIL(GenericP));
439
    table_unlink_untraced_rules (table);
443
    table_unlink_untraced_rules(table);
440
}
444
}
441
 
445
 
442
void
446
void
443
grammar_compute_inlining PROTO_N ((grammar))
447
grammar_compute_inlining(GrammarP grammar)
444
			 PROTO_T (GrammarP grammar)
-
 
445
{
448
{
446
    TableP     table         = grammar_table (grammar);
449
    TableP     table         = grammar_table(grammar);
447
 
450
 
448
    if (rule_get_inline_tail_calls ()) {
451
    if (rule_get_inline_tail_calls()) {
449
	grammar_find_cycles (grammar, CT_TAIL);
452
	grammar_find_cycles(grammar, CT_TAIL);
450
    }
453
    }
451
    table_iter (table, rule_compute_all_basics, NIL (GenericP));
454
    table_iter(table, rule_compute_all_basics, NIL(GenericP));
452
    table_iter (table, rule_compute_inlining, NIL (GenericP));
455
    table_iter(table, rule_compute_inlining, NIL(GenericP));
453
    table_iter (table, rule_compute_needed_functions, NIL (GenericP));
456
    table_iter(table, rule_compute_needed_functions, NIL(GenericP));
454
    grammar_find_cycles (grammar, CT_ALL);
457
    grammar_find_cycles(grammar, CT_ALL);
455
}
458
}
456
 
459
 
457
void
460
void
458
grammar_check_collisions PROTO_N ((grammar))
461
grammar_check_collisions(GrammarP grammar)
459
			 PROTO_T (GrammarP grammar)
-
 
460
{
462
{
461
    TableP table = grammar_table (grammar);
463
    TableP table = grammar_table(grammar);
462
 
464
 
463
    table_iter (table, rule_check_first_set, (GenericP) grammar);
465
    table_iter(table, rule_check_first_set, (GenericP)grammar);
464
    table_iter (table, rule_compute_follow_set, (GenericP) grammar);
466
    table_iter(table, rule_compute_follow_set, (GenericP)grammar);
465
    table_iter (table, rule_compute_see_through_alt, NIL (GenericP));
467
    table_iter(table, rule_compute_see_through_alt, NIL(GenericP));
466
    table_iter (table, rule_compute_alt_first_sets, NIL (GenericP));
468
    table_iter(table, rule_compute_alt_first_sets, NIL(GenericP));
467
}
469
}
468
 
470
 
469
void
471
void
470
grammar_recompute_alt_names PROTO_N ((grammar))
472
grammar_recompute_alt_names(GrammarP grammar)
471
			    PROTO_T (GrammarP grammar)
-
 
472
{
473
{
473
    TableP table        = grammar_table (grammar);
474
    TableP table        = grammar_table(grammar);
474
    EntryP predicate_id = grammar_get_predicate_id (grammar);
475
    EntryP predicate_id = grammar_get_predicate_id(grammar);
475
 
476
 
476
    table_iter (table, rule_recompute_alt_names, (GenericP) predicate_id);
477
    table_iter(table, rule_recompute_alt_names, (GenericP)predicate_id);
477
}
478
}
478
 
479
 
479
void
480
void
480
grammar_compute_mutations PROTO_N ((grammar))
481
grammar_compute_mutations(GrammarP grammar)
481
			  PROTO_T (GrammarP grammar)
-
 
482
{
482
{
483
    TableP    table = grammar_table (grammar);
483
    TableP    table = grammar_table(grammar);
484
    RuleListT root_list;
484
    RuleListT root_list;
485
    RuleP     rule;
485
    RuleP     rule;
486
 
486
 
487
    rule_list_init (&root_list);
487
    rule_list_init(&root_list);
488
    table_iter (table, rule_build_root_list, (GenericP) &root_list);
488
    table_iter(table, rule_build_root_list, (GenericP)&root_list);
489
    rule_list_terminate (&root_list);
489
    rule_list_terminate(&root_list);
490
    for (rule = rule_list_head (&root_list); rule;
490
    for (rule = rule_list_head(&root_list); rule;
491
	 rule = rule_next_in_root_list (rule)) {
491
	 rule = rule_next_in_root_list(rule)) {
492
	rule_compute_reverse_list (rule, CT_MUTATE);
492
	rule_compute_reverse_list(rule, CT_MUTATE);
-
 
493
    }
-
 
494
    table_iter(table, rule_compute_mutations, NIL(GenericP));
-
 
495
    for (rule = rule_list_head(&root_list); rule;
-
 
496
	 rule = rule_next_in_root_list(rule)) {
-
 
497
	rule_reinit_reverse_list(rule);
493
    }
498
    }
494
    table_iter (table, rule_compute_mutations, NIL (GenericP));
-
 
495
    for (rule = rule_list_head (&root_list); rule;
-
 
496
	 rule = rule_next_in_root_list (rule)) {
-
 
497
	rule_reinit_reverse_list (rule);
-
 
498
    }    
-
 
499
}
499
}
500
 
500
 
501
void
501
void
502
write_grammar PROTO_N ((ostream, grammar))
502
write_grammar(OStreamP ostream, GrammarP grammar)
503
	      PROTO_T (OStreamP ostream X
-
 
504
		       GrammarP grammar)
-
 
505
{
503
{
506
    TableP     table      = grammar_table (grammar);
504
    TableP     table      = grammar_table(grammar);
507
    EntryListP entry_list = grammar_entry_list (grammar);
505
    EntryListP entry_list = grammar_entry_list(grammar);
508
 
506
 
509
    table_untrace (table);
507
    table_untrace(table);
510
    entry_list_iter_table (entry_list, FALSE, write_grammar_1,
508
    entry_list_iter_table(entry_list, FALSE, write_grammar_1,
511
			   (GenericP) ostream);
509
			  (GenericP)ostream);
512
}
510
}
513

511

514
/*
512
/*
515
 * Local variables(smf):
513
 * Local variables(smf):
516
 * eval: (include::add-path-entry "../os-interface" "../library")
514
 * eval: (include::add-path-entry "../os-interface" "../library")