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
*/
29
 
59
 
30
 
60
 
31
/*** main.c --- SID program main routine.
61
/*** main.c --- SID program main routine.
32
 *
62
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
64
 *
35
 *** Commentary:
65
 *** Commentary:
Line 70... Line 100...
70
 *
100
 *
71
 * Revision 1.11  1996/06/28  15:12:34  smf
101
 * Revision 1.11  1996/06/28  15:12:34  smf
72
 * main.c:
102
 * main.c:
73
 * 	- added extra information to version string;
103
 * 	- added extra information to version string;
74
 * 	- added "build" mechanism for release system.
104
 * 	- added "build" mechanism for release system.
75
 *
105
 *
76
 * Revision 1.10  1996/03/01  09:51:56  smf
106
 * Revision 1.10  1996/03/01  09:51:56  smf
77
 * main.c:
107
 * main.c:
78
 * 	- updated version number.
108
 * 	- updated version number.
79
 *
109
 *
80
 * Revision 1.9  1996/02/29  09:53:26  smf
110
 * Revision 1.9  1996/02/29  09:53:26  smf
Line 138... Line 168...
138
#include "syntax.h"
168
#include "syntax.h"
139
 
169
 
140
/*--------------------------------------------------------------------------*/
170
/*--------------------------------------------------------------------------*/
141
 
171
 
142
#define USAGE "\
172
#define USAGE "\
143
\tusage: [option ...] in-file ... out-file ...\n\
173
\tusage:[option ...]in-file ... out-file ...\n\
144
\twhere option is one of:"
174
\twhere option is one of:"
145
#ifndef VERSION
175
#ifndef VERSION
146
#define VERSION "sid: version 1.9#13 (ansi-c, pre-ansi-c, ossg-c, test)"
176
#define VERSION "sid: version 1.10.0 (ansi-c, pre-ansi-c, test)"
147
#endif /* !defined (VERSION) */
177
#endif /* !defined (VERSION) */
148
#ifndef RELEASE
178
#ifndef RELEASE
149
#define RELEASE "unknown"
179
#define RELEASE "unknown"
150
#endif /* !defined (RELEASE) */
180
#endif /* !defined (RELEASE) */
151
#ifndef BANNER
181
#ifndef BANNER
Line 154... Line 184...
154
 
184
 
155
/*--------------------------------------------------------------------------*/
185
/*--------------------------------------------------------------------------*/
156
 
186
 
157
typedef struct PhaseListT {
187
typedef struct PhaseListT {
158
    CStringP			phase;
188
    CStringP			phase;
159
    void		      (*proc) PROTO_S ((BoolT));
189
    void		     (*proc)(BoolT);
160
} PhaseListT, *PhaseListP;
190
} PhaseListT, *PhaseListP;
161
 
191
 
162
typedef struct LangListT {
192
typedef struct LangListT {
163
    CStringP			language;
193
    CStringP			language;
164
    GenericP		      (*init_proc) PROTO_S ((OutputInfoP,
194
    GenericP		     (*init_proc)(OutputInfoP, CStringListP);
165
						     CStringListP));
-
 
166
    void		      (*input_proc) PROTO_S ((GenericP, GrammarP));
195
    void		     (*input_proc)(GenericP, GrammarP);
167
    unsigned			num_input_files;
196
    unsigned			num_input_files;
168
    void		      (*output_proc) PROTO_S ((GenericP, GrammarP));
197
    void		     (*output_proc)(GenericP, GrammarP);
169
    unsigned			num_output_files;
198
    unsigned			num_output_files;
170
} LangListT, *LangListP;
199
} LangListT, *LangListP;
171
 
200
 
172
/*--------------------------------------------------------------------------*/
201
/*--------------------------------------------------------------------------*/
173
 
202
 
174
static void
203
static void
175
main_handle_phase_all PROTO_N ((enable))
204
main_handle_phase_all(BoolT enable)
176
		      PROTO_T (BoolT enable)
-
 
177
{
205
{
178
    rule_set_inline_singles (enable);
206
    rule_set_inline_singles(enable);
179
    rule_set_inline_tail_calls (enable);
207
    rule_set_inline_tail_calls(enable);
180
    rule_set_inline_all_basics (enable);
208
    rule_set_inline_all_basics(enable);
181
    rule_set_inline_non_tail_calls (enable);
209
    rule_set_inline_non_tail_calls(enable);
182
    rule_set_multiple_inlining (enable);
210
    rule_set_multiple_inlining(enable);
183
}
211
}
184
 
212
 
185
/*--------------------------------------------------------------------------*/
213
/*--------------------------------------------------------------------------*/
186
 
214
 
187
static GenericP
215
static GenericP
188
main_init_c PROTO_N ((out_info, options, ansi, ossg))
216
main_init_c(OutputInfoP out_info, CStringListP options, BoolT ansi)
189
	    PROTO_T (OutputInfoP  out_info X
-
 
190
		     CStringListP options X
-
 
191
		     BoolT        ansi X
-
 
192
		     BoolT        ossg )
-
 
