// Generates a system of equations for generating functions from a grammar. // // (c) 2015 Mikael Vejdemo-Johansson // // Currently does absolutely no elegance, no caching of information, but rather // just prints the generating functions to a provided FILE*. // // If a desugared parser has user_data set, the generating function systems will try // to interpret it as a string: // // If this string for an h_ch starts with the character 0, then that character // will have weight 0 in the generating function. // // Use the remaining string to set the preferred name of that parser in the // generating function. // #ifndef HAMMER_GRAMMAR__H #define HAMMER_GRAMMAR__H #include "../src/backends/contextfree.h" #include "../src/backends/lr.h" // Filched from cfgrammar.c this function extracts the name from user_data if it // is set; otherwise assigns a name automatically from its position in some // ordering of non-terminals. const char *nonterminal_name(const HCFGrammar *g, const HCFChoice *nt); // This function prints out the monomial generated by a single HCFSequence // It returns the resulting exponent for t in length and the number of alternatives // accumulated in length. The monomial is (mostly) printed out to the provided FILE*, // the caller is responsible for adding a scalar and a power of t to the printout. void readsequence(FILE *file, uint32_t *count, uint32_t *length, const HCFGrammar *g, const HCFSequence *seq); // This function walks through a grammar and generates an equation for each // production rule. The results are printed out to the provided FILE*. void h_pprint_gfeqns(FILE *file, const HCFGrammar *g); #endif