1 /***********************************************************
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Parser generator main program */
27 /* This expects a filename containing the grammar as argv[1] (UNIX)
28 or asks the console for such a file name (THINK C).
29 It writes its output on two files in the current directory:
30 - "graminit.c" gets the grammar as a bunch of initialized data
31 - "graminit.h" gets the grammar's non-terminals as #defines.
32 Error messages and status info during the generation process are
33 written to stdout, or sometimes to stderr. */
35 #include "pgenheaders.h"
44 grammar
*getgrammar
PROTO((char *filename
));
46 int main
PROTO((int, char **));
47 char *askfile
PROTO((void));
71 fprintf(stderr
, "usage: %s grammar\n", argv
[0]);
76 g
= getgrammar(filename
);
77 fp
= fopen("graminit.c", "w");
82 printf("Writing graminit.c ...\n");
85 fp
= fopen("graminit.h", "w");
90 printf("Writing graminit.h ...\n");
91 printnonterminals(g
, fp
);
104 fp
= fopen(filename
, "r");
111 parsefile(fp
, filename
, g0
, g0
->g_start
, (char *)NULL
, (char *)NULL
, &n
);
114 fprintf(stderr
, "Parsing error.\n");
119 printf("Bad grammar.\n");
130 static char name
[256];
131 printf("Input file name: ");
132 if (fgets(buf
, sizeof buf
, stdin
) == NULL
) {
136 /* XXX The (unsigned char *) case is needed by THINK C 3.0 */
137 if (sscanf(/*(unsigned char *)*/buf
, " %s ", name
) != 1) {
149 fprintf(stderr
, "pgen: FATAL ERROR: %s\n", msg
);
164 - check for duplicate definitions of names (instead of fatal err)