193
{
217
{
194
    COutputInfoP      c_out_info = ALLOCATE (COutputInfoT);
218
    COutputInfoP      c_out_info = ALLOCATE(COutputInfoT);
195
    CStringListEntryP entry;
219
    CStringListEntryP entry;
196
 
220
 
197
    c_out_info_init (c_out_info, out_info);
221
    c_out_info_init(c_out_info, out_info);
198
    if (ansi) {
222
    if (ansi) {
199
	c_out_info_set_prototypes (c_out_info, TRUE);
223
	c_out_info_set_prototypes(c_out_info, TRUE);
200
    }
224
    }
201
    if (ossg) {
-
 
202
	c_out_info_set_ossg (c_out_info, TRUE);
-
 
203
    }
-
 
204
    for (entry = cstring_list_head (options); entry;
225
    for (entry = cstring_list_head(options); entry;
205
	 entry = cstring_list_entry_deallocate (entry)) {
226
	 entry = cstring_list_entry_deallocate(entry)) {
206
	CStringP option = cstring_list_entry_string (entry);
227
	CStringP option = cstring_list_entry_string(entry);
207
 
228
 
208
	if (cstring_equal (option, "prototypes") ||
229
	if (cstring_equal(option, "prototypes") ||
209
	    cstring_equal (option, "proto")) {
230
	    cstring_equal(option, "proto")) {
210
	    c_out_info_set_prototypes (c_out_info, TRUE);
231
	    c_out_info_set_prototypes(c_out_info, TRUE);
211
	    c_out_info_set_ossg (c_out_info, FALSE);
-
 
212
	} else if (cstring_equal (option, "no-prototypes") ||
232
	} else if (cstring_equal(option, "no-prototypes") ||
213
		   cstring_equal (option, "no-proto")) {
233
		   cstring_equal(option, "no-proto")) {
214
	    c_out_info_set_prototypes (c_out_info, FALSE);
234
	    c_out_info_set_prototypes(c_out_info, FALSE);
215
	    c_out_info_set_ossg (c_out_info, FALSE);
-
 
216
	} else if (cstring_equal (option, "ossg-prototypes") ||
-
 
217
		   cstring_equal (option, "ossg-proto")) {
-
 
218
	    c_out_info_set_prototypes (c_out_info, TRUE);
-
 
219
	    c_out_info_set_ossg (c_out_info, TRUE);
-
 
220
	} else if (cstring_equal (option, "split")) {
235
	} else if (cstring_equal(option, "split")) {
221
	    c_out_info_set_split (c_out_info, (unsigned) 5000);
236
	    c_out_info_set_split(c_out_info, (unsigned)5000);
222
	} else if (cstring_starts (option, "split=")) {
237
	} else if (cstring_starts(option, "split=")) {
223
	    unsigned limit;
238
	    unsigned limit;
224
	    if (!cstring_to_unsigned (option + 6, &limit)) {
239
	    if (!cstring_to_unsigned(option + 6, &limit)) {
225
		E_bad_split_size (option + 6);
240
		E_bad_split_size(option + 6);
226
		UNREACHED;
241
		UNREACHED;
227
	    }
242
	    }
228
	    c_out_info_set_split (c_out_info, limit);
243
	    c_out_info_set_split(c_out_info, limit);
229
	} else if (cstring_equal (option, "no-split")) {
244
	} else if (cstring_equal(option, "no-split")) {
230
	    c_out_info_set_split (c_out_info, (unsigned) 0);
245
	    c_out_info_set_split(c_out_info, (unsigned)0);
231
	} else if (cstring_equal (option, "numeric-ids") ||
246
	} else if (cstring_equal(option, "numeric-ids") ||
232
		   cstring_equal (option, "numeric")) {
247
		   cstring_equal(option, "numeric")) {
233
	    c_out_info_set_numeric_ids (c_out_info, TRUE);
248
	    c_out_info_set_numeric_ids(c_out_info, TRUE);
234
	} else if (cstring_equal (option, "no-numeric-ids") ||
249
	} else if (cstring_equal(option, "no-numeric-ids") ||
235
		   cstring_equal (option, "no-numeric")) {
250
		   cstring_equal(option, "no-numeric")) {
236
	    c_out_info_set_numeric_ids (c_out_info, FALSE);
251
	    c_out_info_set_numeric_ids(c_out_info, FALSE);
237
	} else if (cstring_equal (option, "casts") ||
252
	} else if (cstring_equal(option, "casts") ||
238
		   cstring_equal (option, "cast")) {
253
		   cstring_equal(option, "cast")) {
239
	    c_out_info_set_casts (c_out_info, TRUE);
254
	    c_out_info_set_casts(c_out_info, TRUE);
240
	} else if (cstring_equal (option, "no-casts") ||
255
	} else if (cstring_equal(option, "no-casts") ||
241
		   cstring_equal (option, "no-cast")) {
256
		   cstring_equal(option, "no-cast")) {
242
	    c_out_info_set_casts (c_out_info, FALSE);
257
	    c_out_info_set_casts(c_out_info, FALSE);
243
	} else if (cstring_equal (option, "unreachable-macros") ||
258
	} else if (cstring_equal(option, "unreachable-macros") ||
244
		   cstring_equal (option, "unreachable-macro")) {
259
		   cstring_equal(option, "unreachable-macro")) {
245
	    c_out_info_set_unreachable (c_out_info, TRUE);
260
	    c_out_info_set_unreachable(c_out_info, TRUE);
246
	} else if (cstring_equal (option, "unreachable-comments") ||
261
	} else if (cstring_equal(option, "unreachable-comments") ||
247
		   cstring_equal (option, "unreachable-comment")) {
262
		   cstring_equal(option, "unreachable-comment")) {
248
	    c_out_info_set_unreachable (c_out_info, FALSE);
263
	    c_out_info_set_unreachable(c_out_info, FALSE);
249
	} else if (cstring_equal (option, "lines") ||
264
	} else if (cstring_equal(option, "lines") ||
250
		   cstring_equal (option, "line")) {
265
		   cstring_equal(option, "line")) {
251
	    c_out_info_set_lines (c_out_info, TRUE);
266
	    c_out_info_set_lines(c_out_info, TRUE);
252
	} else if (cstring_equal (option, "no-lines") ||
267
	} else if (cstring_equal(option, "no-lines") ||
253
		   cstring_equal (option, "no-line")) {
268
		   cstring_equal(option, "no-line")) {
254
	    c_out_info_set_lines (c_out_info, FALSE);
269
	    c_out_info_set_lines(c_out_info, FALSE);
255
	} else {
270
	} else {
256
	    CStringP lang ;
271
	    CStringP lang;
257
	    lang = (ossg ? "ossg-c" : (ansi ? "ansi-c" : "pre-ansi-c"));
272
	    lang = (ansi ? "ansi-c" : "pre-ansi-c");
258
	    E_bad_language_option (lang, option);
273
	    E_bad_language_option(lang, option);
259
	}
274
	}
260
    }
275
    }
261
    return ((GenericP) c_out_info);
276
    return((GenericP)c_out_info);
262
}
-
 
263
 
-
 
264
static GenericP
-
 
265
main_init_ansi_c PROTO_N ((out_info, options))
-
 
266
		 PROTO_T (OutputInfoP  out_info X
-
 
267
			  CStringListP options)
-
 
268
{
-
 
269
    return (main_init_c (out_info, options, TRUE, FALSE));
-
 
270
}
277
}
271
 
278
 
272
static GenericP
279
static GenericP
273
main_init_pre_ansi_c PROTO_N ((out_info, options))
280
main_init_ansi_c(OutputInfoP out_info, CStringListP options)
274
		     PROTO_T (OutputInfoP  out_info X
-
 
275
			      CStringListP options)
-
 
276
{
281
{
277
    return (main_init_c (out_info, options, FALSE, FALSE));
282
    return(main_init_c(out_info, options, TRUE));
278
}
283
}
279
 
