summaryrefslogtreecommitdiffstats
path: root/Parser/pgenmain.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-12-20 15:06:42 (GMT)
committerGuido van Rossum <guido@python.org>1990-12-20 15:06:42 (GMT)
commit3f5da24ea304e674a9abbdcffc4d671e32aa70f1 (patch)
treee932e31cb9381f40b7c87c377638216c043b5cfc /Parser/pgenmain.c
parent226d79eb4a776dd54c9e4544b17deaf928bcef3a (diff)
downloadcpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.zip
cpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.tar.gz
cpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.tar.bz2
"Compiling" version
Diffstat (limited to 'Parser/pgenmain.c')
-rw-r--r--Parser/pgenmain.c111
1 files changed, 62 insertions, 49 deletions
diff --git a/Parser/pgenmain.c b/Parser/pgenmain.c
index 678be5d..6eae230 100644
--- a/Parser/pgenmain.c
+++ b/Parser/pgenmain.c
@@ -1,8 +1,14 @@
/* Parser generator main program */
-#include <stdio.h>
+/* This expects a filename containing the grammar as argv[1] (UNIX)
+ or asks the console for such a file name (THINK C).
+ It writes its output on two files in the current directory:
+ - "graminit.c" gets the grammar as a bunch of initialized data
+ - "graminit.h" gets the grammar's non-terminals as #defines.
+ Error messages and status info during the generation process are
+ written to stdout, or sometimes to stderr. */
-#include "PROTO.h"
+#include "pgenheaders.h"
#include "grammar.h"
#include "node.h"
#include "parsetok.h"
@@ -10,24 +16,51 @@
int debugging;
+/* Forward */
+grammar *getgrammar PROTO((char *filename));
#ifdef THINK_C
-char *
-askfile()
+int main PROTO((int, char **));
+char *askfile PROTO((void));
+#endif
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
{
- char buf[256];
- static char name[256];
- printf("Input file name: ");
- if (fgets(buf, sizeof buf, stdin) == NULL) {
- printf("EOF\n");
+ grammar *g;
+ node *n;
+ FILE *fp;
+ char *filename;
+
+#ifdef THINK_C
+ filename = askfile();
+#else
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s grammar\n", argv[0]);
+ exit(2);
+ }
+ filename = argv[1];
+#endif
+ g = getgrammar(filename);
+ fp = fopen("graminit.c", "w");
+ if (fp == NULL) {
+ perror("graminit.c");
exit(1);
}
- if (sscanf(buf, " %s ", name) != 1) {
- printf("No file\n");
+ printf("Writing graminit.c ...\n");
+ printgrammar(g, fp);
+ fclose(fp);
+ fp = fopen("graminit.h", "w");
+ if (fp == NULL) {
+ perror("graminit.h");
exit(1);
}
- return name;
+ printf("Writing graminit.h ...\n");
+ printnonterminals(g, fp);
+ fclose(fp);
+ exit(0);
}
-#endif
grammar *
getgrammar(filename)
@@ -44,7 +77,7 @@ getgrammar(filename)
}
g0 = meta_grammar();
n = NULL;
- parsefile(fp, g0, g0->g_start, (char *)NULL, (char *)NULL, &n);
+ parsefile(fp, filename, g0, g0->g_start, (char *)NULL, (char *)NULL, &n);
fclose(fp);
if (n == NULL) {
fprintf(stderr, "Parsing error.\n");
@@ -58,43 +91,25 @@ getgrammar(filename)
return g;
}
-main(argc, argv)
- int argc;
- char **argv;
-{
- grammar *g;
- node *n;
- FILE *fp;
- char *filename;
-
#ifdef THINK_C
- filename = askfile();
-#else
- if (argc != 2) {
- fprintf(stderr, "usage: %s grammar\n", argv[0]);
- exit(2);
- }
- filename = argv[1];
-#endif
- g = getgrammar(filename);
- fp = fopen("graminit.c", "w");
- if (fp == NULL) {
- perror("graminit.c");
+char *
+askfile()
+{
+ char buf[256];
+ static char name[256];
+ printf("Input file name: ");
+ if (fgets(buf, sizeof buf, stdin) == NULL) {
+ printf("EOF\n");
exit(1);
}
- printf("Writing graminit.c ...\n");
- printgrammar(g, fp);
- fclose(fp);
- fp = fopen("graminit.h", "w");
- if (fp == NULL) {
- perror("graminit.h");
+ /* XXX The (unsigned char *) case is needed by THINK C */
+ if (sscanf((unsigned char *)buf, " %s ", name) != 1) {
+ printf("No file\n");
exit(1);
}
- printf("Writing graminit.h ...\n");
- printnonterminals(g, fp);
- fclose(fp);
- exit(0);
+ return name;
}
+#endif
void
fatal(msg)
@@ -104,8 +119,6 @@ fatal(msg)
exit(1);
}
-/* TO DO:
-
- - improve user interface
- - check for duplicate definitions of names (instead of fatal err)
+/* XXX TO DO:
+ - check for duplicate definitions of names (instead of fatal err)
*/