} t_length, *p_length;
void do_compute(void);
-void createsets(void);
-void walk(p_set u, p_gram p);
-void co_trans(int (*fc)(p_nont));
-int nempty(p_nont p);
int empty(p_gram p);
-int nfirst(p_nont p);
-int first(p_set setp, p_gram p, int flag);
-int nfollow(p_nont p);
-int follow(p_set setp, p_gram p);
-void co_dirsymb(p_set setp, p_gram p);
-void co_others(p_gram p);
-int ncomplength(p_nont p);
-int nc_nfirst(p_nont p);
-STATIC int nc_nfollow(p_nont p);
-void do_lengthcomp(void);
-void complength(p_gram p, p_length le);
-void add(p_length a, int c, int v);
-int compare(p_length a, p_length b);
-void setdefaults(p_gram p);
-void do_contains(p_nont n);
-void contains(p_gram p, p_set set);
-int nsafes(p_nont p);
-int do_safes(p_gram p, int safe, int *ch);
int t_safety(int rep, int count, int persistent, int safety);
int t_after(int rep, int count, int outsafety);
char * cpy(int s, char * p, int inserted);
void LLmessage(int d);
+/* grammar.c */
+void save_grammar(FILE *f);
+
#endif /* LLGEN_H */
#include "LLgen.h"
+static void createsets(void);
+static void walk(p_set u, p_gram p);
+static void co_trans(int (*fc)(p_nont));
+static int nempty(p_nont p);
+static int nfirst(p_nont p);
+static int nc_nfirst(p_nont p);
+static int first(p_set setp, p_gram p, int flag);
+static int nc_nfollow(p_nont p);
+static int nc_first(p_set setp, p_gram p, int flag);
+static int nfollow(p_nont p);
+static int follow(p_set setp, p_gram p);
+static void co_dirsymb(p_set setp, p_gram p);
+static void co_others(p_gram p);
+static int ncomplength(p_nont p);
+static void do_lengthcomp(void);
+static void complength(p_gram p, p_length le);
+static void add(p_length a, int c, int v);
+static int compare(p_length a, p_length b);
+static void setdefaults(p_gram p);
+static void do_contains(p_nont n);
+static void contains(p_gram p, p_set set);
+static int nsafes(p_nont p);
+static int do_safes(p_gram p, int safe, int *ch);
+
+
/* Defined in this file : */
-void do_compute(void) {
+void do_compute(void)
+{
/*
* Does all the work, by calling other routines (divide and conquer)
*/
# endif
}
-STATIC void createsets() {
+static void createsets()
+{
/*
* Allocate space for the sets. Also determine which files use
* which nonterminals, and determine which nonterminals can be
}
}
-STATIC void walk(p_set u, p_gram p) {
+static void walk(p_set u, p_gram p)
+{
/*
* Walk through the grammar rule p, allocating sets
*/
}
}
-STATIC void co_trans(int (*fc)(p_nont)) {
+static void co_trans(int (*fc)(p_nont))
+{
p_nont p;
int change;
} while (change);
}
-STATIC int nempty(p_nont p) {
+static int nempty(p_nont p)
+{
if (!(p->n_flags & EMPTY) && empty(p->n_rule)) {
p->n_flags |= EMPTY;
return 1;
return 0;
}
-int empty(p_gram p) {
+int empty(p_gram p)
+{
/*
* Does the rule pointed to by p produce empty ?
*/
}
}
-STATIC int nfirst(p_nont p) {
+static int nfirst(p_nont p)
+{
return first(p->n_first, p->n_rule, 0);
}
#ifdef NON_CORRECTING
-STATIC int nc_nfirst(p_nont p) {
+static int nc_nfirst(p_nont p)
+{
return nc_first(p->n_nc_first, p->n_rule, 0);
}
#endif
-STATIC int first(p_set setp, p_gram p, int flag) {
+static int first(p_set setp, p_gram p, int flag)
+{
/*
* Compute the FIRST set of rule p.
* If flag = 0, also the first sets for terms and alternations in
}
#ifdef NON_CORRECTING
-STATIC int nc_first(p_set setp, p_gram p, int flag) {
+static int nc_first(p_set setp, p_gram p, int flag)
+{
/*
* Compute the non_corr FIRST set of rule p.
* If flag = 0, also the non_corr first sets for terms and
* first-sets of startsynbols in the %substart are used
*/
- register s; /* Will gather return value */
+ int s; /* Will gather return value */
int noenter;/* when set, unables entering of elements into
* setp. This is necessary to walk through the
* rest of rule p.
}
#endif
-STATIC int nfollow(p_nont p) {
+static int nfollow(p_nont p)
+{
return follow(p->n_follow, p->n_rule);
}
-STATIC int follow(p_set setp, p_gram p) {
+static int follow(p_set setp, p_gram p)
+{
/*
* setp is the follow set for the rule p.
* Compute the follow sets in the rule p from this set.
#ifdef NON_CORRECTING
-STATIC int nc_nfollow(p_nont p) {
+static int nc_nfollow(p_nont p)
+{
return follow(p->n_nc_follow, p->n_rule);
}
-STATIC int nc_follow(p_set setp, p_gram p) {
+static int nc_follow(p_set setp, p_gram p)
+{
/*
* setp is the follow set for the rule p.
* Compute the follow sets in the rule p from this set.
#endif
-STATIC void co_dirsymb(p_set setp, p_gram p) {
+static void co_dirsymb(p_set setp, p_gram p)
+{
/*
* Walk the rule p, doing the work for alternations
*/
}
}
-STATIC void co_others(p_gram p) {
+static void co_others(p_gram p)
+{
/*
* compute the l_others-sets for the list of alternatives
* indicated by p
static p_length length;
# define INFINITY 32767
-STATIC int ncomplength(p_nont p)
+static int ncomplength(p_nont p)
{
p_length pl = &length[p - nonterms];
int x = pl->cnt;
return pl->cnt < INFINITY && x == INFINITY;
}
-STATIC void do_lengthcomp()
+static void do_lengthcomp()
{
/*
* Compute the minimum length of a terminal production for each
free ((p_mem) length);
}
-STATIC void complength(p_gram p, p_length le) {
+static void complength(p_gram p, p_length le)
+{
/*
* Walk grammar rule p, computing minimum lengths
*/
}
}
-STATIC void add(p_length a, int c, int v) {
+static void add(p_length a, int c, int v)
+{
if (a->cnt == INFINITY || c == INFINITY) {
a->cnt = INFINITY;
return;
a->cnt += c;
}
-STATIC int compare(p_length a, p_length b) {
+static int compare(p_length a, p_length b)
+{
if (a->cnt != b->cnt) return a->cnt - b->cnt;
return a->val - b->val;
}
-STATIC void setdefaults(p_gram p) {
+static void setdefaults(p_gram p)
+{
for (;;) {
switch(g_gettype(p)) {
case EORULE:
}
}
-STATIC void do_contains(p_nont n) {
+static void do_contains(p_nont n)
+{
/*
* Compute the total set of symbols that nonterminal n can
* produce
}
}
-STATIC void contains(p_gram p, p_set set) {
+static void contains(p_gram p, p_set set)
+{
/*
* Does the real computation of the contains-sets
*/
}
}
-STATIC int nsafes(p) p_nont p; {
+static int nsafes(p_nont p)
+{
int ch;
int i;
return ch;
}
-STATIC int
-do_safes(p,safe,ch) p_gram p; int *ch; {
+static int do_safes(p_gram p, int safe, int *ch)
+{
/*
* Walk the grammar rule, doing the computation described in the
* comment of the procedure above this one.
}
}
-int t_safety(int rep, int count, int persistent, int safety) {
+int t_safety(int rep, int count, int persistent, int safety)
+{
if (safety == NOSCANDONE) safety = SCANDONE;
switch(rep) {
/* NOTREACHED */
}
-int t_after(int rep, int count, int outsafety) {
+int t_after(int rep, int count, int outsafety)
+{
if (count == 0 && (rep == STAR || rep == PLUS)) {
return SAFESCANDONE;
}