284
 
280
static GenericP
285
static GenericP
281
main_init_ossg_c PROTO_N ((out_info, options))
286
main_init_pre_ansi_c(OutputInfoP out_info, CStringListP options)
282
		 PROTO_T (OutputInfoP  out_info X
-
 
283
			  CStringListP options)
-
 
284
{
287
{
285
    return (main_init_c (out_info, options, TRUE, TRUE));
288
    return(main_init_c(out_info, options, FALSE));
286
}
289
}
287
 
290
 
288
static void
291
static void
289
main_input_c PROTO_N ((gclosure, grammar))
292
main_input_c(GenericP gclosure, GrammarP grammar)
290
	     PROTO_T (GenericP gclosure X
-
 
291
		      GrammarP grammar)
-
 
292
{
293
{
293
    COutputInfoP  c_out_info = (COutputInfoP) gclosure;
294
    COutputInfoP  c_out_info = (COutputInfoP)gclosure;
294
    OutputInfoP   out_info   = c_out_info_info (c_out_info);
295
    OutputInfoP   out_info   = c_out_info_info(c_out_info);
295
    CLexerStreamT clstream;
296
    CLexerStreamT clstream;
296
 
297
 
297
    c_lexer_init (&clstream, out_info_get_istream (out_info, (unsigned) 1));
298
    c_lexer_init(&clstream, out_info_get_istream(out_info, (unsigned)1));
298
    c_current_stream   = &clstream;
299
    c_current_stream   = &clstream;
299
    c_current_out_info = c_out_info;
300
    c_current_out_info = c_out_info;
300
    c_current_table    = grammar_table (grammar);
301
    c_current_table    = grammar_table(grammar);
301
    c_parse_grammar ();
302
    c_parse_grammar();
302
    c_lexer_close (&clstream);
303
    c_lexer_close(&clstream);
303
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
304
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
304
	exit (EXIT_FAILURE);
305
	exit(EXIT_FAILURE);
305
	UNREACHED;
306
	UNREACHED;
306
    }
307
    }
307
    c_check_grammar (grammar);
308
    c_check_grammar(grammar);
308
}
309
}
309
 
310
 
310
static void
311
static void
311
main_output_c PROTO_N ((gclosure, grammar))
312
main_output_c(GenericP gclosure, GrammarP grammar)
312
	      PROTO_T (GenericP gclosure X
-
 
313
		       GrammarP grammar)
-
 
314
{
313
{
315
    COutputInfoP c_out_info = (COutputInfoP) gclosure;
314
    COutputInfoP c_out_info = (COutputInfoP)gclosure;
316
 
315
 
317
    grammar_compute_mutations (grammar);
316
    grammar_compute_mutations(grammar);
318
    out_info_set_current_ostream (c_out_info_info (c_out_info), (unsigned) 0);
317
    out_info_set_current_ostream(c_out_info_info(c_out_info), (unsigned)0);
319
    c_output_parser (c_out_info, grammar);
318
    c_output_parser(c_out_info, grammar);
320
    out_info_set_current_ostream (c_out_info_info (c_out_info), (unsigned) 1);
319
    out_info_set_current_ostream(c_out_info_info(c_out_info), (unsigned)1);
321
    c_output_header (c_out_info, grammar);
320
    c_output_header(c_out_info, grammar);
322
}
321
}
323
 
322
 
324
static GenericP
323
static GenericP
325
main_init_test PROTO_N ((info, options))
324
main_init_test(OutputInfoP info, CStringListP options)
326
	       PROTO_T (OutputInfoP  info X
-
 
327
			CStringListP options)
-
 
328
{
325
{
329
    CStringListEntryP entry;
326
    CStringListEntryP entry;
330
 
327
 
331
    UNUSED (info);
328
    UNUSED(info);
332
    for (entry = cstring_list_head (options); entry;
329
    for (entry = cstring_list_head(options); entry;
333
	 entry = cstring_list_entry_deallocate (entry)) {
330
	 entry = cstring_list_entry_deallocate(entry)) {
334
	CStringP option = cstring_list_entry_string (entry);
331
	CStringP option = cstring_list_entry_string(entry);
335
 
332
 
336
	E_bad_language_option ("test", option);
333
	E_bad_language_option("test", option);
337
    }
334
    }
338
    return (NIL (GenericP));
335
    return(NIL(GenericP));
339
}
336
}
340
 
337
 
341
static void
338
static void
342
main_input_test PROTO_N ((gclosure, grammar))
339
main_input_test(GenericP gclosure, GrammarP grammar)
343
		PROTO_T (GenericP gclosure X
-
 
344
			 GrammarP grammar)
-
 
345
{
340
{
346
    UNUSED (gclosure);
341
    UNUSED(gclosure);
347
    UNUSED (grammar);
342
    UNUSED(grammar);
348
}
343
}
349
 
344
 
350
static void
345
static void
351
main_output_test PROTO_N ((gclosure, grammar))
346
main_output_test(GenericP gclosure, GrammarP grammar)
352
		 PROTO_T (GenericP gclosure X
-
 
353
			  GrammarP grammar)
-
 
354
{
347
{
355
    UNUSED (gclosure);
348
    UNUSED(gclosure);
356
    UNUSED (grammar);
349
    UNUSED(grammar);
357
}
350
}
358
 
351
 
359
/*--------------------------------------------------------------------------*/
352
/*--------------------------------------------------------------------------*/
360
 
353
 
361
static BoolT main_did_one_off = FALSE;
354
static BoolT main_did_one_off = FALSE;
Line 365... Line 358...
365
 
358
 
366
static CStringListT main_language_options;
359
static CStringListT main_language_options;
367
 
360
 
368
static OStreamT dump_stream;
361
static OStreamT dump_stream;
369
 
362
 
370
static PhaseListT  main_phase_list [] = {
363
static PhaseListT  main_phase_list[] = {
371
    {"singles", rule_set_inline_singles},
364
    {"singles", rule_set_inline_singles},
372
    {"tail", rule_set_inline_tail_calls},
365
    {"tail", rule_set_inline_tail_calls},
373
    {"basics", rule_set_inline_all_basics},
366
    {"basics", rule_set_inline_all_basics},
374
    {"other", rule_set_inline_non_tail_calls},
367
    {"other", rule_set_inline_non_tail_calls},
375
    {"multi", rule_set_multiple_inlining},
368
    {"multi", rule_set_multiple_inlining},
376
    {"all", main_handle_phase_all},
369
    {"all", main_handle_phase_all},
377
    {NIL (CStringP), NIL (void (*) PROTO_S ((BoolT)))}
370
    {NIL(CStringP), NIL(void(*)(BoolT))}
378
};
371
};
379
 
