#define PROG_NAME "grr_reducer" #define PROG_DESC "reduce and reorder a SELVA grammar" #define PROG_VERS "1.0" /* Copyright © 2004 by the State University of Campinas (UNICAMP). */ /* See the copyright, authorship, and warranty notice at end of file. */ /* Last edited on 2024-12-21 11:47:41 by stolfi */ /* TO DO: Remove unreachable symbols and rules? (Need axiom). */ #define PROG_HELP \ " " PROG_NAME " < GRAMMAR.gex > GRAMMAR.red" #define PROG_INFO \ "NAME\n" \ " " PROG_NAME " - " PROG_DESC "\n" \ "\n" \ "SYNOPSIS\n" \ PROG_HELP "\n" \ "\n" \ "DESCRIPTION\n" \ " ???\n" \ "\n" \ "AUTHORS\n" \ " Created 2004-12-08 by Lucien Fantin and Jorge Stolfi at IC-UNICAMP." #include #include #include #include #include #include #include #include #include #include #include #include #include /* PROTOTYPES */ int main(int argc, char **argv); void grr_arg_error(char *msg); /* IMPLEMENTATIONS */ int main(int argc, char **argv) { /* Get command line argument */ if (argc != 1) { grr_arg_error("bad args"); } /* Read expanded grammar. */ Grammar_t *G1 = grr_read_Grammar(stdin); /* grr_write_Grammar(stderr, G1); */ /* Remove empty rules: */ Grammar_t *G2 = grr_remove_empty_rules(G1); grr_free_grammar(G1); /* Remove invalid symbols: */ Grammar_t *G3 = grr_remove_invalid_symbols(G2); grr_free_grammar(G2); /* Simplify grammar by substituting internal symbols with unary rules: */ Grammar_t *G4 = grr_remove_superfluous_symbols(G3); grr_free_grammar(G3); /* Renumber symbols so that unary rules are increasing: */ Grammar_t *G5 = grr_sort_symbols(G4); grr_free_grammar(G4); /* Output numerically-coded grammar: */ grr_write_Grammar(stdout, G5); return 0; } void grr_arg_error(char *msg) { fprintf(stderr, "** %s: %s", PROG_NAME, msg); fprintf(stderr, "usage: %s\n", PROG_HELP); exit(1); }