/* driver3.c * driver program for testing the PASC parser with semantic analysis */ #include #include "tree.h" int outtree = 0; /* flag -- print out syntax tree or not? */ int trace = 0; /* flag -- trace parser */ int traceST = 0; /* flag -- trace semantic analysis */ FILE *treelst; /* file used to same the syntax tree */ extern tree Root; /* syntax tree root, imported form tree.c */ extern void init_table(); /* hash table initialization, imported from table.c */ extern int error_count; /* # of semantic errors found */ main(argc, argv) int argc; char *argv[]; { /* check command line switchs */ argc--; argv++; while (argc > 0) { if (!strcmp(*argv, "-h")) { /* command usage help */ printf("Usage: parser [-da [-ts [-dt [tree_outfile]]]] < file.pasc\n"); return; } else if (!strcmp(*argv, "-da")) { /* trace parser actions */ trace = 1; } else if (!strcmp(*argv, "-ts")) { /* trace semantic analysis */ traceST = 1; } else if (!strcmp(*argv, "-dt")) { /* print syntax tree */ outtree = 1; if (argc > 1) { if ((treelst = fopen(*++argv, "w")) == NULL) { printf("Can't open file '%s' for output. ", *argv); printf("Stdout is assumed\n\n"); treelst = stdout; } argc--; } else { printf("Tree file not specified. Stdout is assumed\n\n"); treelst = stdout; } } argc--; argv++; } init_table(); /* initialize hash table */ if (!yyparse()) { checktree(Root); seman(Root); if (outtree) printtree(Root,0); if (error_count == 0) { printf("Program accepted\n"); return; } } printf("Program rejected\n\n"); }