372
 
380
static LangListT main_language_list [] = {
373
static LangListT main_language_list[] = {
381
    {"ansi-c", main_init_ansi_c, main_input_c, 2, main_output_c, 2},
374
    {"ansi-c", main_init_ansi_c, main_input_c, 2, main_output_c, 2},
382
    {"pre-ansi-c", main_init_pre_ansi_c, main_input_c, 2, main_output_c, 2},
375
    {"pre-ansi-c", main_init_pre_ansi_c, main_input_c, 2, main_output_c, 2},
383
    {"iso-c", main_init_ansi_c, main_input_c, 2, main_output_c, 2},
376
    {"iso-c", main_init_ansi_c, main_input_c, 2, main_output_c, 2},
384
    {"pre-iso-c", main_init_pre_ansi_c, main_input_c, 2, main_output_c, 2},
377
    {"pre-iso-c", main_init_pre_ansi_c, main_input_c, 2, main_output_c, 2},
385
    {"ossg-c", main_init_ossg_c, main_input_c, 2, main_output_c, 2},
-
 
386
    {"test", main_init_test, main_input_test, 1, main_output_test, 0},
378
    {"test", main_init_test, main_input_test, 1, main_output_test, 0},
387
    {NIL (CStringP), NIL (GenericP (*) PROTO_S ((OutputInfoP, CStringListP))),
379
    {NIL(CStringP), NIL(GenericP(*)(OutputInfoP, CStringListP)),
388
     NIL (void (*) PROTO_S ((GenericP, GrammarP))), 0,
380
     NIL(void(*)(GenericP, GrammarP)), 0,
389
     NIL (void (*) PROTO_S ((GenericP, GrammarP))), 0}
381
     NIL(void(*)(GenericP, GrammarP)), 0}
390
};
382
};
391
 
383
 
392
static LangListP main_language = &(main_language_list [0]);
384
static LangListP main_language = &(main_language_list[0]);
393
 
385
 
394
/*--------------------------------------------------------------------------*/
386
/*--------------------------------------------------------------------------*/
395
 
387
 
396
static void
388
static void
397
main_handle_dump_file PROTO_N ((option, usage, gclosure, dump_file))
389
main_handle_dump_file(CStringP option, ArgUsageP usage, GenericP gclosure,
398
		      PROTO_T (CStringP  option X
-
 
399
			       ArgUsageP usage X
-
 
400
			       GenericP  gclosure X
-
 
401
			       CStringP  dump_file)
390
		      CStringP dump_file)
402
{
391
{
403
    UNUSED (option);
392
    UNUSED(option);
404
    UNUSED (usage);
393
    UNUSED(usage);
405
    UNUSED (gclosure);
394
    UNUSED(gclosure);
406
    main_did_other = TRUE;
395
    main_did_other = TRUE;
407
    if (ostream_is_open (&dump_stream)) {
396
    if (ostream_is_open(&dump_stream)) {
408
	E_multiple_dump_files ();
397
	E_multiple_dump_files();
409
	UNREACHED;
398
	UNREACHED;
410
    } else if (!ostream_open (&dump_stream, dump_file)) {
399
    } else if (!ostream_open(&dump_stream, dump_file)) {
411
	E_cannot_open_dump_file (dump_file);
400
	E_cannot_open_dump_file(dump_file);
412
	UNREACHED;
401
	UNREACHED;
413
    }
402
    }
414
}
403
}
415
 
404
 
416
static void
405
static void
417
main_handle_help PROTO_N ((option, usage, gclosure))
406
main_handle_help(CStringP option, ArgUsageP usage, GenericP gclosure)
418
		 PROTO_T (CStringP  option X
-
 
419
			  ArgUsageP usage X
-
 
420
			  GenericP  gclosure)
-
 
421
{
407
{
422
    UNUSED (option);
408
    UNUSED(option);
423
    UNUSED (gclosure);
409
    UNUSED(gclosure);
424
    main_did_one_off = TRUE;
410
    main_did_one_off = TRUE;
425
    write_arg_usage (ostream_error, usage);
411
    write_arg_usage(ostream_error, usage);
426
    write_newline (ostream_error);
412
    write_newline(ostream_error);
427
    ostream_flush (ostream_error);
413
    ostream_flush(ostream_error);
428
}
414
}
429
 
415
 
430
static void
416
static void
431
main_handle_factor_limit PROTO_N ((option, usage, gclosure, limit_str))
417
main_handle_factor_limit(CStringP option, ArgUsageP usage, GenericP gclosure,
432
			 PROTO_T (CStringP  option X
-
 
433
				  ArgUsageP usage X
-
 
434
				  GenericP  gclosure X
-
 
435
				  CStringP  limit_str)
418
			 CStringP limit_str)
436
{
419
{
437
    unsigned limit;
420
    unsigned limit;
438
 
421
 
439
    UNUSED (option);
422
    UNUSED(option);
440
    UNUSED (usage);
423
    UNUSED(usage);
441
    UNUSED (gclosure);
424
    UNUSED(gclosure);
442
    main_did_other = TRUE;
425
    main_did_other = TRUE;
443
    if ((!cstring_to_unsigned (limit_str, &limit)) || (limit == 0)) {
426
    if ((!cstring_to_unsigned(limit_str, &limit)) || (limit == 0)) {
444
	E_bad_factor_limit (limit_str);
427
	E_bad_factor_limit(limit_str);
445
	UNREACHED;
428
	UNREACHED;
446
    }
429
    }
447
    rule_set_factor_limit (limit);
430
    rule_set_factor_limit(limit);
448
}
431
}
449
 
432
 
450
static void
433
static void
451
main_handle_inlining PROTO_N ((option, usage, gclosure, inline_str))
434
main_handle_inlining(CStringP option, ArgUsageP usage, GenericP gclosure,
452
		     PROTO_T (CStringP  option X
-
 
453
			      ArgUsageP usage X
-
 
454
			      GenericP  gclosure X
-
 
455
			      CStringP  inline_str)
435
		     CStringP inline_str)
