Part 1 of warning/old k&r inconsistency correction.
This commit is contained in:
parent
7eff32c40d
commit
9f7ae734db
@ -7,13 +7,11 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
char *
|
char *sys_break(int incr)
|
||||||
sys_break(incr)
|
|
||||||
int incr;
|
|
||||||
{
|
{
|
||||||
register char *brk = sbrk(incr);
|
char *brk = (char*)sbrk(incr);
|
||||||
|
|
||||||
if (brk == (char *) 0 || brk == (char *)-1)
|
if ((brk == (char *) 0) || (brk == (char *)-1))
|
||||||
return ILL_BREAK;
|
return ILL_BREAK;
|
||||||
return brk;
|
return brk;
|
||||||
}
|
}
|
||||||
|
|||||||
160
util/LLgen/src/LLgen.h
Normal file
160
util/LLgen/src/LLgen.h
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
#ifndef LLGEN_H
|
||||||
|
#define LLGEN_H
|
||||||
|
|
||||||
|
/* alloc.c */
|
||||||
|
p_mem alloc(unsigned size);
|
||||||
|
p_mem ralloc(p_mem p, unsigned size);
|
||||||
|
p_mem new_mem(p_info p);
|
||||||
|
|
||||||
|
/* check.c */
|
||||||
|
void conflchecks(void);
|
||||||
|
void prline(char *s);
|
||||||
|
void printset(p_set p, char * s);
|
||||||
|
int check(p_gram p);
|
||||||
|
void moreverbose(p_set t);
|
||||||
|
void prrule(p_gram p);
|
||||||
|
void cfcheck(p_set s1, p_set s2, int flag);
|
||||||
|
void resolve(p_gram p);
|
||||||
|
void propagate(p_set set, p_gram p);
|
||||||
|
void spaces(void);
|
||||||
|
|
||||||
|
/* compute.c */
|
||||||
|
typedef struct lngth {
|
||||||
|
/* Structure used to compute the shortest possible
|
||||||
|
* length of a terminal production of a rule.
|
||||||
|
* In case of a tie, the second field is used.
|
||||||
|
*/
|
||||||
|
int cnt;
|
||||||
|
int val;
|
||||||
|
} 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);
|
||||||
|
|
||||||
|
/* gencode.c */
|
||||||
|
void doclose(FILE *f);
|
||||||
|
int *mk_tokenlist(void);
|
||||||
|
void genhdr(void);
|
||||||
|
void gencode(int argc);
|
||||||
|
void opentemp(char * str);
|
||||||
|
void geninclude(void);
|
||||||
|
void genrecovery(void);
|
||||||
|
void generate(p_file f);
|
||||||
|
void prset(p_set p);
|
||||||
|
void macro(char * s, p_nont n);
|
||||||
|
void controlline(void);
|
||||||
|
void getparams(void);
|
||||||
|
void genprototypes(p_file f);
|
||||||
|
void getansiparams(int mkdef);
|
||||||
|
int gettok(void);
|
||||||
|
void rulecode(p_gram p, int safety, int mustscan, int mustpop);
|
||||||
|
void alternation(p_gram pp, int safety, int mustscan, int mustpop, int lb);
|
||||||
|
void genncrecovery(void);
|
||||||
|
int *dopush(p_gram p, int safety, int toplevel, int **pp);
|
||||||
|
void getaction(int flag);
|
||||||
|
int codeforterm(p_term q, int safety, int toplevel);
|
||||||
|
void genswhead(p_term q, int rep_kind, int rep_count, int safety, int ispushed);
|
||||||
|
void gencases(int *tokenlist, int caseno, int compacted);
|
||||||
|
char * genname(char * s);
|
||||||
|
void genpush(int d);
|
||||||
|
void genincrdecr(char * s, int d);
|
||||||
|
void genpop(int d);
|
||||||
|
int analyze_switch(int *tokenlist);
|
||||||
|
void add_cases(p_set s, int *tokenlist, int caseno);
|
||||||
|
void out_list(int *tokenlist, int listno, int casecnt);
|
||||||
|
void genextname(int d, char *s, FILE *f);
|
||||||
|
void correct_prefix(void);
|
||||||
|
|
||||||
|
/* LLgen.c */
|
||||||
|
void newnorder(int index);
|
||||||
|
void newtorder(int index);
|
||||||
|
int p_init(void);
|
||||||
|
void LL0_spec(void);
|
||||||
|
void mkalt(p_gram prod, int condition, int lc, p_gram res);
|
||||||
|
void mkterm(p_gram prod, int flags, int lc, p_gram result);
|
||||||
|
p_gram copyrule(p_gram p, int length);
|
||||||
|
|
||||||
|
/* Lpars.c */
|
||||||
|
void LLparse(void);
|
||||||
|
void LLscan(int t);
|
||||||
|
void LLread(void);
|
||||||
|
void LLerror(int t);
|
||||||
|
void LLsafeerror(int t);
|
||||||
|
int LLnext(int n);
|
||||||
|
int LLskip(void);
|
||||||
|
void LLnewlevel(unsigned int *LLsinfo);
|
||||||
|
void LLoldlevel(unsigned int *LLsinfo);
|
||||||
|
|
||||||
|
/* machdep.c */
|
||||||
|
void UNLINK(char * x);
|
||||||
|
void RENAME(char * x, char * y);
|
||||||
|
char * libpath(char * s);
|
||||||
|
|
||||||
|
/* main.c */
|
||||||
|
int main(int argc, char *argv[]);
|
||||||
|
void readgrammar(int argc, char *argv[]);
|
||||||
|
void doparse(p_file p);
|
||||||
|
void error(int lineno, char *s, char *t, char *u);
|
||||||
|
void warning(int lineno, char *s, char *t, char *u);
|
||||||
|
void fatal(int lineno, char *s, char *t, char *u);
|
||||||
|
void comfatal(void);
|
||||||
|
void copyfile(char *file);
|
||||||
|
void install(char *target, char *source);
|
||||||
|
|
||||||
|
/* name.c */
|
||||||
|
int name_init(void);
|
||||||
|
p_entry newentry(char * str, p_entry next);
|
||||||
|
char * store(char * s);
|
||||||
|
int hash(char * str);
|
||||||
|
p_gram search(int type, char * str, int option);
|
||||||
|
|
||||||
|
/* reach.c */
|
||||||
|
int co_reach(void);
|
||||||
|
void reachable(p_nont p);
|
||||||
|
void reachwalk(p_gram p);
|
||||||
|
|
||||||
|
/* sets.c */
|
||||||
|
int setinit(int nt_needed);
|
||||||
|
p_set get_set(void);
|
||||||
|
p_set setalloc(void);
|
||||||
|
int setunion(p_set a, p_set b);
|
||||||
|
int setintersect(p_set a, p_set b);
|
||||||
|
int setminus(p_set a, p_set b);
|
||||||
|
int setempty(p_set p);
|
||||||
|
int findindex(p_set set);
|
||||||
|
int setcount(p_set set, int *saved);
|
||||||
|
/* tokens.c */
|
||||||
|
void copyact(int ch1, int ch2, int flag, int level);
|
||||||
|
int scanner(void);
|
||||||
|
int input(void);
|
||||||
|
int unput(int c);
|
||||||
|
int skipcomment(int flag);
|
||||||
|
char * vallookup(int s);
|
||||||
|
char * cpy(int s, char * p, int inserted);
|
||||||
|
int LLmessage(int d);
|
||||||
|
|
||||||
|
#endif /* LLGEN_H */
|
||||||
@ -24,29 +24,15 @@
|
|||||||
# include "sets.h"
|
# include "sets.h"
|
||||||
# include "assert.h"
|
# include "assert.h"
|
||||||
|
|
||||||
# ifndef NORCSID
|
#include "LLgen.h"
|
||||||
static string rcsid1 = "$Id$";
|
|
||||||
# endif
|
|
||||||
|
|
||||||
static string c_first = "> firstset ";
|
static string c_first = "> firstset ";
|
||||||
static string c_contains = "> containset ";
|
static string c_contains = "> containset ";
|
||||||
static string c_follow = "> followset ";
|
static string c_follow = "> followset ";
|
||||||
p_set setalloc();
|
|
||||||
static int level;
|
static int level;
|
||||||
|
|
||||||
/* In this file are defined : */
|
/* In this file are defined : */
|
||||||
extern conflchecks();
|
void conflchecks() {
|
||||||
STATIC prline();
|
|
||||||
STATIC printset();
|
|
||||||
STATIC int check();
|
|
||||||
STATIC moreverbose();
|
|
||||||
STATIC prrule();
|
|
||||||
STATIC cfcheck();
|
|
||||||
STATIC resolve();
|
|
||||||
STATIC propagate();
|
|
||||||
STATIC spaces();
|
|
||||||
|
|
||||||
conflchecks() {
|
|
||||||
/*
|
/*
|
||||||
* Check for conflicts, that is,
|
* Check for conflicts, that is,
|
||||||
* in a repeating term, the FIRST and FOLLOW must be disjunct,
|
* in a repeating term, the FIRST and FOLLOW must be disjunct,
|
||||||
@ -63,7 +49,7 @@ conflchecks() {
|
|||||||
for (p = nonterms; p < maxnt; p++) p->n_flags |= VERBOSE;
|
for (p = nonterms; p < maxnt; p++) p->n_flags |= VERBOSE;
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
if ((fout = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out);
|
if ((fout = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out, NULL);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Check the rules in the order in which they are declared,
|
* Check the rules in the order in which they are declared,
|
||||||
|
|||||||
@ -17,61 +17,23 @@
|
|||||||
* Also checks the continuation grammar from the specified grammar.
|
* Also checks the continuation grammar from the specified grammar.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "extern.h"
|
# include "extern.h"
|
||||||
# include "sets.h"
|
# include "sets.h"
|
||||||
# include "assert.h"
|
# include "assert.h"
|
||||||
# include "io.h"
|
# include "io.h"
|
||||||
|
|
||||||
# ifndef NORCSID
|
#include "LLgen.h"
|
||||||
static string rcsid = "$Id$";
|
|
||||||
# endif
|
|
||||||
|
|
||||||
p_set get_set();
|
|
||||||
typedef struct lngth {
|
|
||||||
/* Structure used to compute the shortest possible
|
|
||||||
* length of a terminal production of a rule.
|
|
||||||
* In case of a tie, the second field is used.
|
|
||||||
*/
|
|
||||||
int cnt;
|
|
||||||
int val;
|
|
||||||
} t_length, *p_length;
|
|
||||||
|
|
||||||
/* Defined in this file : */
|
/* Defined in this file : */
|
||||||
extern do_compute();
|
void do_compute(void) {
|
||||||
STATIC createsets();
|
|
||||||
STATIC walk();
|
|
||||||
STATIC co_trans();
|
|
||||||
STATIC int nempty();
|
|
||||||
extern empty();
|
|
||||||
STATIC int nfirst();
|
|
||||||
STATIC first();
|
|
||||||
STATIC int nfollow();
|
|
||||||
STATIC follow();
|
|
||||||
STATIC co_dirsymb();
|
|
||||||
STATIC co_others();
|
|
||||||
STATIC do_lengthcomp();
|
|
||||||
STATIC complength();
|
|
||||||
STATIC add();
|
|
||||||
STATIC int compare();
|
|
||||||
STATIC setdefaults();
|
|
||||||
STATIC do_contains();
|
|
||||||
STATIC contains();
|
|
||||||
STATIC int nsafes();
|
|
||||||
STATIC int do_safes();
|
|
||||||
#ifdef NON_CORRECTING
|
|
||||||
STATIC int nc_nfirst();
|
|
||||||
STATIC nc_first();
|
|
||||||
STATIC int nc_nfollow();
|
|
||||||
STATIC nc_follow();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
do_compute() {
|
|
||||||
/*
|
/*
|
||||||
* Does all the work, by calling other routines (divide and conquer)
|
* Does all the work, by calling other routines (divide and conquer)
|
||||||
*/
|
*/
|
||||||
register p_nont p;
|
p_nont p;
|
||||||
register p_start st;
|
p_start st;
|
||||||
|
|
||||||
createsets();
|
createsets();
|
||||||
co_trans(nempty); /* Which nonterminals produce empty? */
|
co_trans(nempty); /* Which nonterminals produce empty? */
|
||||||
@ -160,22 +122,21 @@ do_compute() {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void createsets() {
|
||||||
createsets() {
|
|
||||||
/*
|
/*
|
||||||
* Allocate space for the sets. Also determine which files use
|
* Allocate space for the sets. Also determine which files use
|
||||||
* which nonterminals, and determine which nonterminals can be
|
* which nonterminals, and determine which nonterminals can be
|
||||||
* made static.
|
* made static.
|
||||||
*/
|
*/
|
||||||
register p_nont p;
|
p_nont p;
|
||||||
register p_file f;
|
p_file f;
|
||||||
register p_start st;
|
p_start st;
|
||||||
register int i;
|
int i;
|
||||||
int n = NINTS(NBYTES(nnonterms));
|
int n = NINTS(NBYTES(nnonterms));
|
||||||
p_mem alloc();
|
p_mem alloc();
|
||||||
|
|
||||||
for (f = files; f < maxfiles; f++) {
|
for (f = files; f < maxfiles; f++) {
|
||||||
register p_set s;
|
p_set s;
|
||||||
f->f_used = s = (p_set) alloc((unsigned)n*sizeof(*(f->f_used)));
|
f->f_used = s = (p_set) alloc((unsigned)n*sizeof(*(f->f_used)));
|
||||||
for (i = n; i; i--) *s++ = 0;
|
for (i = n; i; i--) *s++ = 0;
|
||||||
for (i = f->f_nonterminals; i != -1; i = p->n_next) {
|
for (i = f->f_nonterminals; i != -1; i = p->n_next) {
|
||||||
@ -192,7 +153,7 @@ createsets() {
|
|||||||
}
|
}
|
||||||
for (f = files; f < maxfiles; f++) {
|
for (f = files; f < maxfiles; f++) {
|
||||||
for (i = f->f_nonterminals; i != -1; i = p->n_next) {
|
for (i = f->f_nonterminals; i != -1; i = p->n_next) {
|
||||||
register p_file f2;
|
p_file f2;
|
||||||
|
|
||||||
p = &nonterms[i];
|
p = &nonterms[i];
|
||||||
for (f2 = files; f2 < maxfiles; f2++) {
|
for (f2 = files; f2 < maxfiles; f2++) {
|
||||||
@ -207,8 +168,7 @@ createsets() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void walk(p_set u, p_gram p) {
|
||||||
walk(u, p) p_set u; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* Walk through the grammar rule p, allocating sets
|
* Walk through the grammar rule p, allocating sets
|
||||||
*/
|
*/
|
||||||
@ -216,7 +176,7 @@ walk(u, p) p_set u; register p_gram p; {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
switch (g_gettype(p)) {
|
switch (g_gettype(p)) {
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
q->t_first = get_set();
|
q->t_first = get_set();
|
||||||
@ -228,7 +188,7 @@ walk(u, p) p_set u; register p_gram p; {
|
|||||||
walk(u, q->t_rule);
|
walk(u, q->t_rule);
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
|
|
||||||
l = g_getlink(p);
|
l = g_getlink(p);
|
||||||
l->l_symbs = get_set();
|
l->l_symbs = get_set();
|
||||||
@ -239,7 +199,7 @@ walk(u, p) p_set u; register p_gram p; {
|
|||||||
walk(u, l->l_rule);
|
walk(u, l->l_rule);
|
||||||
break; }
|
break; }
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register int i = g_getcont(p);
|
int i = g_getcont(p);
|
||||||
|
|
||||||
PUTIN(u, i);
|
PUTIN(u, i);
|
||||||
break; }
|
break; }
|
||||||
@ -250,10 +210,9 @@ walk(u, p) p_set u; register p_gram p; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void co_trans(int (*fc)(p_nont)) {
|
||||||
co_trans(fc) int (*fc)(); {
|
p_nont p;
|
||||||
register p_nont p;
|
int change;
|
||||||
register int change;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
change = 0;
|
change = 0;
|
||||||
@ -263,8 +222,7 @@ co_trans(fc) int (*fc)(); {
|
|||||||
} while (change);
|
} while (change);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int
|
STATIC int nempty(p_nont p) {
|
||||||
nempty(p) register p_nont p; {
|
|
||||||
if (!(p->n_flags & EMPTY) && empty(p->n_rule)) {
|
if (!(p->n_flags & EMPTY) && empty(p->n_rule)) {
|
||||||
p->n_flags |= EMPTY;
|
p->n_flags |= EMPTY;
|
||||||
return 1;
|
return 1;
|
||||||
@ -272,7 +230,7 @@ nempty(p) register p_nont p; {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
empty(p) register p_gram p; {
|
int empty(p_gram p) {
|
||||||
/*
|
/*
|
||||||
* Does the rule pointed to by p produce empty ?
|
* Does the rule pointed to by p produce empty ?
|
||||||
*/
|
*/
|
||||||
@ -282,7 +240,7 @@ empty(p) register p_gram p; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return 1;
|
return 1;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
if (r_getkind(q) == STAR
|
if (r_getkind(q) == STAR
|
||||||
@ -308,19 +266,17 @@ empty(p) register p_gram p; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int
|
STATIC int nfirst(p_nont p) {
|
||||||
nfirst(p) register p_nont p; {
|
|
||||||
return first(p->n_first, p->n_rule, 0);
|
return first(p->n_first, p->n_rule, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
STATIC int nc_nfirst(p) register p_nont p; {
|
STATIC int nc_nfirst(p_nont p) {
|
||||||
return nc_first(p->n_nc_first, p->n_rule, 0);
|
return nc_first(p->n_nc_first, p->n_rule, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC
|
STATIC int first(p_set setp, p_gram p, int flag) {
|
||||||
first(setp,p,flag) p_set setp; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* Compute the FIRST set of rule p.
|
* Compute the FIRST set of rule p.
|
||||||
* If flag = 0, also the first sets for terms and alternations in
|
* If flag = 0, also the first sets for terms and alternations in
|
||||||
@ -328,8 +284,8 @@ first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
* The FIRST set is put in setp.
|
* The FIRST set is put in setp.
|
||||||
* return 1 if the set refered to by "setp" changed
|
* return 1 if the set refered to by "setp" changed
|
||||||
*/
|
*/
|
||||||
register s; /* Will gather return value */
|
int s; /* Will gather return value */
|
||||||
int noenter;/* when set, unables entering of elements into
|
int noenter;/* when set, unables entering of elements into
|
||||||
* setp. This is necessary to walk through the
|
* setp. This is necessary to walk through the
|
||||||
* rest of rule p.
|
* rest of rule p.
|
||||||
*/
|
*/
|
||||||
@ -341,11 +297,11 @@ first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return s;
|
return s;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
if (first(q->t_first,q->t_rule,0))/*nothing*/;
|
first(q->t_first,q->t_rule,0);
|
||||||
}
|
}
|
||||||
if (!noenter) s |= setunion(setp,q->t_first);
|
if (!noenter) s |= setunion(setp,q->t_first);
|
||||||
p++;
|
p++;
|
||||||
@ -354,11 +310,11 @@ first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
empty(q->t_rule)) continue;
|
empty(q->t_rule)) continue;
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
|
|
||||||
l = g_getlink(p);
|
l = g_getlink(p);
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
if (first(l->l_symbs,l->l_rule,0))/*nothing*/;
|
first(l->l_symbs,l->l_rule,0);
|
||||||
}
|
}
|
||||||
if (noenter == 0) {
|
if (noenter == 0) {
|
||||||
s |= setunion(setp,l->l_symbs);
|
s |= setunion(setp,l->l_symbs);
|
||||||
@ -378,7 +334,7 @@ first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
if (noenter == 0) {
|
if (noenter == 0) {
|
||||||
@ -398,8 +354,7 @@ first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
STATIC
|
STATIC int nc_first(p_set setp, p_gram p, int flag) {
|
||||||
nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* Compute the non_corr FIRST set of rule p.
|
* Compute the non_corr FIRST set of rule p.
|
||||||
* If flag = 0, also the non_corr first sets for terms and
|
* If flag = 0, also the non_corr first sets for terms and
|
||||||
@ -424,11 +379,11 @@ nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return s;
|
return s;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
if (nc_first(q->t_nc_first,q->t_rule,0))/*nothing*/;
|
nc_first(q->t_nc_first,q->t_rule,0);
|
||||||
}
|
}
|
||||||
if (!noenter) s |= setunion(setp,q->t_nc_first);
|
if (!noenter) s |= setunion(setp,q->t_nc_first);
|
||||||
p++;
|
p++;
|
||||||
@ -437,11 +392,11 @@ nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
empty(q->t_rule)) continue;
|
empty(q->t_rule)) continue;
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
|
|
||||||
l = g_getlink(p);
|
l = g_getlink(p);
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
if (nc_first(l->l_nc_symbs,l->l_rule,0))/*nothing*/;
|
nc_first(l->l_nc_symbs,l->l_rule,0);
|
||||||
}
|
}
|
||||||
if (noenter == 0) {
|
if (noenter == 0) {
|
||||||
s |= setunion(setp,l->l_nc_symbs);
|
s |= setunion(setp,l->l_nc_symbs);
|
||||||
@ -451,17 +406,23 @@ nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
p++;
|
p++;
|
||||||
continue;
|
continue;
|
||||||
case ACTION : {
|
case ACTION : {
|
||||||
register p_start subp;
|
p_start subp;
|
||||||
|
|
||||||
if (!noenter)
|
if (!noenter)
|
||||||
|
{
|
||||||
if (subpars_sim)
|
if (subpars_sim)
|
||||||
|
{
|
||||||
s |= setunion(setp, start_firsts);
|
s |= setunion(setp, start_firsts);
|
||||||
else {
|
}
|
||||||
for (subp = g_getsubparse(p); subp;
|
else
|
||||||
subp = subp->ff_next)
|
{
|
||||||
s |= setunion(setp, (&nonterms[subp->ff_nont])->n_nc_first);
|
for (subp = g_getsubparse(p); subp; subp = subp->ff_next)
|
||||||
|
{
|
||||||
|
s |= setunion(setp, (&nonterms[subp->ff_nont])->n_nc_first);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p++;
|
p++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -479,7 +440,7 @@ nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
if (noenter == 0) {
|
if (noenter == 0) {
|
||||||
@ -499,19 +460,17 @@ nc_first(setp,p,flag) p_set setp; register p_gram p; {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC int
|
STATIC int nfollow(p_nont p) {
|
||||||
nfollow(p) register p_nont p; {
|
|
||||||
return follow(p->n_follow, p->n_rule);
|
return follow(p->n_follow, p->n_rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC int follow(p_set setp, p_gram p) {
|
||||||
follow(setp,p) p_set setp; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* setp is the follow set for the rule p.
|
* setp is the follow set for the rule p.
|
||||||
* Compute the follow sets in the rule p from this set.
|
* Compute the follow sets in the rule p from this set.
|
||||||
* Return 1 if a follow set of a nonterminal changed.
|
* Return 1 if a follow set of a nonterminal changed.
|
||||||
*/
|
*/
|
||||||
register s; /* Will gather return value */
|
int s; /* Will gather return value */
|
||||||
|
|
||||||
s = 0;
|
s = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -519,7 +478,7 @@ follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return s;
|
return s;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
if (empty(p+1)) {
|
if (empty(p+1)) {
|
||||||
@ -558,7 +517,7 @@ follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
s |= follow(setp,g_getlink(p)->l_rule);
|
s |= follow(setp,g_getlink(p)->l_rule);
|
||||||
break;
|
break;
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
s |= first(n->n_follow,p+1,1);
|
s |= first(n->n_follow,p+1,1);
|
||||||
@ -578,19 +537,17 @@ follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
|
|
||||||
STATIC int
|
STATIC int nc_nfollow(p_nont p) {
|
||||||
nc_nfollow(p) register p_nont p; {
|
|
||||||
return follow(p->n_nc_follow, p->n_rule);
|
return follow(p->n_nc_follow, p->n_rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC int nc_follow(p_set setp, p_gram p) {
|
||||||
nc_follow(setp,p) p_set setp; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* setp is the follow set for the rule p.
|
* setp is the follow set for the rule p.
|
||||||
* Compute the follow sets in the rule p from this set.
|
* Compute the follow sets in the rule p from this set.
|
||||||
* Return 1 if a follow set of a nonterminal changed.
|
* Return 1 if a follow set of a nonterminal changed.
|
||||||
*/
|
*/
|
||||||
register s; /* Will gather return value */
|
int s; /* Will gather return value */
|
||||||
|
|
||||||
s = 0;
|
s = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -598,7 +555,7 @@ nc_follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return s;
|
return s;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
if (empty(p+1)) {
|
if (empty(p+1)) {
|
||||||
@ -637,7 +594,7 @@ nc_follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
s |= nc_follow(setp,g_getlink(p)->l_rule);
|
s |= nc_follow(setp,g_getlink(p)->l_rule);
|
||||||
break;
|
break;
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
s |= nc_first(n->n_nc_follow,p+1,1);
|
s |= nc_first(n->n_nc_follow,p+1,1);
|
||||||
@ -657,25 +614,24 @@ nc_follow(setp,p) p_set setp; register p_gram p; {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC
|
STATIC void co_dirsymb(p_set setp, p_gram p) {
|
||||||
co_dirsymb(setp,p) p_set setp; register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* Walk the rule p, doing the work for alternations
|
* Walk the rule p, doing the work for alternations
|
||||||
*/
|
*/
|
||||||
register p_gram s = 0;
|
p_gram s = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (g_gettype(p)) {
|
switch (g_gettype(p)) {
|
||||||
case EORULE :
|
case EORULE :
|
||||||
return;
|
return;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
co_dirsymb(q->t_follow,q->t_rule);
|
co_dirsymb(q->t_follow,q->t_rule);
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
/*
|
/*
|
||||||
* Save first alternative
|
* Save first alternative
|
||||||
*/
|
*/
|
||||||
@ -705,13 +661,12 @@ co_dirsymb(setp,p) p_set setp; register p_gram p; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void co_others(p_gram p) {
|
||||||
co_others(p) register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* compute the l_others-sets for the list of alternatives
|
* compute the l_others-sets for the list of alternatives
|
||||||
* indicated by p
|
* indicated by p
|
||||||
*/
|
*/
|
||||||
register p_link l1,l2;
|
p_link l1,l2;
|
||||||
|
|
||||||
l1 = g_getlink(p);
|
l1 = g_getlink(p);
|
||||||
p++;
|
p++;
|
||||||
@ -732,11 +687,9 @@ co_others(p) register p_gram p; {
|
|||||||
static p_length length;
|
static p_length length;
|
||||||
# define INFINITY 32767
|
# define INFINITY 32767
|
||||||
|
|
||||||
STATIC
|
STATIC int ncomplength(p_nont p)
|
||||||
ncomplength(p)
|
|
||||||
register p_nont p;
|
|
||||||
{
|
{
|
||||||
register p_length pl = &length[p - nonterms];
|
p_length pl = &length[p - nonterms];
|
||||||
int x = pl->cnt;
|
int x = pl->cnt;
|
||||||
|
|
||||||
pl->cnt = -1;
|
pl->cnt = -1;
|
||||||
@ -744,8 +697,8 @@ ncomplength(p)
|
|||||||
return pl->cnt < INFINITY && x == INFINITY;
|
return pl->cnt < INFINITY && x == INFINITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void do_lengthcomp()
|
||||||
do_lengthcomp() {
|
{
|
||||||
/*
|
/*
|
||||||
* Compute the minimum length of a terminal production for each
|
* Compute the minimum length of a terminal production for each
|
||||||
* nonterminal.
|
* nonterminal.
|
||||||
@ -755,8 +708,8 @@ do_lengthcomp() {
|
|||||||
* - a crude measure of the number of terms and nonterminals in the
|
* - a crude measure of the number of terms and nonterminals in the
|
||||||
* production of this shortest string.
|
* production of this shortest string.
|
||||||
*/
|
*/
|
||||||
register p_length pl;
|
p_length pl;
|
||||||
register p_nont p;
|
p_nont p;
|
||||||
p_mem alloc();
|
p_mem alloc();
|
||||||
|
|
||||||
length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length)));
|
length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length)));
|
||||||
@ -776,13 +729,12 @@ do_lengthcomp() {
|
|||||||
free ((p_mem) length);
|
free ((p_mem) length);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void complength(p_gram p, p_length le) {
|
||||||
complength(p,le) register p_gram p; p_length le; {
|
|
||||||
/*
|
/*
|
||||||
* Walk grammar rule p, computing minimum lengths
|
* Walk grammar rule p, computing minimum lengths
|
||||||
*/
|
*/
|
||||||
register p_link l;
|
p_link l;
|
||||||
register p_term q;
|
p_term q;
|
||||||
t_length i;
|
t_length i;
|
||||||
t_length X;
|
t_length X;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@ -825,7 +777,7 @@ complength(p,le) register p_gram p; p_length le; {
|
|||||||
le->val = X.val;
|
le->val = X.val;
|
||||||
return;
|
return;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register int rep;
|
int rep;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
rep = r_getkind(q);
|
rep = r_getkind(q);
|
||||||
@ -844,7 +796,7 @@ complength(p,le) register p_gram p; p_length le; {
|
|||||||
break; }
|
break; }
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
int nn = g_getcont(p);
|
int nn = g_getcont(p);
|
||||||
register p_length pl = &length[nn];
|
p_length pl = &length[nn];
|
||||||
int x = pl->cnt;
|
int x = pl->cnt;
|
||||||
|
|
||||||
if (x == INFINITY) {
|
if (x == INFINITY) {
|
||||||
@ -861,9 +813,7 @@ complength(p,le) register p_gram p; p_length le; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void add(p_length a, int c, int v) {
|
||||||
add(a, c, v) register p_length a; {
|
|
||||||
|
|
||||||
if (a->cnt == INFINITY || c == INFINITY) {
|
if (a->cnt == INFINITY || c == INFINITY) {
|
||||||
a->cnt = INFINITY;
|
a->cnt = INFINITY;
|
||||||
return;
|
return;
|
||||||
@ -872,14 +822,12 @@ add(a, c, v) register p_length a; {
|
|||||||
a->cnt += c;
|
a->cnt += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int
|
STATIC int compare(p_length a, p_length b) {
|
||||||
compare(a, b) register p_length a, b; {
|
|
||||||
if (a->cnt != b->cnt) return a->cnt - b->cnt;
|
if (a->cnt != b->cnt) return a->cnt - b->cnt;
|
||||||
return a->val - b->val;
|
return a->val - b->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void setdefaults(p_gram p) {
|
||||||
setdefaults(p) register p_gram p; {
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch(g_gettype(p)) {
|
switch(g_gettype(p)) {
|
||||||
case EORULE:
|
case EORULE:
|
||||||
@ -888,7 +836,7 @@ setdefaults(p) register p_gram p; {
|
|||||||
setdefaults(g_getterm(p)->t_rule);
|
setdefaults(g_getterm(p)->t_rule);
|
||||||
break;
|
break;
|
||||||
case ALTERNATION: {
|
case ALTERNATION: {
|
||||||
register p_link l, l1;
|
p_link l, l1;
|
||||||
int temp = 0, temp1, cnt = 0;
|
int temp = 0, temp1, cnt = 0;
|
||||||
t_length count, i;
|
t_length count, i;
|
||||||
|
|
||||||
@ -920,8 +868,7 @@ setdefaults(p) register p_gram p; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void do_contains(p_nont n) {
|
||||||
do_contains(n) register p_nont n; {
|
|
||||||
/*
|
/*
|
||||||
* Compute the total set of symbols that nonterminal n can
|
* Compute the total set of symbols that nonterminal n can
|
||||||
* produce
|
* produce
|
||||||
@ -948,8 +895,7 @@ do_contains(n) register p_nont n; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void contains(p_gram p, p_set set) {
|
||||||
contains(p,set) register p_gram p; register p_set set; {
|
|
||||||
/*
|
/*
|
||||||
* Does the real computation of the contains-sets
|
* Does the real computation of the contains-sets
|
||||||
*/
|
*/
|
||||||
@ -959,7 +905,7 @@ contains(p,set) register p_gram p; register p_set set; {
|
|||||||
case EORULE :
|
case EORULE :
|
||||||
return;
|
return;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
int rep;
|
int rep;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
@ -987,7 +933,7 @@ contains(p,set) register p_gram p; register p_set set; {
|
|||||||
if (set) setunion(set,q->t_contains);
|
if (set) setunion(set,q->t_contains);
|
||||||
break; }
|
break; }
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
do_contains(n);
|
do_contains(n);
|
||||||
@ -997,7 +943,7 @@ contains(p,set) register p_gram p; register p_set set; {
|
|||||||
}
|
}
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
|
|
||||||
l = g_getlink(p);
|
l = g_getlink(p);
|
||||||
contains(l->l_rule,
|
contains(l->l_rule,
|
||||||
@ -1005,7 +951,7 @@ contains(p,set) register p_gram p; register p_set set; {
|
|||||||
break; }
|
break; }
|
||||||
case LITERAL :
|
case LITERAL :
|
||||||
case TERMINAL : {
|
case TERMINAL : {
|
||||||
register hulp;
|
int hulp;
|
||||||
|
|
||||||
if (set) {
|
if (set) {
|
||||||
hulp = g_getcont(p);
|
hulp = g_getcont(p);
|
||||||
@ -1017,9 +963,9 @@ contains(p,set) register p_gram p; register p_set set; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int nsafes(p) register p_nont p; {
|
STATIC int nsafes(p) p_nont p; {
|
||||||
int ch;
|
int ch;
|
||||||
register int i;
|
int i;
|
||||||
|
|
||||||
ch = 0;
|
ch = 0;
|
||||||
i = getntsafe(p);
|
i = getntsafe(p);
|
||||||
@ -1038,7 +984,7 @@ STATIC int nsafes(p) register p_nont p; {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC int
|
STATIC int
|
||||||
do_safes(p,safe,ch) register p_gram p; register int *ch; {
|
do_safes(p,safe,ch) p_gram p; int *ch; {
|
||||||
/*
|
/*
|
||||||
* Walk the grammar rule, doing the computation described in the
|
* Walk the grammar rule, doing the computation described in the
|
||||||
* comment of the procedure above this one.
|
* comment of the procedure above this one.
|
||||||
@ -1055,7 +1001,7 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
|
|||||||
safe = NOSCANDONE;
|
safe = NOSCANDONE;
|
||||||
break;
|
break;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
int i,rep;
|
int i,rep;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
@ -1067,8 +1013,8 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
|
|||||||
safe = t_after(rep, i, retval);
|
safe = t_after(rep, i, retval);
|
||||||
break; }
|
break; }
|
||||||
case ALTERNATION : {
|
case ALTERNATION : {
|
||||||
register p_link l;
|
p_link l;
|
||||||
register int i;
|
int i;
|
||||||
|
|
||||||
retval = -1;
|
retval = -1;
|
||||||
while (g_gettype(p) == ALTERNATION) {
|
while (g_gettype(p) == ALTERNATION) {
|
||||||
@ -1089,8 +1035,8 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
|
|||||||
}
|
}
|
||||||
return retval; }
|
return retval; }
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
register int nsafe, osafe;
|
int nsafe, osafe;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
nsafe = getntsafe(n);
|
nsafe = getntsafe(n);
|
||||||
@ -1122,7 +1068,7 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t_safety(rep, count, persistent, safety) {
|
int t_safety(int rep, int count, int persistent, int safety) {
|
||||||
|
|
||||||
if (safety == NOSCANDONE) safety = SCANDONE;
|
if (safety == NOSCANDONE) safety = SCANDONE;
|
||||||
switch(rep) {
|
switch(rep) {
|
||||||
@ -1147,7 +1093,7 @@ t_safety(rep, count, persistent, safety) {
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
t_after(rep, count, outsafety) {
|
int t_after(int rep, int count, int outsafety) {
|
||||||
if (count == 0 && (rep == STAR || rep == PLUS)) {
|
if (count == 0 && (rep == STAR || rep == PLUS)) {
|
||||||
return SAFESCANDONE;
|
return SAFESCANDONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
* This file is a mess, it should be cleaned up some time.
|
* This file is a mess, it should be cleaned up some time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "io.h"
|
# include "io.h"
|
||||||
# include "extern.h"
|
# include "extern.h"
|
||||||
@ -25,18 +27,16 @@
|
|||||||
# include "assert.h"
|
# include "assert.h"
|
||||||
# include "cclass.h"
|
# include "cclass.h"
|
||||||
|
|
||||||
# ifndef NORCSID
|
#include "LLgen.h"
|
||||||
static string rcsid3 = "$Id$";
|
|
||||||
#endif /* NORCSID */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some codestrings used more than once
|
* Some codechar *s used more than once
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static string c_arrend = "0 };\n";
|
static char * c_arrend = "0 };\n";
|
||||||
static string c_close = "}\n";
|
static char * c_close = "}\n";
|
||||||
static string c_break = "break;\n";
|
static char * c_break = "break;\n";
|
||||||
static string c_read = "LLread();\n";
|
static char * c_read = "LLread();\n";
|
||||||
|
|
||||||
/* Some constants used for reading from the action file */
|
/* Some constants used for reading from the action file */
|
||||||
# define ENDDECL 0400
|
# define ENDDECL 0400
|
||||||
@ -47,65 +47,28 @@ static int firsts; /* are there any? */
|
|||||||
static int listcount;
|
static int listcount;
|
||||||
|
|
||||||
/* In this file the following routines are defined: */
|
/* In this file the following routines are defined: */
|
||||||
extern gencode();
|
|
||||||
STATIC opentemp();
|
|
||||||
STATIC geninclude();
|
|
||||||
STATIC genrecovery();
|
|
||||||
#ifdef NON_CORRECTING
|
|
||||||
STATIC genncrecovery();
|
|
||||||
#endif
|
|
||||||
STATIC string genname();
|
|
||||||
STATIC generate();
|
|
||||||
STATIC prset();
|
|
||||||
STATIC macro();
|
|
||||||
STATIC controlline();
|
|
||||||
STATIC getparams();
|
|
||||||
STATIC getansiparams();
|
|
||||||
STATIC genprototypes();
|
|
||||||
STATIC gettok();
|
|
||||||
STATIC rulecode();
|
|
||||||
STATIC int * dopush();
|
|
||||||
STATIC int * mk_tokenlist();
|
|
||||||
STATIC getaction();
|
|
||||||
STATIC alternation();
|
|
||||||
STATIC codeforterm();
|
|
||||||
STATIC genswhead();
|
|
||||||
STATIC gencases();
|
|
||||||
STATIC genpush();
|
|
||||||
STATIC genpop();
|
|
||||||
STATIC genincrdecr();
|
|
||||||
STATIC add_cases();
|
|
||||||
STATIC int analyze_switch();
|
|
||||||
STATIC out_list();
|
|
||||||
STATIC genextname();
|
|
||||||
STATIC correct_prefix();
|
|
||||||
|
|
||||||
# define NOPOP -20000
|
# define NOPOP -20000
|
||||||
|
|
||||||
p_mem alloc(), ralloc();
|
|
||||||
|
|
||||||
doclose(f)
|
void doclose(FILE *f)
|
||||||
FILE *f;
|
|
||||||
{
|
{
|
||||||
if (ferror(f) != 0) {
|
if (ferror(f) != 0) {
|
||||||
fatal(0,"Write error on temporary");
|
fatal(0,"Write error on temporary", NULL, NULL);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int *
|
STATIC int *mk_tokenlist()
|
||||||
mk_tokenlist()
|
|
||||||
{
|
{
|
||||||
register int i = ntokens;
|
int i = ntokens;
|
||||||
register int *p = (int *)alloc((unsigned)(i * sizeof(int))) + i;
|
int *p = (int *)alloc((unsigned)(i * sizeof(int))) + i;
|
||||||
|
|
||||||
while (i--) *--p = -1;
|
while (i--) *--p = -1;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genhdr()
|
||||||
genhdr()
|
|
||||||
{
|
{
|
||||||
if (!firsts) fputs("#define LLNOFIRSTS\n", fpars);
|
if (!firsts) fputs("#define LLNOFIRSTS\n", fpars);
|
||||||
if (ansi_c) fputs("#define LL_ANSI_C 1\n", fpars);
|
if (ansi_c) fputs("#define LL_ANSI_C 1\n", fpars);
|
||||||
@ -119,12 +82,12 @@ genhdr()
|
|||||||
copyfile(incl_file);
|
copyfile(incl_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
gencode(argc) {
|
void gencode(int argc) {
|
||||||
register p_file p = files;
|
p_file p = files;
|
||||||
|
|
||||||
/* Set up for code generation */
|
/* Set up for code generation */
|
||||||
if ((fact = fopen(f_temp,"r")) == NULL) {
|
if ((fact = fopen(f_temp,"r")) == NULL) {
|
||||||
fatal(0,e_noopen,f_temp);
|
fatal(0,e_noopen,f_temp, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
@ -157,22 +120,20 @@ gencode(argc) {
|
|||||||
fclose(fact);
|
fclose(fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void opentemp(char *str) {
|
||||||
opentemp(str) string str; {
|
|
||||||
|
|
||||||
if ((fpars = fopen(f_pars,"w")) == NULL) {
|
if ((fpars = fopen(f_pars,"w")) == NULL) {
|
||||||
fatal(0,e_noopen,f_pars);
|
fatal(0,e_noopen,f_pars, NULL);
|
||||||
}
|
}
|
||||||
if (!str) str = ".";
|
if (!str) str = ".";
|
||||||
fprintf(fpars,LLgenid,str);
|
fprintf(fpars,LLgenid,str);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void geninclude() {
|
||||||
geninclude() {
|
p_token p;
|
||||||
register p_token p;
|
|
||||||
int maxno = 0;
|
int maxno = 0;
|
||||||
|
|
||||||
opentemp((string) 0);
|
opentemp((char *) 0);
|
||||||
for (p = tokens; p < maxt; p++) {
|
for (p = tokens; p < maxt; p++) {
|
||||||
if (p->t_tokno > maxno) maxno = p->t_tokno;
|
if (p->t_tokno > maxno) maxno = p->t_tokno;
|
||||||
if (p->t_tokno >= 0400) {
|
if (p->t_tokno >= 0400) {
|
||||||
@ -192,18 +153,17 @@ geninclude() {
|
|||||||
install(f_include, ".");
|
install(f_include, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genrecovery() {
|
||||||
genrecovery() {
|
FILE *f;
|
||||||
register FILE *f;
|
p_token t;
|
||||||
register p_token t;
|
int *q;
|
||||||
register int *q;
|
p_nont p;
|
||||||
register p_nont p;
|
p_set *psetl;
|
||||||
register p_set *psetl;
|
|
||||||
int *index;
|
int *index;
|
||||||
int i;
|
int i;
|
||||||
register p_start st;
|
p_start st;
|
||||||
|
|
||||||
opentemp((string) 0);
|
opentemp((char *) 0);
|
||||||
f = fpars;
|
f = fpars;
|
||||||
correct_prefix();
|
correct_prefix();
|
||||||
genhdr();
|
genhdr();
|
||||||
@ -304,16 +264,15 @@ genrecovery() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
STATIC
|
STATIC void genncrecovery() {
|
||||||
genncrecovery() {
|
FILE *f;
|
||||||
register FILE *f;
|
p_token t;
|
||||||
register p_token t;
|
int *q;
|
||||||
register int *q;
|
|
||||||
int *index;
|
int *index;
|
||||||
|
|
||||||
/* Generate the non-correcting error recovery file */
|
/* Generate the non-correcting error recovery file */
|
||||||
|
|
||||||
opentemp((string) 0);
|
opentemp((char *) 0);
|
||||||
f = fpars;
|
f = fpars;
|
||||||
|
|
||||||
genhdr();
|
genhdr();
|
||||||
@ -343,15 +302,14 @@ genncrecovery() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC
|
STATIC void generate(p_file f) {
|
||||||
generate(f) p_file f; {
|
|
||||||
/*
|
/*
|
||||||
* Generates a parsing routine for every nonterminal
|
* Generates a parsing routine for every nonterminal
|
||||||
*/
|
*/
|
||||||
register int s;
|
int s;
|
||||||
register p_nont p;
|
p_nont p;
|
||||||
int i;
|
int i;
|
||||||
register p_first ff;
|
p_first ff;
|
||||||
int mustpop;
|
int mustpop;
|
||||||
int is_first = 1;
|
int is_first = 1;
|
||||||
|
|
||||||
@ -413,10 +371,9 @@ generate(f) p_file f; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void prset(p_set p) {
|
||||||
prset(p) p_set p; {
|
int k;
|
||||||
register int k;
|
unsigned i;
|
||||||
register unsigned i;
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
j = nbytes;
|
j = nbytes;
|
||||||
@ -434,8 +391,7 @@ prset(p) p_set p; {
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void macro(char * s, p_nont n) {
|
||||||
macro(s,n) string s; p_nont n; {
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = findindex(n->n_first);
|
i = findindex(n->n_first);
|
||||||
@ -449,29 +405,27 @@ macro(s,n) string s; p_nont n; {
|
|||||||
fprintf(fpars,"#define %s(x) LLfirst((x), %d)\n", s, i);
|
fprintf(fpars,"#define %s(x) LLfirst((x), %d)\n", s, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void controlline() {
|
||||||
controlline() {
|
|
||||||
/* Copy a compiler control line */
|
/* Copy a compiler control line */
|
||||||
register int l;
|
int l;
|
||||||
register FILE *f1,*f2;
|
FILE *f1,*f2;
|
||||||
|
|
||||||
f1 = fact; f2 = fpars;
|
f1 = fact; f2 = fpars;
|
||||||
l = getc(f1);
|
l = getc(f1);
|
||||||
assert(l == '\0');
|
assert(l == '\0');
|
||||||
do {
|
do {
|
||||||
l = getc(f1);
|
l = getc(f1);
|
||||||
if (l == EOF) fatal(0, "temp file mangled");
|
if (l == EOF) fatal(0, "temp file mangled", NULL, NULL);
|
||||||
putc(l,f2);
|
putc(l,f2);
|
||||||
} while ( l != '\n' ) ;
|
} while ( l != '\n' ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void getparams() {
|
||||||
getparams() {
|
|
||||||
/* getparams is called if a nonterminal has parameters. The names
|
/* getparams is called if a nonterminal has parameters. The names
|
||||||
* of the parameters have to be found, and they should be declared
|
* of the parameters have to be found, and they should be declared
|
||||||
*/
|
*/
|
||||||
long off;
|
long off;
|
||||||
register int l;
|
int l;
|
||||||
long ftell();
|
long ftell();
|
||||||
char first;
|
char first;
|
||||||
char add_semi = ' ';
|
char add_semi = ' ';
|
||||||
@ -508,15 +462,13 @@ getparams() {
|
|||||||
fprintf(fpars, "%c\n",add_semi);
|
fprintf(fpars, "%c\n",add_semi);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genprototypes(p_file f)
|
||||||
genprototypes(f)
|
|
||||||
register p_file f;
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Generate prototypes for all nonterminals
|
* Generate prototypes for all nonterminals
|
||||||
*/
|
*/
|
||||||
register int i;
|
int i;
|
||||||
register p_nont p;
|
p_nont p;
|
||||||
long off = ftell(fact);
|
long off = ftell(fact);
|
||||||
|
|
||||||
fputs("#if LL_ANSI_C\n", fpars);
|
fputs("#if LL_ANSI_C\n", fpars);
|
||||||
@ -555,13 +507,12 @@ genprototypes(f)
|
|||||||
fputs("#endif\n", fpars);
|
fputs("#endif\n", fpars);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void getansiparams(int mkdef) {
|
||||||
getansiparams(mkdef) {
|
|
||||||
/* getansiparams is called if a nonterminal has parameters
|
/* getansiparams is called if a nonterminal has parameters
|
||||||
* and an ANSI C function definition/declaration has to be produced.
|
* and an ANSI C function definition/declaration has to be produced.
|
||||||
* If a definition has to be produced, "mkdef" is set to 1.
|
* If a definition has to be produced, "mkdef" is set to 1.
|
||||||
*/
|
*/
|
||||||
register int l;
|
int l;
|
||||||
int delayed = 0;
|
int delayed = 0;
|
||||||
|
|
||||||
ltext[0] = '\0';
|
ltext[0] = '\0';
|
||||||
@ -586,12 +537,11 @@ getansiparams(mkdef) {
|
|||||||
fprintf(fpars, ") %c\n", mkdef ? ' ' : ';');
|
fprintf(fpars, ") %c\n", mkdef ? ' ' : ';');
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC int gettok() {
|
||||||
gettok() {
|
|
||||||
/* Read from the action file. */
|
/* Read from the action file. */
|
||||||
register int ch;
|
int ch;
|
||||||
register string c;
|
char *c;
|
||||||
register FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fact;
|
f = fact;
|
||||||
ch = getc(f);
|
ch = getc(f);
|
||||||
@ -624,15 +574,14 @@ gettok() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void rulecode(p_gram p, int safety, int mustscan, int mustpop) {
|
||||||
rulecode(p,safety,mustscan,mustpop) register p_gram p; {
|
|
||||||
/*
|
/*
|
||||||
* Code for a production rule.
|
* Code for a production rule.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
register int toplevel = 1;
|
int toplevel = 1;
|
||||||
register FILE *f;
|
FILE *f;
|
||||||
register int *ppu;
|
int *ppu;
|
||||||
int *pushlist;
|
int *pushlist;
|
||||||
int *ppushlist;
|
int *ppushlist;
|
||||||
|
|
||||||
@ -663,8 +612,8 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
|
|||||||
return;
|
return;
|
||||||
case LITERAL :
|
case LITERAL :
|
||||||
case TERMINAL : {
|
case TERMINAL : {
|
||||||
register p_token t;
|
p_token t;
|
||||||
string s;
|
char * s;
|
||||||
|
|
||||||
t = &tokens[g_getcont(p)];
|
t = &tokens[g_getcont(p)];
|
||||||
if (toplevel == 0) {
|
if (toplevel == 0) {
|
||||||
@ -694,7 +643,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
|
|||||||
safety = NOSCANDONE;
|
safety = NOSCANDONE;
|
||||||
break; }
|
break; }
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n = &nonterms[g_getcont(p)];
|
p_nont n = &nonterms[g_getcont(p)];
|
||||||
|
|
||||||
if (safety == NOSCANDONE &&
|
if (safety == NOSCANDONE &&
|
||||||
getntsafe(n) < NOSCANDONE) {
|
getntsafe(n) < NOSCANDONE) {
|
||||||
@ -734,13 +683,11 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void alternation(p_gram pp, int safety, int mustscan, int mustpop, int lb)
|
||||||
alternation(pp, safety, mustscan, mustpop, lb)
|
|
||||||
p_gram pp;
|
|
||||||
{
|
{
|
||||||
register p_gram p = pp;
|
p_gram p = pp;
|
||||||
register FILE *f = fpars;
|
FILE *f = fpars;
|
||||||
register p_link l;
|
p_link l;
|
||||||
int hulp, hulp1,hulp2;
|
int hulp, hulp1,hulp2;
|
||||||
int haddefault = 0;
|
int haddefault = 0;
|
||||||
int nsafe;
|
int nsafe;
|
||||||
@ -891,12 +838,12 @@ alternation(pp, safety, mustscan, mustpop, lb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC int *
|
STATIC int *
|
||||||
dopush(p,safety,toplevel,pp) register p_gram p; int **pp; {
|
dopush(p,safety,toplevel,pp) p_gram p; int **pp; {
|
||||||
/*
|
/*
|
||||||
* The safety only matters if toplevel != 0
|
* The safety only matters if toplevel != 0
|
||||||
*/
|
*/
|
||||||
unsigned int i = 100;
|
unsigned int i = 100;
|
||||||
register int *ip = (int *) alloc(100 * sizeof(int));
|
int *ip = (int *) alloc(100 * sizeof(int));
|
||||||
|
|
||||||
*pp = ip;
|
*pp = ip;
|
||||||
|
|
||||||
@ -912,7 +859,7 @@ dopush(p,safety,toplevel,pp) register p_gram p; int **pp; {
|
|||||||
case ALTERNATION :
|
case ALTERNATION :
|
||||||
return ip;
|
return ip;
|
||||||
case TERM : {
|
case TERM : {
|
||||||
register p_term q;
|
p_term q;
|
||||||
int rep_kind, rep_count;
|
int rep_kind, rep_count;
|
||||||
|
|
||||||
q = g_getterm(p);
|
q = g_getterm(p);
|
||||||
@ -934,7 +881,7 @@ dopush(p,safety,toplevel,pp) register p_gram p; int **pp; {
|
|||||||
if (toplevel == 0) *ip++ = -(g_getcont(p)+1);
|
if (toplevel == 0) *ip++ = -(g_getcont(p)+1);
|
||||||
break;
|
break;
|
||||||
case NONTERM : {
|
case NONTERM : {
|
||||||
register p_nont n;
|
p_nont n;
|
||||||
|
|
||||||
n = &nonterms[g_getcont(p)];
|
n = &nonterms[g_getcont(p)];
|
||||||
if (toplevel == 0 ||
|
if (toplevel == 0 ||
|
||||||
@ -955,14 +902,13 @@ dopush(p,safety,toplevel,pp) register p_gram p; int **pp; {
|
|||||||
|
|
||||||
# define max(a,b) ((a) < (b) ? (b) : (a))
|
# define max(a,b) ((a) < (b) ? (b) : (a))
|
||||||
|
|
||||||
STATIC
|
STATIC void getaction(int flag) {
|
||||||
getaction(flag) {
|
|
||||||
/* Read an action from the action file.
|
/* Read an action from the action file.
|
||||||
* flag = 1 if it is an action,
|
* flag = 1 if it is an action,
|
||||||
* 0 when reading parameters
|
* 0 when reading parameters
|
||||||
*/
|
*/
|
||||||
register int ch;
|
int ch;
|
||||||
register FILE *f;
|
FILE *f;
|
||||||
int mark = 0;
|
int mark = 0;
|
||||||
|
|
||||||
if (flag == 1) {
|
if (flag == 1) {
|
||||||
@ -991,14 +937,13 @@ getaction(flag) {
|
|||||||
if (flag) fputs("\n",f);
|
if (flag) fputs("\n",f);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC int codeforterm(p_term q, int safety, int toplevel) {
|
||||||
codeforterm(q,safety,toplevel) register p_term q; {
|
|
||||||
/*
|
/*
|
||||||
* Generate code for a term
|
* Generate code for a term
|
||||||
*/
|
*/
|
||||||
register FILE *f = fpars;
|
FILE *f = fpars;
|
||||||
register int rep_count = r_getnum(q);
|
int rep_count = r_getnum(q);
|
||||||
register int rep_kind = r_getkind(q);
|
int rep_kind = r_getkind(q);
|
||||||
int term_is_persistent = (q->t_flags & PERSISTENT);
|
int term_is_persistent = (q->t_flags & PERSISTENT);
|
||||||
int ispushed = NOPOP;
|
int ispushed = NOPOP;
|
||||||
|
|
||||||
@ -1024,7 +969,7 @@ codeforterm(q,safety,toplevel) register p_term q; {
|
|||||||
}
|
}
|
||||||
if (rep_count) {
|
if (rep_count) {
|
||||||
/* N > 0, so generate fixed forloop */
|
/* N > 0, so generate fixed forloop */
|
||||||
fputs("{\nregister LL_i;\n", f);
|
fputs("{\nLL_i;\n", f);
|
||||||
assert(ispushed != NOPOP);
|
assert(ispushed != NOPOP);
|
||||||
fprintf(f, "for (LL_i = %d; LL_i >= 0; LL_i--) {\n", rep_count - 1);
|
fprintf(f, "for (LL_i = %d; LL_i >= 0; LL_i--) {\n", rep_count - 1);
|
||||||
if (rep_kind == FIXED) {
|
if (rep_kind == FIXED) {
|
||||||
@ -1075,18 +1020,17 @@ codeforterm(q,safety,toplevel) register p_term q; {
|
|||||||
if (rep_kind != OPT && (rep_kind != FIXED || rep_count > 0)) {
|
if (rep_kind != OPT && (rep_kind != FIXED || rep_count > 0)) {
|
||||||
fputs(c_close, f); /* Close for */
|
fputs(c_close, f); /* Close for */
|
||||||
if (rep_count > 0) {
|
if (rep_count > 0) {
|
||||||
fputs(c_close, f);/* Close Register ... */
|
fputs(c_close, f);/* Close ... */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t_after(rep_kind, rep_count, gettout(q));
|
return t_after(rep_kind, rep_count, gettout(q));
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genswhead(p_term q, int rep_kind, int rep_count, int safety, int ispushed) {
|
||||||
genswhead(q, rep_kind, rep_count, safety, ispushed) register p_term q; {
|
|
||||||
/*
|
/*
|
||||||
* Generate switch statement for term q
|
* Generate switch statement for term q
|
||||||
*/
|
*/
|
||||||
register FILE *f = fpars;
|
FILE *f = fpars;
|
||||||
p_set p1;
|
p_set p1;
|
||||||
p_set setalloc();
|
p_set setalloc();
|
||||||
int hulp1 = 0, hulp2;
|
int hulp1 = 0, hulp2;
|
||||||
@ -1180,9 +1124,7 @@ genswhead(q, rep_kind, rep_count, safety, ispushed) register p_term q; {
|
|||||||
free((p_mem) tokenlist);
|
free((p_mem) tokenlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void gencases(int *tokenlist, int caseno, int compacted)
|
||||||
gencases(tokenlist, caseno, compacted)
|
|
||||||
int *tokenlist;
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* setp points to a bitset indicating which cases must
|
* setp points to a bitset indicating which cases must
|
||||||
@ -1199,32 +1141,33 @@ gencases(tokenlist, caseno, compacted)
|
|||||||
* labeledstatement : labels statement ;
|
* labeledstatement : labels statement ;
|
||||||
* labels : labels label | ;
|
* labels : labels label | ;
|
||||||
*/
|
*/
|
||||||
register p_token p;
|
p_token p;
|
||||||
register int i;
|
int i;
|
||||||
|
|
||||||
if (compacted) fprintf(fpars, "case %d :\n", caseno);
|
if (compacted) fprintf(fpars, "case %d :\n", caseno);
|
||||||
for (i = 0, p = tokens; i < ntokens; i++, p++) {
|
for (i = 0, p = tokens; i < ntokens; i++, p++) {
|
||||||
if (tokenlist[i] == caseno) {
|
if (tokenlist[i] == caseno)
|
||||||
fprintf(fpars,
|
{
|
||||||
compacted ?
|
if (compacted)
|
||||||
(p->t_tokno < 0400 ? "/* case '%s' */\n" :
|
fprintf(fpars, p->t_tokno < 0400 ? "/* case '%s' */\n" :
|
||||||
"/* case %s */\n") :
|
"/* case %s */\n",
|
||||||
p->t_tokno<0400 ? "case /* '%s' */ %d : ;\n"
|
p->t_string);
|
||||||
: "case /* %s */ %d : ;\n",
|
else
|
||||||
p->t_string, i);
|
fprintf(fpars, p->t_tokno<0400 ? "case /* '%s' */ %d : ;\n" :
|
||||||
|
"case /* %s */ %d : ;\n",
|
||||||
|
p->t_string, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char namebuf[20];
|
static char namebuf[20];
|
||||||
|
|
||||||
STATIC string
|
STATIC char *genname(char * s) {
|
||||||
genname(s) string s; {
|
|
||||||
/*
|
/*
|
||||||
* Generate a target file name from the
|
* Generate a target file name from the
|
||||||
* source file name s.
|
* source file name s.
|
||||||
*/
|
*/
|
||||||
register string c,d;
|
char *c, *d;
|
||||||
|
|
||||||
c = namebuf;
|
c = namebuf;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
@ -1238,7 +1181,7 @@ genname(s) string s; {
|
|||||||
for (d = c; --d > namebuf;) if (*d == '.') break;
|
for (d = c; --d > namebuf;) if (*d == '.') break;
|
||||||
if (d == namebuf) d = c;
|
if (d == namebuf) d = c;
|
||||||
if (d >= &namebuf[12]) {
|
if (d >= &namebuf[12]) {
|
||||||
fatal(0,"%s : filename too long",namebuf);
|
fatal(0,"%s : filename too long",namebuf, NULL);
|
||||||
}
|
}
|
||||||
*d++ = '.';
|
*d++ = '.';
|
||||||
*d++ = 'c';
|
*d++ = 'c';
|
||||||
@ -1246,13 +1189,11 @@ genname(s) string s; {
|
|||||||
return namebuf;
|
return namebuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genpush(int d) {
|
||||||
genpush(d) {
|
|
||||||
genincrdecr("incr", d);
|
genincrdecr("incr", d);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genincrdecr(char *s, int d) {
|
||||||
genincrdecr(s, d) string s; {
|
|
||||||
if (d == NOPOP) return;
|
if (d == NOPOP) return;
|
||||||
if (d >= 0) {
|
if (d >= 0) {
|
||||||
fprintf(fpars, "LLs%s(%d);\n", s, d / nbytes);
|
fprintf(fpars, "LLs%s(%d);\n", s, d / nbytes);
|
||||||
@ -1261,16 +1202,13 @@ genincrdecr(s, d) string s; {
|
|||||||
fprintf(fpars, "LLt%s(%d);\n", s, -(d + 1));
|
fprintf(fpars, "LLt%s(%d);\n", s, -(d + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genpop(int d) {
|
||||||
genpop(d) {
|
|
||||||
genincrdecr("decr", d);
|
genincrdecr("decr", d);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int
|
STATIC int analyze_switch(int *tokenlist)
|
||||||
analyze_switch(tokenlist)
|
|
||||||
int *tokenlist;
|
|
||||||
{
|
{
|
||||||
register int i;
|
int i;
|
||||||
int ncases = 0;
|
int ncases = 0;
|
||||||
int percentage;
|
int percentage;
|
||||||
int maxcase = 0, mincase = 0;
|
int maxcase = 0, mincase = 0;
|
||||||
@ -1290,12 +1228,9 @@ analyze_switch(tokenlist)
|
|||||||
return percentage >= low_percentage && percentage <= high_percentage;
|
return percentage >= low_percentage && percentage <= high_percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void add_cases(p_set s, int *tokenlist, int caseno)
|
||||||
add_cases(s, tokenlist, caseno)
|
|
||||||
p_set s;
|
|
||||||
int *tokenlist;
|
|
||||||
{
|
{
|
||||||
register int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ntokens; i++) {
|
for (i = 0; i < ntokens; i++) {
|
||||||
if (IN(s, i)) {
|
if (IN(s, i)) {
|
||||||
@ -1304,12 +1239,10 @@ add_cases(s, tokenlist, caseno)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void out_list(int *tokenlist, int listno, int casecnt)
|
||||||
out_list(tokenlist, listno, casecnt)
|
|
||||||
int *tokenlist;
|
|
||||||
{
|
{
|
||||||
register int i;
|
int i;
|
||||||
register FILE *f = fpars;
|
FILE *f = fpars;
|
||||||
|
|
||||||
fprintf(f, "static %s LL%d_tklist[] = {",
|
fprintf(f, "static %s LL%d_tklist[] = {",
|
||||||
casecnt <= 127 ? "char" : "short",
|
casecnt <= 127 ? "char" : "short",
|
||||||
@ -1322,19 +1255,15 @@ out_list(tokenlist, listno, casecnt)
|
|||||||
fprintf(f, "switch(LL%d_tklist[LLcsymb]) {\n", listno);
|
fprintf(f, "switch(LL%d_tklist[LLcsymb]) {\n", listno);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void genextname(int d, char *s, FILE *f)
|
||||||
genextname(d, s, f)
|
|
||||||
char *s;
|
|
||||||
FILE *f;
|
|
||||||
{
|
{
|
||||||
fprintf(f, "%s%d_%s", prefix ? prefix : "LL", d, s);
|
fprintf(f, "%s%d_%s", prefix ? prefix : "LL", d, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void correct_prefix()
|
||||||
correct_prefix()
|
|
||||||
{
|
{
|
||||||
register FILE *f = fpars;
|
FILE *f = fpars;
|
||||||
register char *s = prefix;
|
char *s = prefix;
|
||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
fprintf(f, "#define LLsymb %ssymb\n", s);
|
fprintf(f, "#define LLsymb %ssymb\n", s);
|
||||||
|
|||||||
@ -16,20 +16,24 @@
|
|||||||
* Machine dependant things
|
* Machine dependant things
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
|
|
||||||
|
#include "LLgen.h"
|
||||||
|
|
||||||
# ifndef NORCSID
|
# ifndef NORCSID
|
||||||
static string rcsid5 = "$Id$";
|
static string rcsid5 = "$Id$";
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* In this file the following routines are defined: */
|
/* In this file the following routines are defined: */
|
||||||
//extern UNLINK();
|
/* extern UNLINK(); */
|
||||||
//extern RENAME();
|
/* extern RENAME(); */
|
||||||
//extern string libpath();
|
/* extern string libpath(); */
|
||||||
|
|
||||||
UNLINK(x) string x; {
|
void UNLINK(string x) {
|
||||||
/* Must remove the file "x" */
|
/* Must remove the file "x" */
|
||||||
|
|
||||||
#ifdef USE_SYS
|
#ifdef USE_SYS
|
||||||
@ -39,14 +43,14 @@ UNLINK(x) string x; {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RENAME(x,y) string x,y; {
|
void RENAME(char *x, char *y) {
|
||||||
/* Must move the file "x" to the file "y" */
|
/* Must move the file "x" to the file "y" */
|
||||||
|
|
||||||
#ifdef USE_SYS
|
#ifdef USE_SYS
|
||||||
if(! sys_rename(x,y)) fatal(1,"Cannot rename to %s",y);
|
if(! sys_rename(x,y)) fatal(1,"Cannot rename to %s",y);
|
||||||
#else
|
#else
|
||||||
if (rename(x, y) == -1)
|
if (rename(x, y) == -1)
|
||||||
fatal(1, "Cannot rename to %s", y);
|
fatal(1, "Cannot rename to %s", y, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +59,9 @@ libpath(s) string s; {
|
|||||||
/* Must deliver a full pathname to the library file "s" */
|
/* Must deliver a full pathname to the library file "s" */
|
||||||
|
|
||||||
register string p;
|
register string p;
|
||||||
register length;
|
int length;
|
||||||
p_mem alloc();
|
p_mem alloc();
|
||||||
// string strcpy(), strcat();
|
/* string strcpy(), strcat(); */
|
||||||
|
|
||||||
char* libdir = getenv("LLGEN_LIB_DIR");
|
char* libdir = getenv("LLGEN_LIB_DIR");
|
||||||
if (!libdir)
|
if (!libdir)
|
||||||
|
|||||||
@ -16,31 +16,27 @@
|
|||||||
* Contains main program, and some error message routines
|
* Contains main program, and some error message routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "extern.h"
|
||||||
|
#include "sets.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "LLgen.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
# include "types.h"
|
#include <unistd.h>
|
||||||
# include "io.h"
|
|
||||||
# include "extern.h"
|
|
||||||
# include "sets.h"
|
|
||||||
# include "assert.h"
|
|
||||||
|
|
||||||
# ifndef NORCSID
|
|
||||||
|
void *sbrk(void *addr);
|
||||||
|
char *mktemp(char *template);
|
||||||
|
|
||||||
|
#ifndef NORCSID
|
||||||
static string rcsid6 = "$Id$";
|
static string rcsid6 = "$Id$";
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
/* In this file the following routines are defined: */
|
|
||||||
extern int main();
|
|
||||||
STATIC readgrammar();
|
|
||||||
STATIC doparse();
|
|
||||||
extern error();
|
|
||||||
extern fatal();
|
|
||||||
extern comfatal();
|
|
||||||
extern copyfile();
|
|
||||||
extern install();
|
|
||||||
extern char *mktemp();
|
|
||||||
extern char *sbrk();
|
|
||||||
|
|
||||||
main(argc,argv) register string argv[]; {
|
int main(int argc, char *argv[]) {
|
||||||
register string arg;
|
register string arg;
|
||||||
string libpath();
|
string libpath();
|
||||||
char *beg_sbrk = 0;
|
char *beg_sbrk = 0;
|
||||||
@ -130,7 +126,7 @@ main(argc,argv) register string argv[]; {
|
|||||||
argc--;
|
argc--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) beg_sbrk = sbrk(0);
|
if (verbose) beg_sbrk = sbrk(NULL);
|
||||||
|
|
||||||
#ifdef NON_CORRECTING
|
#ifdef NON_CORRECTING
|
||||||
if ((subpars_sim) && (!non_corr)) {
|
if ((subpars_sim) && (!non_corr)) {
|
||||||
@ -207,13 +203,12 @@ main(argc,argv) register string argv[]; {
|
|||||||
fprintf(stderr, "number of tokens: %d\n", ntokens);
|
fprintf(stderr, "number of tokens: %d\n", ntokens);
|
||||||
fprintf(stderr, "number of term structures: %d\n", nterms);
|
fprintf(stderr, "number of term structures: %d\n", nterms);
|
||||||
fprintf(stderr, "number of alternation structures: %d\n", nalts);
|
fprintf(stderr, "number of alternation structures: %d\n", nalts);
|
||||||
fprintf(stderr, "total memory used: %ld\n", (long)(sbrk(0) - beg_sbrk));
|
fprintf(stderr, "total memory used: %ld\n", (long)((long)sbrk(0) - (long)beg_sbrk));
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void readgrammar(int argc, char *argv[]) {
|
||||||
readgrammar(argc,argv) char *argv[]; {
|
|
||||||
/*
|
/*
|
||||||
* Do just what the name suggests : read the grammar
|
* Do just what the name suggests : read the grammar
|
||||||
*/
|
*/
|
||||||
@ -233,7 +228,7 @@ readgrammar(argc,argv) char *argv[]; {
|
|||||||
} else {
|
} else {
|
||||||
while (argc--) {
|
while (argc--) {
|
||||||
if ((finput = fopen(f_input=argv[1],"r")) == NULL) {
|
if ((finput = fopen(f_input=argv[1],"r")) == NULL) {
|
||||||
fatal(0,e_noopen,f_input);
|
fatal(0, e_noopen, f_input, NULL);
|
||||||
}
|
}
|
||||||
doparse(p++);
|
doparse(p++);
|
||||||
argv++;
|
argv++;
|
||||||
@ -246,13 +241,12 @@ readgrammar(argc,argv) char *argv[]; {
|
|||||||
* There must be a start symbol!
|
* There must be a start symbol!
|
||||||
*/
|
*/
|
||||||
if (! nerrors && start == 0) {
|
if (! nerrors && start == 0) {
|
||||||
fatal(linecount,"Missing %%start");
|
fatal(linecount, "Missing %%start", NULL, NULL);
|
||||||
}
|
}
|
||||||
if (nerrors) comfatal();
|
if (nerrors) comfatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC void doparse(p_file p) {
|
||||||
doparse(p) register p_file p; {
|
|
||||||
|
|
||||||
linecount = 0;
|
linecount = 0;
|
||||||
p->f_name = f_input;
|
p->f_name = f_input;
|
||||||
@ -266,7 +260,7 @@ doparse(p) register p_file p; {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* VARARGS1 */
|
/* VARARGS1 */
|
||||||
error(lineno,s,t,u) string s,t,u; {
|
void error(int lineno, char *s, char *t, char *u) {
|
||||||
/*
|
/*
|
||||||
* Just an error message
|
* Just an error message
|
||||||
*/
|
*/
|
||||||
@ -279,7 +273,7 @@ error(lineno,s,t,u) string s,t,u; {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* VARARGS1 */
|
/* VARARGS1 */
|
||||||
warning(lineno,s,t,u) string s,t,u; {
|
void warning(int lineno, char *s, char *t, char *u) {
|
||||||
/*
|
/*
|
||||||
* Just a warning
|
* Just a warning
|
||||||
*/
|
*/
|
||||||
@ -292,7 +286,7 @@ warning(lineno,s,t,u) string s,t,u; {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* VARARGS1 */
|
/* VARARGS1 */
|
||||||
fatal(lineno,s,t,u) string s,t,u; {
|
void fatal(int lineno, char *s, char *t, char *u) {
|
||||||
/*
|
/*
|
||||||
* Fatal error
|
* Fatal error
|
||||||
*/
|
*/
|
||||||
@ -300,7 +294,7 @@ fatal(lineno,s,t,u) string s,t,u; {
|
|||||||
comfatal();
|
comfatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
comfatal() {
|
void comfatal(void) {
|
||||||
/*
|
/*
|
||||||
* Some common code for exit on errors
|
* Some common code for exit on errors
|
||||||
*/
|
*/
|
||||||
@ -313,7 +307,7 @@ comfatal() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
copyfile(file) string file; {
|
void copyfile(char *file) {
|
||||||
/*
|
/*
|
||||||
* Copies a file indicated by the parameter to filedescriptor fpars.
|
* Copies a file indicated by the parameter to filedescriptor fpars.
|
||||||
*/
|
*/
|
||||||
@ -321,13 +315,13 @@ copyfile(file) string file; {
|
|||||||
register FILE *f;
|
register FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(file,"r")) == NULL) {
|
if ((f = fopen(file,"r")) == NULL) {
|
||||||
fatal(0,"Cannot open library file %s, call an expert",file);
|
fatal(0,"Cannot open library file %s, call an expert",file, NULL);
|
||||||
}
|
}
|
||||||
while ((c = getc(f)) != EOF) putc(c,fpars);
|
while ((c = getc(f)) != EOF) putc(c,fpars);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
install(target, source) string target, source; {
|
void install(char *target, char *source) {
|
||||||
/*
|
/*
|
||||||
* Copy the temporary file generated from source to target
|
* Copy the temporary file generated from source to target
|
||||||
* if allowed (which means that the target must be generated
|
* if allowed (which means that the target must be generated
|
||||||
@ -341,7 +335,7 @@ install(target, source) string target, source; {
|
|||||||
* First open temporary, generated for source
|
* First open temporary, generated for source
|
||||||
*/
|
*/
|
||||||
if ((f1 = fopen(f_pars,"r")) == NULL) {
|
if ((f1 = fopen(f_pars,"r")) == NULL) {
|
||||||
fatal(0,e_noopen,f_pars);
|
fatal(0,e_noopen,f_pars, NULL);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Now open target for reading
|
* Now open target for reading
|
||||||
@ -371,7 +365,7 @@ install(target, source) string target, source; {
|
|||||||
*/
|
*/
|
||||||
if (c1 != c2) {
|
if (c1 != c2) {
|
||||||
if (cnt >= 0) {
|
if (cnt >= 0) {
|
||||||
fatal(0,"%s : not a file generated by LLgen",target);
|
fatal(0,"%s : not a file generated by LLgen",target, NULL);
|
||||||
}
|
}
|
||||||
RENAME(f_pars,target);
|
RENAME(f_pars,target);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
* [B | C]* becomes X; X: B X | C X | {empty} etc.
|
* [B | C]* becomes X; X: B X | C X | {empty} etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "extern.h"
|
# include "extern.h"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user