Next batch of Ansi-ification

This commit is contained in:
Manoel Trapier 2013-03-06 18:05:32 +01:00 committed by Manoël Trapier
parent 9f7ae734db
commit d28368333a
5 changed files with 62 additions and 100 deletions

View File

@ -133,7 +133,7 @@ int hash(char * str);
p_gram search(int type, char * str, int option); p_gram search(int type, char * str, int option);
/* reach.c */ /* reach.c */
int co_reach(void); void co_reach(void);
void reachable(p_nont p); void reachable(p_nont p);
void reachwalk(p_gram p); void reachwalk(p_gram p);
@ -147,6 +147,7 @@ int setminus(p_set a, p_set b);
int setempty(p_set p); int setempty(p_set p);
int findindex(p_set set); int findindex(p_set set);
int setcount(p_set set, int *saved); int setcount(p_set set, int *saved);
/* tokens.c */ /* tokens.c */
void copyact(int ch1, int ch2, int flag, int level); void copyact(int ch1, int ch2, int flag, int level);
int scanner(void); int scanner(void);

View File

@ -40,8 +40,8 @@ void conflchecks() {
* in an alternation, the sets that determine the direction to take, * in an alternation, the sets that determine the direction to take,
* must be disjunct. * must be disjunct.
*/ */
register p_nont p; p_nont p;
register int s; int s;
p_file x = files; p_file x = files;
f_input = x->f_name; f_input = x->f_name;
@ -69,7 +69,7 @@ void conflchecks() {
if (p->n_flags & RECURSIVE) { if (p->n_flags & RECURSIVE) {
error(p->n_lineno, error(p->n_lineno,
"Recursion in default for nonterminal %s", "Recursion in default for nonterminal %s",
p->n_name); p->n_name, NULL);
} }
/* /*
* If a printout is needed for this rule in * If a printout is needed for this rule in
@ -96,20 +96,18 @@ void conflchecks() {
if (verbose) fclose(fout); if (verbose) fclose(fout);
} }
STATIC STATIC void prline(char *s) {
prline(s) char *s; {
fputs(s, fout); fputs(s, fout);
spaces(); spaces();
} }
STATIC STATIC void printset(p_set p, char *s) {
printset(p,s) register p_set p; string s; {
/* /*
* Print the elements of a set * Print the elements of a set
*/ */
register int i; int i;
register int j; int j;
register p_token pt; p_token pt;
string name; string name;
int k; int k;
int hulp; int hulp;
@ -156,13 +154,12 @@ printset(p,s) register p_set p; string s; {
prline("}\n"); prline("}\n");
} }
STATIC int STATIC int check(p_gram p) {
check(p) register p_gram p; {
/* /*
* Search for conflicts in a grammar rule. * Search for conflicts in a grammar rule.
*/ */
register p_set temp; p_set temp;
register int retval; int retval;
retval = 0; retval = 0;
for (;;) { for (;;) {
@ -170,17 +167,17 @@ check(p) register p_gram p; {
case EORULE : case EORULE :
return retval; return retval;
case NONTERM : { case NONTERM : {
register p_nont n; p_nont n;
n = &nonterms[g_getcont(p)]; n = &nonterms[g_getcont(p)];
if (g_getnpar(p) != getntparams(n)) { if (g_getnpar(p) != getntparams(n)) {
error(p->g_lineno, error(p->g_lineno,
"Call of %s: parameter count mismatch", "Call of %s: parameter count mismatch",
n->n_name); n->n_name, NULL);
} }
break; } break; }
case TERM : { case TERM : {
register p_term q; p_term q;
q = g_getterm(p); q = g_getterm(p);
retval |= check(q->t_rule); retval |= check(q->t_rule);
@ -188,12 +185,12 @@ check(p) register p_gram p; {
if (setempty(q->t_first)) { if (setempty(q->t_first)) {
q->t_flags |= EMPTYFIRST; q->t_flags |= EMPTYFIRST;
retval = 1; retval = 1;
error(p->g_lineno, "No symbols in term"); error(p->g_lineno, "No symbols in term", NULL, NULL);
} }
if (empty(q->t_rule)) { if (empty(q->t_rule)) {
q->t_flags |= EMPTYTERM; q->t_flags |= EMPTYTERM;
retval = 1; retval = 1;
error(p->g_lineno, "Term with variable repetition count produces empty"); error(p->g_lineno, "Term with variable repetition count produces empty", NULL, NULL);
} }
temp = setalloc(); temp = setalloc();
setunion(temp,q->t_first); setunion(temp,q->t_first);
@ -206,7 +203,7 @@ check(p) register p_gram p; {
* No conflict resolver * No conflict resolver
*/ */
error(p->g_lineno, error(p->g_lineno,
"Repetition conflict"); "Repetition conflict", NULL, NULL);
retval = 1; retval = 1;
moreverbose(temp); moreverbose(temp);
} }
@ -215,13 +212,13 @@ check(p) register p_gram p; {
if (q->t_flags & RESOLVER) { if (q->t_flags & RESOLVER) {
q->t_flags |= NOCONF; q->t_flags |= NOCONF;
warning(p->g_lineno, warning(p->g_lineno,
"%%while without conflict"); "%%while without conflict", NULL, NULL);
} }
} }
free((p_mem) temp); free((p_mem) temp);
break; } break; }
case ALTERNATION : { case ALTERNATION : {
register p_link l; p_link l;
l = g_getlink(p); l = g_getlink(p);
temp = setalloc(); temp = setalloc();
@ -232,16 +229,14 @@ check(p) register p_gram p; {
* symbols * symbols
*/ */
if (!(l->l_flag & (COND|PREFERING|AVOIDING))) { if (!(l->l_flag & (COND|PREFERING|AVOIDING))) {
error(p->g_lineno, error(p->g_lineno, "Alternation conflict", NULL, NULL);
"Alternation conflict");
retval = 1; retval = 1;
moreverbose(temp); moreverbose(temp);
} }
} else { } else {
if (l->l_flag & (COND|PREFERING|AVOIDING)) { if (l->l_flag & (COND|PREFERING|AVOIDING)) {
l->l_flag |= NOCONF; l->l_flag |= NOCONF;
warning(p->g_lineno, warning(p->g_lineno, "Conflict resolver without conflict", NULL, NULL);
"Conflict resolver without conflict");
} }
} }
free( (p_mem) temp); free( (p_mem) temp);
@ -253,27 +248,25 @@ check(p) register p_gram p; {
} }
} }
STATIC STATIC void moreverbose(p_set t) {
moreverbose(t) register p_set t; {
/* /*
* t points to a set containing conflicting symbols and pssibly * t points to a set containing conflicting symbols and pssibly
* also containing nonterminals. * also containing nonterminals.
* Take care that a printout will be prepared for these nonterminals * Take care that a printout will be prepared for these nonterminals
*/ */
register int i; int i;
register p_nont p; p_nont p;
if (verbose == 2) for (i = 0, p = nonterms; i < nnonterms; i++, p++) { if (verbose == 2) for (i = 0, p = nonterms; i < nnonterms; i++, p++) {
if (NTIN(t,i)) p->n_flags |= VERBOSE; if (NTIN(t,i)) p->n_flags |= VERBOSE;
} }
} }
STATIC STATIC void prrule(p_gram p) {
prrule(p) register p_gram p; {
/* /*
* Create a verbose printout of grammar rule p * Create a verbose printout of grammar rule p
*/ */
register FILE *f; FILE *f;
int present = 0; int present = 0;
int firstalt = 1; int firstalt = 1;
@ -284,8 +277,8 @@ prrule(p) register p_gram p; {
fputs("\n",f); fputs("\n",f);
return; return;
case TERM : { case TERM : {
register p_term q; p_term q;
register int c; int c;
q = g_getterm(p); q = g_getterm(p);
if (present) prline("\n"); if (present) prline("\n");
@ -323,7 +316,9 @@ prrule(p) register p_gram p; {
c = r_getkind(q); c = r_getkind(q);
fputs(c == STAR ? "]*" : c == PLUS ? "]+" : fputs(c == STAR ? "]*" : c == PLUS ? "]+" :
c == OPT ? "]?" : "]", f); c == OPT ? "]?" : "]", f);
if (c = r_getnum(q)) {
c = r_getnum(q);
if (c) {
fprintf(f,"%d",c); fprintf(f,"%d",c);
} }
prline("\n"); prline("\n");
@ -332,7 +327,7 @@ prrule(p) register p_gram p; {
fputs("{..} ",f); fputs("{..} ",f);
break; break;
case ALTERNATION : { case ALTERNATION : {
register p_link l; p_link l;
l = g_getlink(p); l = g_getlink(p);
if (firstalt) { if (firstalt) {
@ -366,7 +361,7 @@ prrule(p) register p_gram p; {
p++; continue; } p++; continue; }
case LITERAL : case LITERAL :
case TERMINAL : { case TERMINAL : {
register p_token pt = &tokens[g_getcont(p)]; p_token pt = &tokens[g_getcont(p)];
fprintf(f,pt->t_tokno<0400 ? fprintf(f,pt->t_tokno<0400 ?
"'%s' " : "%s ", pt->t_string); "'%s' " : "%s ", pt->t_string);
@ -380,15 +375,14 @@ prrule(p) register p_gram p; {
} }
} }
STATIC STATIC void cfcheck(p_set s1, p_set s2, int flag) {
cfcheck(s1,s2,flag) p_set s1,s2; {
/* /*
* Check if s1 and s2 have elements in common. * Check if s1 and s2 have elements in common.
* If so, flag must be non-zero, indicating that there is a * If so, flag must be non-zero, indicating that there is a
* conflict resolver, otherwise, flag must be zero, indicating * conflict resolver, otherwise, flag must be zero, indicating
* that there is not. * that there is not.
*/ */
register p_set temp; p_set temp;
temp = setalloc(); temp = setalloc();
setunion(temp,s1); setunion(temp,s1);
@ -405,8 +399,7 @@ cfcheck(s1,s2,flag) p_set s1,s2; {
free((p_mem) temp); free((p_mem) temp);
} }
STATIC STATIC void resolve(p_gram p) {
resolve(p) register p_gram p; {
/* /*
* resolve conflicts, as specified by the user * resolve conflicts, as specified by the user
*/ */
@ -418,7 +411,7 @@ resolve(p) register p_gram p; {
resolve(g_getterm(p)->t_rule); resolve(g_getterm(p)->t_rule);
break; break;
case ALTERNATION : { case ALTERNATION : {
register p_link l; p_link l;
l = g_getlink(p); l = g_getlink(p);
if (l->l_flag & AVOIDING) { if (l->l_flag & AVOIDING) {
@ -432,7 +425,7 @@ resolve(p) register p_gram p; {
/* /*
* This may be caused by the statement above * This may be caused by the statement above
*/ */
error(p->g_lineno,"Alternative never chosen"); error(p->g_lineno,"Alternative never chosen", NULL, NULL);
} }
resolve(l->l_rule); resolve(l->l_rule);
break; } break; }
@ -441,8 +434,7 @@ resolve(p) register p_gram p; {
} }
} }
STATIC STATIC void propagate(p_set set, p_gram p) {
propagate(set,p) p_set set; register p_gram p; {
/* /*
* Propagate the fact that on the elements of set the grammar rule * Propagate the fact that on the elements of set the grammar rule
* p will not be chosen. * p will not be chosen.
@ -453,8 +445,6 @@ propagate(set,p) p_set set; register p_gram p; {
} }
} }
STATIC STATIC void spaces() {
spaces() {
if (level > 0) fprintf(fout,"%*c",level,' '); if (level > 0) fprintf(fout,"%*c",level,' ');
} }

View File

@ -27,15 +27,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
void *sbrk(void *addr);
char *mktemp(char *template);
#ifndef NORCSID
static string rcsid6 = "$Id$";
#endif
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
register string arg; register string arg;
string libpath(); string libpath();
@ -126,7 +117,7 @@ int main(int argc, char *argv[]) {
argc--; argc--;
} }
if (verbose) beg_sbrk = sbrk(NULL); if (verbose) beg_sbrk = (char *)sbrk(0);
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if ((subpars_sim) && (!non_corr)) { if ((subpars_sim) && (!non_corr)) {

View File

@ -22,9 +22,7 @@
# include "assert.h" # include "assert.h"
# include "io.h" # include "io.h"
# ifndef NORCSID #include "LLgen.h"
static string rcsid7 = "$Id$";
# endif
# define HASHSIZE 128 # define HASHSIZE 128
# define NMSIZ 2048 /* Room for names allocated NMSIZ bytes at a time */ # define NMSIZ 2048 /* Room for names allocated NMSIZ bytes at a time */
@ -36,16 +34,8 @@ static p_entry entries, maxentries;
static t_info token_info, nont_info; static t_info token_info, nont_info;
/* Defined in this file are: */ /* Defined in this file are: */
extern string store();
extern name_init();
STATIC int hash();
STATIC p_entry newentry();
extern p_gram search();
p_mem alloc(); void name_init() {
p_mem new_mem();
name_init() {
token_info.i_esize = sizeof (t_token); token_info.i_esize = sizeof (t_token);
token_info.i_incr = 50; token_info.i_incr = 50;
nont_info.i_esize = sizeof (t_nont); nont_info.i_esize = sizeof (t_nont);
@ -56,8 +46,7 @@ name_init() {
#endif #endif
} }
STATIC p_entry STATIC p_entry newentry(char *str, p_entry next) {
newentry(str, next) string str; p_entry next; {
register p_entry p; register p_entry p;
if ((p = entries) == maxentries) { if ((p = entries) == maxentries) {
@ -74,8 +63,7 @@ newentry(str, next) string str; p_entry next; {
return p; return p;
} }
string char *store(char *s) {
store(s) string s; {
/* /*
* Store a string s in the name table * Store a string s in the name table
*/ */
@ -97,8 +85,7 @@ store(s) string s; {
return s1; return s1;
} }
STATIC int STATIC int hash(char *str) {
hash(str) string str; {
/* /*
* Compute the hash for string str * Compute the hash for string str
*/ */

View File

@ -22,31 +22,26 @@
# include "io.h" # include "io.h"
# include "assert.h" # include "assert.h"
# ifndef NORCSID #include "LLgen.h"
static string rcsid8 = "$Id$";
# endif
/* In this file the following routines are defined: */ /* In this file the following routines are defined: */
extern co_reach();
STATIC reachable();
STATIC reachwalk();
co_reach() { void co_reach() {
/* /*
* Check for undefined or unreachable nonterminals. * Check for undefined or unreachable nonterminals.
*/ */
register p_nont p; p_nont p;
register p_token t; p_token t;
register p_start st; p_start st;
register p_file x; p_file x;
register int s; int s;
/* Check for undefined nonterminals */ /* Check for undefined nonterminals */
for (p = nonterms; p < maxnt; p++) { for (p = nonterms; p < maxnt; p++) {
if (! p->n_rule) { /* undefined */ if (! p->n_rule) { /* undefined */
f_input = p->n_string; f_input = p->n_string;
error(p->n_lineno,"Nonterminal %s not defined", error(p->n_lineno,"Nonterminal %s not defined",
p->n_name); p->n_name, NULL);
} }
} }
@ -67,21 +62,20 @@ co_reach() {
p = &nonterms[s]; p = &nonterms[s];
if (! (p->n_flags & REACHABLE)) { if (! (p->n_flags & REACHABLE)) {
warning(p->n_lineno,"nonterminal %s unreachable", warning(p->n_lineno,"nonterminal %s unreachable",
p->n_name); p->n_name, NULL);
} }
} }
for (s = x->f_terminals; s != -1; s = t->t_next) { for (s = x->f_terminals; s != -1; s = t->t_next) {
t = &tokens[s]; t = &tokens[s];
if (! (t->t_flags & REACHABLE)) { if (! (t->t_flags & REACHABLE)) {
warning(t->t_lineno,"terminal %s not used", warning(t->t_lineno,"terminal %s not used",
t->t_string); t->t_string, NULL);
} }
} }
} }
} }
STATIC STATIC void reachable(p_nont p) {
reachable(p) register p_nont p; {
/* /*
* Enter the fact that p is reachable, and look for implications * Enter the fact that p is reachable, and look for implications
*/ */
@ -94,8 +88,7 @@ reachable(p) register p_nont p; {
} }
} }
STATIC STATIC void reachwalk(p_gram p) {
reachwalk(p) register p_gram p; {
/* /*
* Walk through rule p, looking for nonterminals. * Walk through rule p, looking for nonterminals.
* The nonterminals found are entered as reachable * The nonterminals found are entered as reachable
@ -110,12 +103,12 @@ reachwalk(p) register p_gram p; {
reachwalk(g_getterm(p)->t_rule); reachwalk(g_getterm(p)->t_rule);
break; break;
case NONTERM : { case NONTERM : {
register p_nont n = &nonterms[g_getcont(p)]; p_nont n = &nonterms[g_getcont(p)];
reachable(n); reachable(n);
if (n->n_rule && g_gettype(n->n_rule) == EORULE && if (n->n_rule && g_gettype(n->n_rule) == EORULE &&
! g_getnpar(p) && (getntparams(n) == 0)) { ! g_getnpar(p) && (getntparams(n) == 0)) {
register p_gram np = p; p_gram np = p;
do { do {
*np = *(np + 1); *np = *(np + 1);
np++; np++;