456
{
436
{
457
    UNUSED (option);
437
    UNUSED(option);
458
    UNUSED (usage);
438
    UNUSED(usage);
459
    UNUSED (gclosure);
439
    UNUSED(gclosure);
460
    main_did_other = TRUE;
440
    main_did_other = TRUE;
461
    while (*inline_str) {
441
    while (*inline_str) {
462
	BoolT      enable = TRUE;
442
	BoolT      enable = TRUE;
463
	DStringT   dstring;
443
	DStringT   dstring;
464
	CStringP   phase;
444
	CStringP   phase;
465
	PhaseListP entry;
445
	PhaseListP entry;
466
 
446
 
467
	if ((syntax_downcase (inline_str [0]) == 'n') &&
447
	if ((syntax_downcase(inline_str[0]) == 'n') &&
468
	    (syntax_downcase (inline_str [1]) == 'o')) {
448
	   (syntax_downcase(inline_str[1]) == 'o')) {
469
	    inline_str += 2;
449
	    inline_str += 2;
470
	    enable = FALSE;
450
	    enable = FALSE;
471
	}
451
	}
472
	dstring_init (&dstring);
452
	dstring_init(&dstring);
473
	while ((*inline_str) && (*inline_str != ',')) {
453
	while ((*inline_str) && (*inline_str != ',')) {
474
	    dstring_append_char (&dstring, syntax_downcase (*inline_str ++));
454
	    dstring_append_char(&dstring, syntax_downcase(*inline_str++));
475
	}
455
	}
476
	if (*inline_str == ',') {
456
	if (*inline_str == ',') {
477
	    inline_str ++;
457
	    inline_str++;
478
	}
458
	}
479
	phase = dstring_destroy_to_cstring (&dstring);
459
	phase = dstring_destroy_to_cstring(&dstring);
480
	for (entry = main_phase_list; entry->phase; entry ++) {
460
	for (entry = main_phase_list; entry->phase; entry++) {
481
	    if (cstring_equal (phase, entry->phase)) {
461
	    if (cstring_equal(phase, entry->phase)) {
482
		if (entry->proc) {
462
		if (entry->proc) {
483
		    (*(entry->proc)) (enable);
463
		   (*(entry->proc))(enable);
484
		}
464
		}
485
		goto next;
465
		goto next;
486
	    }
466
	    }
487
	}
467
	}
488
	E_bad_inlining_phase (phase);
468
	E_bad_inlining_phase(phase);
489
	UNREACHED;
469
	UNREACHED;
490
      next:;
470
      next:;
491
    }
471
    }
492
}
472
}
493
 
473
 
494
static void
474
static void
495
main_handle_language PROTO_N ((option, usage, gclosure, language_str))
475
main_handle_language(CStringP option, ArgUsageP usage, GenericP gclosure,
496
		     PROTO_T (CStringP  option X
-
 
497
			      ArgUsageP usage X
-
 
498
			      GenericP  gclosure X
-
 
499
			      CStringP  language_str)
476
		     CStringP language_str)
500
{
477
{
501
    LangListP entry;
478
    LangListP entry;
502
 
479
 
503
    UNUSED (option);
480
    UNUSED(option);
504
    UNUSED (usage);
481
    UNUSED(usage);
505
    UNUSED (gclosure);
482
    UNUSED(gclosure);
506
    main_did_other = TRUE;
483
    main_did_other = TRUE;
507
    for (entry = main_language_list; entry->language; entry ++) {
484
    for (entry = main_language_list; entry->language; entry++) {
508
	if (cstring_equal (language_str, entry->language)) {
485
	if (cstring_equal(language_str, entry->language)) {
509
	    main_language = entry;
486
	    main_language = entry;
510
	    return;
487
	    return;
511
	}
488
	}
512
    }
489
    }
513
    E_bad_language (language_str);
490
    E_bad_language(language_str);
514
    UNREACHED;
491
    UNREACHED;
515
}
492
}
516
 
493
 
517
static void
494
static void
518
main_handle_show_errors PROTO_N ((option, usage, gclosure))
495
main_handle_show_errors(CStringP option, ArgUsageP usage, GenericP gclosure)
519
			PROTO_T (CStringP  option X
-
 
520
				 ArgUsageP usage X
-
 
521
				 GenericP  gclosure)
-
 
522
{
496
{
523
    UNUSED (option);
497
    UNUSED(option);
524
    UNUSED (usage);
498
    UNUSED(usage);
525
    UNUSED (gclosure);
499
    UNUSED(gclosure);
526
    main_did_one_off = TRUE;
500
    main_did_one_off = TRUE;
527
    write_error_file (ostream_output);
501
    write_error_file(ostream_output);
528
    ostream_flush (ostream_output);
502
    ostream_flush(ostream_output);
529
}
503
}
530
 
504
 
531
static void
505
static void
532
main_handle_switch PROTO_N ((option, usage, gclosure, opt))
506
main_handle_switch(CStringP option, ArgUsageP usage, GenericP gclosure,
533
		   PROTO_T (CStringP  option X
-
 
534
			    ArgUsageP usage X
-
 
535
			    GenericP  gclosure X
-
 
536
			    CStringP  opt)
507
		   CStringP opt)
537
{
508
{
538
    UNUSED (option);
509
    UNUSED(option);
539
    UNUSED (usage);
510
    UNUSED(usage);
540
    UNUSED (gclosure);
511
    UNUSED(gclosure);
541
    main_did_other = TRUE;
512
    main_did_other = TRUE;
542
    cstring_list_append (&main_language_options, opt);
513
    cstring_list_append(&main_language_options, opt);
543
}
514
}
544
 
515
 
545
static void
516
static void
546
main_handle_tab_width PROTO_N ((option, usage, gclosure, width_str))
517
main_handle_tab_width(CStringP option, ArgUsageP usage, GenericP gclosure,
547
		      PROTO_T (CStringP  option X
-
 
548
			       ArgUsageP usage X
-
 
549
			       GenericP  gclosure X
-
 
550
			       CStringP  width_str)
518
		      CStringP width_str)
551
{
519
{
552
    unsigned width;
520
    unsigned width;
553
 
521
 
554
    UNUSED (option);
522
    UNUSED(option);
555
    UNUSED (usage);
523
    UNUSED(usage);
556
    UNUSED (gclosure);
524
    UNUSED(gclosure);
557
    main_did_other = TRUE;
525
    main_did_other = TRUE;
558
    if ((!cstring_to_unsigned (width_str, &width)) || (width == 0)) {
526
    if ((!cstring_to_unsigned(width_str, &width)) || (width == 0)) {
559
	E_bad_tab_width (width_str);
527
	E_bad_tab_width(width_str);
560
	UNREACHED;
528
	UNREACHED;
561
    }
529
    }
562
    out_info_set_tab_width (main_info_closure, width);
530
    out_info_set_tab_width(main_info_closure, width);
563
}
531
}
564
 
532
 
565
static void
533
static void
566
main_handle_version PROTO_N ((option, usage, gclosure))
534
main_handle_version(CStringP option, ArgUsageP usage, GenericP gclosure)
567
		    PROTO_T (CStringP  option X
-
 
568
			     ArgUsageP usage X
-
 
569
			     GenericP  gclosure)
-
 
570
{
535
{
571
    UNUSED (option);
536
    UNUSED(option);
572
    UNUSED (usage);
537
    UNUSED(usage);
573
    UNUSED (gclosure);
538
    UNUSED(gclosure);
574
    main_did_one_off = TRUE;
539
    main_did_one_off = TRUE;
575
    write_cstring (ostream_error, VERSION);
540
    write_cstring(ostream_error, VERSION);
576
    write_cstring (ostream_error, " (Release ");
541
    write_cstring(ostream_error, " (Release ");
577
    write_cstring (ostream_error, RELEASE);
542
    write_cstring(ostream_error, RELEASE);
578
    write_cstring (ostream_error, ")");
543
    write_cstring(ostream_error, ")");
579
    write_cstring (ostream_error, BANNER);
544
    write_cstring(ostream_error, BANNER);
580
    write_newline (ostream_error);
545
    write_newline(ostream_error);
581
    ostream_flush (ostream_error);
546
    ostream_flush(ostream_error);
582
}
547
}
583
 
548
 
584
/*--------------------------------------------------------------------------*/
549
/*--------------------------------------------------------------------------*/
585
 
550
 
586
static EStringDataT main_description_strings [] = {
551
static EStringDataT main_description_strings[] = {
587
    UB {
552
    UB {
588
	"description of dump-file",
553
	"description of dump-file",
589
	" FILE\n\tCause intermediate grammars to be written to FILE."
554
	" FILE\n\tCause intermediate grammars to be written to FILE."
590
    } UE, UB {
555
    } UE, UB {
591
	"description of help",
556
	"description of help",
Line 618... Line 583...
618
/* Some conversions to ArgProcP are slightly suspect */
583
/* Some conversions to ArgProcP are slightly suspect */
619
#pragma TenDRA begin
584
#pragma TenDRA begin
620
#pragma TenDRA conversion analysis (pointer-pointer) off
585
#pragma TenDRA conversion analysis (pointer-pointer) off
621
#endif
586
#endif
622
 
587
 
623
static ArgListT main_arglist [] = {
588
static ArgListT main_arglist[] = {
624
    {
589
    {
625
	"dump-file", 'd',			AT_FOLLOWING,
590
	"dump-file", 'd',			AT_FOLLOWING,
626
	(ArgProcP) main_handle_dump_file,	NIL (GenericP),
591
	(ArgProcP)main_handle_dump_file,	NIL(GenericP),
627
	UB "description of dump-file" UE
592
	UB "description of dump-file" UE
628
    }, {
593
    }, {
629
        "factor-limit", 'f',			AT_FOLLOWING,
594
        "factor-limit", 'f',			AT_FOLLOWING,
630
	(ArgProcP) main_handle_factor_limit,	NIL (GenericP),
595
	(ArgProcP)main_handle_factor_limit,	NIL(GenericP),
631
	UB "description of factor-limit" UE
596
	UB "description of factor-limit" UE
632
    }, {
597
    }, {
633
	"help", '?',				AT_EMPTY,
598
	"help", '?',				AT_EMPTY,
634
	(ArgProcP) main_handle_help,		NIL (GenericP),
599
	(ArgProcP)main_handle_help,		NIL(GenericP),
635
	UB "description of help" UE
600
	UB "description of help" UE
636
    }, {
601
    }, {
637
	"inline", 'i',				AT_FOLLOWING,
602
	"inline", 'i',				AT_FOLLOWING,
638
	(ArgProcP) main_handle_inlining,	NIL (GenericP),
603
	(ArgProcP)main_handle_inlining,	NIL(GenericP),
639
	UB "description of inlining" UE
604
	UB "description of inlining" UE
640
    }, {
605
    }, {
641
	"language", 'l',			AT_FOLLOWING,
606
	"language", 'l',			AT_FOLLOWING,
642
	(ArgProcP) main_handle_language,	NIL (GenericP),
607
	(ArgProcP)main_handle_language,	NIL(GenericP),
643
	UB "description of language" UE
608
	UB "description of language" UE
644
    }, {
609
    }, {
645
	"show-errors", 'e',			AT_EMPTY,
610
	"show-errors", 'e',			AT_EMPTY,
646
	(ArgProcP) main_handle_show_errors,	NIL (GenericP),
611
	(ArgProcP)main_handle_show_errors,	NIL(GenericP),
647
	UB "description of show-errors" UE
612
	UB "description of show-errors" UE
648
    }, {
613
    }, {
649
	"switch", 's',				AT_FOLLOWING,
614
	"switch", 's',				AT_FOLLOWING,
650
	(ArgProcP) main_handle_switch,		NIL (GenericP),
615
	(ArgProcP)main_handle_switch,		NIL(GenericP),
651
	UB "description of switch" UE
616
	UB "description of switch" UE
652
    }, {
617
    }, {
653
	"tab-width", 't',			AT_FOLLOWING,
618
	"tab-width", 't',			AT_FOLLOWING,
654
	(ArgProcP) main_handle_tab_width,	NIL (GenericP),
619
	(ArgProcP)main_handle_tab_width,	NIL(GenericP),
655
	UB "description of tab-width" UE
620
	UB "description of tab-width" UE
656
    }, {
621
    }, {
657
	"version", 'v',				AT_EMPTY,
622
	"version", 'v',				AT_EMPTY,
658
	(ArgProcP) main_handle_version,		NIL (GenericP),
623
	(ArgProcP)main_handle_version,		NIL(GenericP),
659
	UB "description of version" UE
624
	UB "description of version" UE
660
    }, ARG_PARSE_END_LIST
625
    }, ARG_PARSE_END_LIST
661
};
626
};
662
 
627
 
663
#ifdef __TenDRA__
628
#ifdef __TenDRA__
Line 665... Line 630...
665
#endif
630
#endif
666
 
631
 
667
/*--------------------------------------------------------------------------*/
632
/*--------------------------------------------------------------------------*/
668
 
633
 
669
static void
634
static void
670
main_init PROTO_N ((argc, argv, out_info))
635
main_init(int argc, char **argv, OutputInfoP out_info)
671
	  PROTO_T (int         argc X
-
 
672
		   char      **argv X
-
 
673
		   OutputInfoP out_info)
-
 
674
{
636
{
675
    EStringP  usage_estring = error_define_string ("sid usage message", USAGE);
637
    EStringP  usage_estring = error_define_string("sid usage message", USAGE);
676
    ArgUsageT closure;
638
    ArgUsageT closure;
677
    CStringP  error_file;
639
    CStringP  error_file;
678
    int       skip;
640
    int       skip;
679
    unsigned  i;
641
    unsigned  i;
680
    unsigned  num_infiles;
642
    unsigned  num_infiles;
681
    unsigned  num_outfiles;
643
    unsigned  num_outfiles;
682
 
644
 
683
    error_init (argv [0], gen_errors_init_errors);
645
    error_init(argv[0], gen_errors_init_errors);
684
    error_intern_strings (main_description_strings);
646
    error_intern_strings(main_description_strings);
685
    if ((error_file = getenv ("SID_ERROR_FILE")) != NIL (CStringP)) {
647
    if ((error_file = getenv("SID_ERROR_FILE")) != NIL(CStringP)) {
686
	error_file_parse (error_file, FALSE);
648
	error_file_parse(error_file, FALSE);
687
    }
649
    }
688
    closure.usage     = error_string_contents (usage_estring);
650
    closure.usage     = error_string_contents(usage_estring);
689
    closure.arg_list  = main_arglist;
651
    closure.arg_list  = main_arglist;
690
    main_info_closure = out_info;
652
    main_info_closure = out_info;
691
    arg_parse_intern_descriptions (main_arglist);
653
    arg_parse_intern_descriptions(main_arglist);
692
    skip = arg_parse_arguments (main_arglist, usage_estring, -- argc, ++ argv);
654
    skip = arg_parse_arguments(main_arglist, usage_estring, --argc, ++argv);
693
    argc -= skip;
655
    argc -= skip;
694
    argv += skip;
656
    argv += skip;
695
    if (main_did_one_off && (!main_did_other) && (argc == 0)) {
657
    if (main_did_one_off && (!main_did_other) && (argc == 0)) {
696
	exit (EXIT_SUCCESS);
658
	exit(EXIT_SUCCESS);
697
	UNREACHED;
659
	UNREACHED;
698
    }
660
    }
699
    num_infiles  = main_language->num_input_files;
661
    num_infiles  = main_language->num_input_files;
700
    num_outfiles = main_language->num_output_files;
662
    num_outfiles = main_language->num_output_files;
701
    if ((unsigned) argc != (num_infiles + num_outfiles)) {
663
    if ((unsigned)argc != (num_infiles + num_outfiles)) {
702
	E_usage (main_language->language, num_infiles, num_outfiles, &closure);
664
	E_usage(main_language->language, num_infiles, num_outfiles, &closure);
703
	UNREACHED;
665
	UNREACHED;
704
    }
666
    }
705
    out_info_set_num_input_files (out_info, num_infiles);
667
    out_info_set_num_input_files(out_info, num_infiles);
706
    out_info_set_num_output_files (out_info, num_outfiles);
668
    out_info_set_num_output_files(out_info, num_outfiles);
707
    for (i = 0; i < num_infiles; i ++) {
669
    for (i = 0; i < num_infiles; i++) {
708
	CStringP  name = argv [i];
670
	CStringP  name = argv[i];
709
	if (!istream_open (out_info_get_istream (out_info, i), name)) {
671
	if (!istream_open(out_info_get_istream(out_info, i), name)) {
710
	    E_cannot_open_input_file (name);
672
	    E_cannot_open_input_file(name);
711
	    UNREACHED;
673
	    UNREACHED;
712
	}
674
	}
713
	out_info_set_infile_name (out_info, i, name);
675
	out_info_set_infile_name(out_info, i, name);
714
    }
676
    }
715
    for (i = 0; i < num_outfiles; i ++) {
677
    for (i = 0; i < num_outfiles; i++) {
716
	CStringP  name = argv [num_infiles + i];
678
	CStringP  name = argv[num_infiles + i];
717
	if (!ostream_open (out_info_get_ostream (out_info, i), name)) {
679
	if (!ostream_open(out_info_get_ostream(out_info, i), name)) {
718
	    E_cannot_open_output_file (name);
680
	    E_cannot_open_output_file(name);
719
	    UNREACHED;
681
	    UNREACHED;
720
	}
682
	}
721
	out_info_set_outfile_name (out_info, i, name);
683
	out_info_set_outfile_name(out_info, i, name);
722
    }
684
    }
723
}
685
}
724
 
686
 
725
static void
687
static void
726
main_dump_grammar PROTO_N ((dstream, grammar, mesg))
688
main_dump_grammar(OStreamP dstream, GrammarP grammar, CStringP mesg)
727
		  PROTO_T (OStreamP dstream X
-
 
728
			   GrammarP grammar X
-
 
729
			   CStringP mesg)
-
 
730
{
689
{
731
    if (dstream) {
690
    if (dstream) {
732
	write_cstring (dstream, mesg);
691
	write_cstring(dstream, mesg);
733
	write_newline (dstream);
692
	write_newline(dstream);
734
	write_newline (dstream);
693
	write_newline(dstream);
735
	write_grammar (dstream, grammar);
694
	write_grammar(dstream, grammar);
736
    }
695
    }
737
}
696
}
738
 
697
 
739
static void
698
static void
740
main_abort_if_errored PROTO_Z ()
699
main_abort_if_errored(void)
741
{
700
{
742
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
701
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
743
	exit (EXIT_FAILURE);
702
	exit(EXIT_FAILURE);
744
	UNREACHED;
703
	UNREACHED;
745
    }
704
    }
746
}
705
}
747
 
706
 
748
static void
707
static void
749
main_1 PROTO_N ((out_info, dstream))
708
main_1(OutputInfoP out_info, OStreamP dstream)
750
       PROTO_T (OutputInfoP out_info X
-
 
751
		OStreamP    dstream)
-
 
752
{
709
{
753
    LexerStreamT lstream;
710
    LexerStreamT lstream;
754
    GrammarT     grammar;
711
    GrammarT     grammar;
755
    GenericP     output_closure;
712
    GenericP     output_closure;
756
 
713
 
757
    output_closure = (*(main_language->init_proc)) (out_info,
714
    output_closure = (*(main_language->init_proc))(out_info,
758
						    &main_language_options);
715
						   &main_language_options);
759
    grammar_init (&grammar);
716
    grammar_init(&grammar);
760
    lexer_init (&lstream, out_info_get_istream (out_info, (unsigned) 0));
717
    lexer_init(&lstream, out_info_get_istream(out_info, (unsigned)0));
761
    sid_current_stream  = &lstream;
718
    sid_current_stream  = &lstream;
762
    sid_current_grammar = &grammar;
719
    sid_current_grammar = &grammar;
763
    sid_parse_grammar ();
720
    sid_parse_grammar();
764
    lexer_close (&lstream);
721
    lexer_close(&lstream);
765
    main_abort_if_errored ();
722
    main_abort_if_errored();
766
    grammar_check_complete (&grammar);
723
    grammar_check_complete(&grammar);
767
    main_abort_if_errored ();
724
    main_abort_if_errored();
768
    (*(main_language->input_proc)) (output_closure, &grammar);
725
   (*(main_language->input_proc))(output_closure, &grammar);
769
    main_abort_if_errored ();
726
    main_abort_if_errored();
770
    main_dump_grammar (dstream, &grammar, "Original grammar:");
727
    main_dump_grammar(dstream, &grammar, "Original grammar:");
771
    grammar_remove_left_recursion (&grammar);
728
    grammar_remove_left_recursion(&grammar);
772
    main_dump_grammar (dstream, &grammar, "After left recursion elimination:");
729
    main_dump_grammar(dstream, &grammar, "After left recursion elimination:");
773
    main_abort_if_errored ();
730
    main_abort_if_errored();
774
    grammar_compute_first_sets (&grammar);
731
    grammar_compute_first_sets(&grammar);
775
    main_abort_if_errored ();
732
    main_abort_if_errored();
776
    grammar_factor (&grammar);
733
    grammar_factor(&grammar);
777
    main_dump_grammar (dstream, &grammar, "After factorisation:");
734
    main_dump_grammar(dstream, &grammar, "After factorisation:");
778
    main_abort_if_errored ();
735
    main_abort_if_errored();
779
    grammar_simplify (&grammar);
736
    grammar_simplify(&grammar);
780
    main_dump_grammar (dstream, &grammar, "After simplification:");
737
    main_dump_grammar(dstream, &grammar, "After simplification:");
781
    grammar_compute_inlining (&grammar);
738
    grammar_compute_inlining(&grammar);
782
    grammar_check_collisions (&grammar);
739
    grammar_check_collisions(&grammar);
783
    main_dump_grammar (dstream, &grammar, "After everything:");
740
    main_dump_grammar(dstream, &grammar, "After everything:");
784
    main_abort_if_errored ();
741
    main_abort_if_errored();
785
    grammar_recompute_alt_names (&grammar);
742
    grammar_recompute_alt_names(&grammar);
786
    if (dstream) {
743
    if (dstream) {
787
	ostream_close (dstream);
744
	ostream_close(dstream);
788
    }
745
    }
789
    (*(main_language->output_proc)) (output_closure, &grammar);
746
   (*(main_language->output_proc))(output_closure, &grammar);
790
}
747
}
791
 
748
 
792
/*--------------------------------------------------------------------------*/
749
/*--------------------------------------------------------------------------*/
793
 
750
 
794
int
751
int
795
main PROTO_N ((argc, argv))
-
 
796
     PROTO_T (int    argc X
-
 
797
	      char **argv)
752
main(int argc, char **argv)
798
{
753
{
799
    HANDLE {
754
    HANDLE {
800
	OutputInfoT out_info;
755
	OutputInfoT out_info;
801
 
756
 
802
	istream_setup ();
757
	istream_setup();
803
	ostream_setup ();
758
	ostream_setup();
804
	out_info_init (&out_info, argv [0]);
759
	out_info_init(&out_info, argv[0]);
805
	ostream_init (&dump_stream);
760
	ostream_init(&dump_stream);
806
	cstring_list_init (&main_language_options);
761
	cstring_list_init(&main_language_options);
807
	main_init (argc, argv, &out_info);
762
	main_init(argc, argv, &out_info);
808
	if (ostream_is_open (&dump_stream)) {
763
	if (ostream_is_open(&dump_stream)) {
809
	    main_1 (&out_info, &dump_stream);
764
	    main_1(&out_info, &dump_stream);
810
	} else {
765
	} else {
811
	    main_1 (&out_info, NIL (OStreamP));
766
	    main_1(&out_info, NIL(OStreamP));
812
	}
767
	}
813
    } WITH {
768
    } WITH {
814
	ExceptionP exception = EXCEPTION_EXCEPTION ();
769
	ExceptionP exception = EXCEPTION_EXCEPTION();
815
 
770
 
816
	if (exception == XX_dalloc_no_memory) {
771
	if (exception == XX_dalloc_no_memory) {
817
	    E_no_memory ();
772
	    E_no_memory();
818
	    UNREACHED;
773
	    UNREACHED;
819
	} else if (exception == XX_istream_read_error) {
774
	} else if (exception == XX_istream_read_error) {
820
	    CStringP file = (CStringP) EXCEPTION_VALUE ();
775
	    CStringP file = (CStringP)EXCEPTION_VALUE();
821
 
776
 
822
	    E_read_error (file);
777
	    E_read_error(file);
823
	    UNREACHED;
778
	    UNREACHED;
824
	} else if (exception == XX_ostream_write_error) {
779
	} else if (exception == XX_ostream_write_error) {
825
	    CStringP file = (CStringP) EXCEPTION_VALUE ();
780
	    CStringP file = (CStringP)EXCEPTION_VALUE();
826
 
781
 
827
	    E_write_error (file);
782
	    E_write_error(file);
828
	    UNREACHED;
783
	    UNREACHED;
829
	} else {
784
	} else {
830
	    RETHROW ();
785
	    RETHROW();
831
	    UNREACHED;
786
	    UNREACHED;
832
	}
787
	}
833
    } END_HANDLE
788
    } END_HANDLE
834
    exit (EXIT_SUCCESS);
789
    exit(EXIT_SUCCESS);
835
    UNREACHED;
790
    UNREACHED;
836
}
791
}
837

792

838
/*
793
/*
839
 * Local variables(smf):
794
 * Local variables(smf):