Better ANSI C compatibility and portability:

+ Addition of function prototypes and include files.
+ Change function definitions to ANSI C style.
- Remove support for generating K&R code.
- Remove mkstemp and replace by tmpnam (more portable but less safe)
This commit is contained in:
carl 2019-02-19 00:39:05 +08:00
parent 42bbdec82d
commit 10717cc791
21 changed files with 2424 additions and 2052 deletions

View file

@ -2,9 +2,6 @@
#include "Lpars.h" #include "Lpars.h"
#define LL_LEXI scanner #define LL_LEXI scanner
#define LLNOFIRSTS #define LLNOFIRSTS
#if __STDC__ || __cplusplus
#define LL_ANSI_C 1
#endif
#define LL_LEXI scanner #define LL_LEXI scanner
/* $Id$ */ /* $Id$ */
#ifdef LL_DEBUG #ifdef LL_DEBUG
@ -38,7 +35,6 @@ extern int LLstartsymb;
#define LLsincr(d) LLscnt[d]++ #define LLsincr(d) LLscnt[d]++
#define LLtincr(d) LLtcnt[d]++ #define LLtincr(d) LLtcnt[d]++
#if LL_ANSI_C
extern int LL_LEXI(void); extern int LL_LEXI(void);
extern void LLread(void); extern void LLread(void);
extern int LLskip(void); extern int LLskip(void);
@ -56,33 +52,15 @@ extern int LLfirst(int, int);
#if LL_NON_CORR #if LL_NON_CORR
extern void LLnc_recover(void); extern void LLnc_recover(void);
#endif #endif
#else /* not LL_ANSI_C */
extern LLread();
extern int LLskip();
extern int LLnext();
extern LLerror();
extern LLsafeerror();
extern LLnewlevel();
extern LLoldlevel();
#ifndef LL_FASTER
extern LLscan();
#endif
#ifndef LLNOFIRSTS
extern int LLfirst();
#endif
#if LL_NON_CORR
extern LLnc_recover();
#endif
#endif /* not LL_ANSI_C */
# line 20 "LLgen.g" # line 20 "LLgen.g"
# include <stdlib.h> #include <stdlib.h>
# include <string.h> #include <string.h>
# include "types.h" #include "types.h"
# include "io.h" #include "io.h"
# include "extern.h" #include "extern.h"
# include "assert.h" #include "assert.h"
# include "cclass.h" #include "cclass.h"
# ifndef NORCSID # ifndef NORCSID
static string rcsid = "$Id$"; static string rcsid = "$Id$";
@ -106,15 +84,14 @@ static int max_rules;
#define RULEINCR 32 #define RULEINCR 32
/* Here are defined : */ /* Here are defined : */
STATIC newnorder(); STATIC void newnorder(int index);
STATIC newtorder(); STATIC void newtorder(int index);
STATIC mkalt(); STATIC void mkalt(p_gram prod, int condition,int lc,register p_gram res);
STATIC mkterm(); STATIC void mkterm(p_gram prod, int flags,int lc,register p_gram result);
STATIC p_gram copyrule(); STATIC p_gram copyrule(register p_gram p,int length);
/* and of course LLparse() */ /* and of course LLparse() */
STATIC STATIC void newnorder(int index) {
newnorder(index) {
static int porder; static int porder;
if (norder != -1) { if (norder != -1) {
@ -125,8 +102,7 @@ newnorder(index) {
nonterms[porder].n_next = -1; nonterms[porder].n_next = -1;
} }
STATIC STATIC void newtorder(int index) {
newtorder(index) {
static int porder; static int porder;
if (torder != -1) { if (torder != -1) {
@ -137,7 +113,7 @@ newtorder(index) {
tokens[porder].t_next = -1; tokens[porder].t_next = -1;
} }
p_init() void p_init(void)
{ {
alt_table = (p_gram )alloc(ALTINCR*sizeof(t_gram)); alt_table = (p_gram )alloc(ALTINCR*sizeof(t_gram));
n_alts = 0; n_alts = 0;
@ -147,47 +123,31 @@ p_init()
max_rules = RULEINCR; max_rules = RULEINCR;
} }
#if LL_ANSI_C
static void LL1_def(void); static void LL1_def(void);
static void LL2_rule(void); static void LL2_rule(void);
static void LL3_listel(void); static void LL3_listel(void);
static void LL4_firsts(void); static void LL4_firsts(void);
static void LL5_productions( static void LL5_productions(
# line 246 "LLgen.g" # line 244 "LLgen.g"
p_gram *p) ; p_gram *p) ;
static void LL6_simpleproduction( static void LL6_simpleproduction(
# line 332 "LLgen.g" # line 330 "LLgen.g"
p_gram *p ,register int *conflres) ; p_gram *p ,register int *conflres) ;
static void LL7_elem( static void LL7_elem(
# line 480 "LLgen.g" # line 478 "LLgen.g"
register p_gram pres) ; register p_gram pres) ;
static void LL8_repeats( static void LL8_repeats(
# line 602 "LLgen.g" # line 600 "LLgen.g"
int *kind ,int *cnt) ; int *kind ,int *cnt) ;
static void LL9_number( static void LL9_number(
# line 619 "LLgen.g" # line 617 "LLgen.g"
int *t) ; int *t) ;
#else
static LL1_def();
static LL2_rule();
static LL3_listel();
static LL4_firsts();
static LL5_productions();
static LL6_simpleproduction();
static LL7_elem();
static LL8_repeats();
static LL9_number();
#endif
#if LL_ANSI_C
void void
#endif
LL0_spec( LL0_spec(
#if LL_ANSI_C
void void
#endif
) { ) {
LLsincr(0); LLsincr(0);
# line 96 "LLgen.g" # line 94 "LLgen.g"
{ acount = 0; p_init(); } { acount = 0; p_init(); }
for (;;) { for (;;) {
goto L_1; goto L_1;
@ -215,7 +175,7 @@ continue;
LLsdecr(0); LLsdecr(0);
break; break;
} }
# line 98 "LLgen.g" # line 96 "LLgen.g"
{ /* { /*
* Put an endmarker in temporary file * Put an endmarker in temporary file
*/ */
@ -226,15 +186,11 @@ break;
} }
} }
static static
#if LL_ANSI_C
void void
#endif
LL1_def( LL1_def(
#if LL_ANSI_C
void void
#endif
) { ) {
# line 108 "LLgen.g" # line 106 "LLgen.g"
register string p; register string p;
switch(LLcsymb) { switch(LLcsymb) {
case /* C_IDENT */ 2 : ; case /* C_IDENT */ 2 : ;
@ -275,13 +231,13 @@ LLtincr(2);
LLtincr(24); LLtincr(24);
LL_SAFE(C_START); LL_SAFE(C_START);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 118 "LLgen.g" # line 116 "LLgen.g"
{ p = store(lextoken.t_string); } { p = store(lextoken.t_string); }
LLtdecr(23); LLtdecr(23);
LL_NOSCANDONE(','); LL_NOSCANDONE(',');
LLtdecr(2); LLtdecr(2);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 123 "LLgen.g" # line 121 "LLgen.g"
{ /* { /*
* Put the declaration in the list * Put the declaration in the list
* of start symbols * of start symbols
@ -309,11 +265,11 @@ case /* C_LEXICAL */ 14 : ;
LLtincr(24); LLtincr(24);
LL_SAFE(C_LEXICAL); LL_SAFE(C_LEXICAL);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 149 "LLgen.g" # line 147 "LLgen.g"
{ if (!lexical) { { if (!lexical) {
lexical = store(lextoken.t_string); lexical = store(lextoken.t_string);
} }
else error(linecount,"Duplicate %%lexical"); else error(linecount,"Duplicate %%lexical", NULL);
} }
LLtdecr(24); LLtdecr(24);
LL_NOSCANDONE(';'); LL_NOSCANDONE(';');
@ -322,16 +278,16 @@ case /* C_PREFIX */ 15 : ;
LLtincr(24); LLtincr(24);
LL_SAFE(C_PREFIX); LL_SAFE(C_PREFIX);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 159 "LLgen.g" # line 157 "LLgen.g"
{ if (!prefix) { { if (!prefix) {
prefix = store(lextoken.t_string); prefix = store(lextoken.t_string);
if (strlen(prefix) > 6) { if (strlen(prefix) > 6) {
error(linecount, error(linecount,
"%%prefix too long"); "%%prefix too long",NULL);
prefix[6] = 0; prefix[6] = 0;
} }
} }
else error(linecount,"Duplicate %%prefix"); else error(linecount,"Duplicate %%prefix", NULL);
} }
LLtdecr(24); LLtdecr(24);
LL_NOSCANDONE(';'); LL_NOSCANDONE(';');
@ -340,25 +296,25 @@ case /* C_ONERROR */ 16 : ;
LLtincr(24); LLtincr(24);
LL_SAFE(C_ONERROR); LL_SAFE(C_ONERROR);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 171 "LLgen.g" # line 169 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (non_corr) { if (non_corr) {
warning(linecount, "%%onerror conflicts with -n option"); warning(linecount, "%%onerror conflicts with -n option", NULL);
} }
else else
#endif #endif
if (! onerror) { if (! onerror) {
onerror = store(lextoken.t_string); onerror = store(lextoken.t_string);
} }
else error(linecount,"Duplicate %%onerror"); else error(linecount,"Duplicate %%onerror", NULL);
} }
LLtdecr(24); LLtdecr(24);
LL_NOSCANDONE(';'); LL_NOSCANDONE(';');
break; break;
default: default:
LL_SSCANDONE(C_ACTION); LL_SSCANDONE(C_ACTION);
# line 184 "LLgen.g" # line 182 "LLgen.g"
{ acount++; } { acount++; }
break; break;
case /* C_FIRST */ 13 : ; case /* C_FIRST */ 13 : ;
@ -367,31 +323,23 @@ break;
} }
} }
static static
#if LL_ANSI_C
void void
#endif
LL3_listel( LL3_listel(
#if LL_ANSI_C
void void
#endif
) { ) {
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 194 "LLgen.g" # line 192 "LLgen.g"
{ p_gram temp = search(TERMINAL,lextoken.t_string,ENTERING); { p_gram temp = search(TERMINAL,lextoken.t_string,ENTERING);
newtorder(g_getcont(temp)); newtorder(g_getcont(temp));
tokens[g_getcont(temp)].t_lineno = linecount; tokens[g_getcont(temp)].t_lineno = linecount;
} }
} }
static static
#if LL_ANSI_C
void void
#endif
LL2_rule( LL2_rule(
#if LL_ANSI_C
void void
#endif
) { ) {
# line 200 "LLgen.g" # line 198 "LLgen.g"
register p_nont p; register p_nont p;
p_gram rr; p_gram rr;
register p_gram temp; register p_gram temp;
@ -402,7 +350,7 @@ LLtincr(25);
LLsincr(1); LLsincr(1);
LLtincr(24); LLtincr(24);
LL_SAFE(C_IDENT); LL_SAFE(C_IDENT);
# line 207 "LLgen.g" # line 205 "LLgen.g"
{ temp = search(NONTERM,lextoken.t_string,BOTH); { temp = search(NONTERM,lextoken.t_string,BOTH);
p = &nonterms[g_getcont(temp)]; p = &nonterms[g_getcont(temp)];
if (p->n_rule) { if (p->n_rule) {
@ -437,11 +385,11 @@ else if (LL_3 & 1) goto L_1;}
case /* C_PARAMS */ 6 : ; case /* C_PARAMS */ 6 : ;
LLtdecr(6); LLtdecr(6);
LL_SAFE(C_PARAMS); LL_SAFE(C_PARAMS);
# line 225 "LLgen.g" # line 223 "LLgen.g"
{ if (lextoken.t_num > 0) { { if (lextoken.t_num > 0) {
p->n_flags |= PARAMS; p->n_flags |= PARAMS;
if (lextoken.t_num > 15) { if (lextoken.t_num > 15) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters", NULL);
} }
else setntparams(p,lextoken.t_num); else setntparams(p,lextoken.t_num);
} }
@ -463,41 +411,34 @@ else if (LL_4 & 1) goto L_2;}
case /* C_ACTION */ 7 : ; case /* C_ACTION */ 7 : ;
LLtdecr(7); LLtdecr(7);
LL_SAFE(C_ACTION); LL_SAFE(C_ACTION);
# line 234 "LLgen.g" # line 232 "LLgen.g"
{ p->n_flags |= LOCALS; } { p->n_flags |= LOCALS; }
LLread(); LLread();
} }
} }
LLtdecr(25); LLtdecr(25);
LL_SCANDONE(':'); LL_SCANDONE(':');
# line 236 "LLgen.g" # line 234 "LLgen.g"
{ in_production = 1; } { in_production = 1; }
LLread(); LLread();
LLsdecr(1); LLsdecr(1);
LL5_productions( LL5_productions(
# line 237 "LLgen.g" # line 235 "LLgen.g"
&rr); &rr);
LLtdecr(24); LLtdecr(24);
LL_SCANDONE(';'); LL_SCANDONE(';');
# line 238 "LLgen.g" # line 236 "LLgen.g"
{ in_production = 0; } { in_production = 0; }
# line 243 "LLgen.g" # line 241 "LLgen.g"
{ nonterms[g_getcont(temp)].n_rule = rr;} { nonterms[g_getcont(temp)].n_rule = rr;}
} }
static static
#if LL_ANSI_C
void void
#endif
LL5_productions( LL5_productions(
#if LL_ANSI_C # line 244 "LLgen.g"
# line 246 "LLgen.g"
p_gram *p) p_gram *p)
#else
# line 246 "LLgen.g"
p) p_gram *p;
#endif
{ {
# line 250 "LLgen.g" # line 248 "LLgen.g"
p_gram prod; p_gram prod;
int conflres = 0; int conflres = 0;
int t = 0; int t = 0;
@ -506,12 +447,12 @@ p_gram *p)
int o_lc, n_lc; int o_lc, n_lc;
LLtincr(26); LLtincr(26);
# line 257 "LLgen.g" # line 255 "LLgen.g"
{ o_lc = linecount; } { o_lc = linecount; }
LL6_simpleproduction( LL6_simpleproduction(
# line 258 "LLgen.g" # line 256 "LLgen.g"
p,&conflres); p,&conflres);
# line 259 "LLgen.g" # line 257 "LLgen.g"
{ if (conflres & DEF) haddefault = 1; } { if (conflres & DEF) haddefault = 1; }
goto L_2; /* so that the label is used for certain */ goto L_2; /* so that the label is used for certain */
L_2: ; L_2: ;
@ -523,13 +464,13 @@ LLsdecr(1);
LLtincr(26); LLtincr(26);
for (;;) { for (;;) {
LL_SAFE('|'); LL_SAFE('|');
# line 261 "LLgen.g" # line 259 "LLgen.g"
{ n_lc = linecount; } { n_lc = linecount; }
LLread(); LLread();
LL6_simpleproduction( LL6_simpleproduction(
# line 262 "LLgen.g" # line 260 "LLgen.g"
&prod,&t); &prod,&t);
# line 263 "LLgen.g" # line 261 "LLgen.g"
{ if (n_alts >= max_alts-2) { { if (n_alts >= max_alts-2) {
alt_table = (p_gram ) ralloc( alt_table = (p_gram ) ralloc(
(p_mem) alt_table, (p_mem) alt_table,
@ -538,7 +479,7 @@ LL6_simpleproduction(
if (t & DEF) { if (t & DEF) {
if (haddefault) { if (haddefault) {
error(n_lc, error(n_lc,
"More than one %%default in alternation"); "More than one %%default in alternation", NULL);
} }
haddefault = 1; haddefault = 1;
} }
@ -566,10 +507,10 @@ continue;
LLtdecr(26); LLtdecr(26);
break; break;
} }
# line 282 "LLgen.g" # line 280 "LLgen.g"
{ if (conflres & (COND|PREFERING|AVOIDING)) { { if (conflres & (COND|PREFERING|AVOIDING)) {
error(n_lc, error(n_lc,
"Resolver on last alternative not allowed"); "Resolver on last alternative not allowed", NULL);
} }
mkalt(*p,conflres,n_lc,&alt_table[n_alts++]); mkalt(*p,conflres,n_lc,&alt_table[n_alts++]);
altcnt++; altcnt++;
@ -582,15 +523,15 @@ case /* ']' */ 28 : ;
goto L_3; goto L_3;
L_3: ; L_3: ;
LLtdecr(26); LLtdecr(26);
# line 292 "LLgen.g" # line 290 "LLgen.g"
{ if (conflres & (COND|PREFERING|AVOIDING)) { { if (conflres & (COND|PREFERING|AVOIDING)) {
error(o_lc, error(o_lc,
"No alternation conflict resolver allowed here"); "No alternation conflict resolver allowed here", NULL);
} }
/* /*
if (conflres & DEF) { if (conflres & DEF) {
error(o_lc, error(o_lc,
"No %%default allowed here"); "No %%default allowed here", NULL);
} }
*/ */
} }
@ -598,14 +539,14 @@ break;
default: if (LLskip()) goto L_2; default: if (LLskip()) goto L_2;
goto L_3; goto L_3;
} }
# line 304 "LLgen.g" # line 302 "LLgen.g"
{ n_alts -= altcnt; } { n_alts -= altcnt; }
} }
# line 306 "LLgen.g" # line 304 "LLgen.g"
STATIC STATIC void mkalt(p_gram prod, int condition,int lc,register p_gram res)
mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; { {
/* /*
* Create an alternation and initialise it. * Create an alternation and initialise it.
*/ */
@ -627,19 +568,12 @@ mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; {
nalts++; nalts++;
} }
static static
#if LL_ANSI_C
void void
#endif
LL6_simpleproduction( LL6_simpleproduction(
#if LL_ANSI_C # line 330 "LLgen.g"
# line 332 "LLgen.g"
p_gram *p ,register int *conflres) p_gram *p ,register int *conflres)
#else
# line 332 "LLgen.g"
p,conflres) p_gram *p; register int *conflres;
#endif
{ {
# line 333 "LLgen.g" # line 331 "LLgen.g"
t_gram elem; t_gram elem;
int elmcnt = 0; int elmcnt = 0;
int cnt, kind; int cnt, kind;
@ -675,7 +609,7 @@ else if (LL_6 & 1) goto L_1;}
case /* C_DEFAULT */ 19 : ; case /* C_DEFAULT */ 19 : ;
LLtdecr(19); LLtdecr(19);
LL_SAFE(C_DEFAULT); LL_SAFE(C_DEFAULT);
# line 338 "LLgen.g" # line 336 "LLgen.g"
{ *conflres |= DEF; } { *conflres |= DEF; }
LLread(); LLread();
} }
@ -708,17 +642,17 @@ switch(LLcsymb) {
case /* C_IF */ 10 : ; case /* C_IF */ 10 : ;
LL_SAFE(C_IF); LL_SAFE(C_IF);
LL_NOSCANDONE(C_EXPR); LL_NOSCANDONE(C_EXPR);
# line 344 "LLgen.g" # line 342 "LLgen.g"
{ *conflres |= COND; } { *conflres |= COND; }
break; break;
default: default:
LL_SAFE(C_PREFER); LL_SAFE(C_PREFER);
# line 345 "LLgen.g" # line 343 "LLgen.g"
{ *conflres |= PREFERING; } { *conflres |= PREFERING; }
break; break;
case /* C_AVOID */ 17 : ; case /* C_AVOID */ 17 : ;
LL_SAFE(C_AVOID); LL_SAFE(C_AVOID);
# line 346 "LLgen.g" # line 344 "LLgen.g"
{ *conflres |= AVOIDING; } { *conflres |= AVOIDING; }
break; break;
} }
@ -747,7 +681,7 @@ else if (LL_8 & 1) goto L_6;}
case /* C_ILLEGAL */ 22 : ; case /* C_ILLEGAL */ 22 : ;
LLtdecr(22); LLtdecr(22);
LL_SAFE(C_ILLEGAL); LL_SAFE(C_ILLEGAL);
# line 348 "LLgen.g" # line 346 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (n_rules >= max_rules-2) { if (n_rules >= max_rules-2) {
@ -759,7 +693,7 @@ LL_SAFE(C_ILLEGAL);
rule_table[n_rules++] = rule_table[n_rules++] =
*search(TERMINAL, "LLILLEGAL", BOTH); *search(TERMINAL, "LLILLEGAL", BOTH);
if (*conflres & DEF) { if (*conflres & DEF) {
error(linecount, "%%illegal not allowed in %%default rule"); error(linecount, "%%illegal not allowed in %%default rule", NULL);
} }
#endif #endif
} }
@ -790,9 +724,9 @@ case /* '*' */ 30 : ;
case /* '+' */ 31 : ; case /* '+' */ 31 : ;
LLsincr(4); LLsincr(4);
LL7_elem( LL7_elem(
# line 364 "LLgen.g" # line 362 "LLgen.g"
&elem); &elem);
# line 365 "LLgen.g" # line 363 "LLgen.g"
{ if (n_rules >= max_rules-2) { { if (n_rules >= max_rules-2) {
rule_table = (p_gram) ralloc( rule_table = (p_gram) ralloc(
(p_mem) rule_table, (p_mem) rule_table,
@ -810,9 +744,9 @@ case /* '*' */ 30 : ;
case /* '+' */ 31 : ; case /* '+' */ 31 : ;
LLsdecr(4); LLsdecr(4);
LL8_repeats( LL8_repeats(
# line 373 "LLgen.g" # line 371 "LLgen.g"
&kind, &cnt); &kind, &cnt);
# line 374 "LLgen.g" # line 372 "LLgen.g"
{ if (g_gettype(&elem) != TERM) { { if (g_gettype(&elem) != TERM) {
rule_table[n_rules] = elem; rule_table[n_rules] = elem;
g_settype((&rule_table[n_rules+1]),EORULE); g_settype((&rule_table[n_rules+1]),EORULE);
@ -835,7 +769,7 @@ case /* ']' */ 28 : ;
goto L_10; goto L_10;
L_10: ; L_10: ;
LLsdecr(4); LLsdecr(4);
# line 384 "LLgen.g" # line 382 "LLgen.g"
{ if (g_gettype(&elem) == TERM) { { if (g_gettype(&elem) == TERM) {
register p_term q = g_getterm(&elem); register p_term q = g_getterm(&elem);
@ -867,7 +801,7 @@ break;
default: if (LLskip()) goto L_9; default: if (LLskip()) goto L_9;
goto L_10; goto L_10;
} }
# line 411 "LLgen.g" # line 409 "LLgen.g"
{ if (!termdeleted && g_gettype(&elem) == TERM) { { if (!termdeleted && g_gettype(&elem) == TERM) {
register p_term q; register p_term q;
@ -877,7 +811,7 @@ goto L_10;
if ((q->t_flags & RESOLVER) && if ((q->t_flags & RESOLVER) &&
(kind == PLUS || kind == FIXED)) { (kind == PLUS || kind == FIXED)) {
error(linecount, error(linecount,
"%%while not allowed in this term"); "%%while not allowed in this term", NULL);
} }
/* /*
* A persistent fixed term is the same * A persistent fixed term is the same
@ -886,7 +820,7 @@ goto L_10;
if ((q->t_flags & PERSISTENT) && if ((q->t_flags & PERSISTENT) &&
kind == FIXED) { kind == FIXED) {
error(linecount, error(linecount,
"Illegal %%persistent"); "Illegal %%persistent", NULL);
} }
*/ */
} }
@ -900,7 +834,7 @@ continue;
LLsdecr(3); LLsdecr(3);
break; break;
} }
# line 437 "LLgen.g" # line 435 "LLgen.g"
{ register p_term q; { register p_term q;
g_settype((&rule_table[n_rules]),EORULE); g_settype((&rule_table[n_rules]),EORULE);
@ -918,11 +852,11 @@ break;
elmcnt+1); elmcnt+1);
} }
} }
# line 454 "LLgen.g" # line 452 "LLgen.g"
STATIC STATIC void mkterm(p_gram prod, int flags,int lc,register p_gram result)
mkterm(prod,flags,lc,result) p_gram prod; register p_gram result; { {
/* /*
* Create a term, initialise it and return * Create a term, initialise it and return
* a grammar element containing it * a grammar element containing it
@ -944,19 +878,12 @@ mkterm(prod,flags,lc,result) p_gram prod; register p_gram result; {
nterms++; nterms++;
} }
static static
#if LL_ANSI_C
void void
#endif
LL7_elem( LL7_elem(
#if LL_ANSI_C # line 478 "LLgen.g"
# line 480 "LLgen.g"
register p_gram pres) register p_gram pres)
#else
# line 480 "LLgen.g"
pres) register p_gram pres;
#endif
{ {
# line 481 "LLgen.g" # line 479 "LLgen.g"
register int t = 0; register int t = 0;
p_gram p1; p_gram p1;
int ln; int ln;
@ -972,7 +899,7 @@ LLtincr(12);
LLsincr(1); LLsincr(1);
LLtincr(28); LLtincr(28);
LL_SAFE('['); LL_SAFE('[');
# line 489 "LLgen.g" # line 487 "LLgen.g"
{ ln = linecount; } { ln = linecount; }
LLread(); LLread();
goto L_4; goto L_4;
@ -1003,7 +930,7 @@ case /* C_WHILE */ 11 : ;
LLtdecr(11); LLtdecr(11);
LL_SAFE(C_WHILE); LL_SAFE(C_WHILE);
LL_NOSCANDONE(C_EXPR); LL_NOSCANDONE(C_EXPR);
# line 490 "LLgen.g" # line 488 "LLgen.g"
{ t |= RESOLVER; } { t |= RESOLVER; }
LLread(); LLread();
} }
@ -1034,18 +961,18 @@ else if (LL_11 & 1) goto L_5;}
case /* C_PERSISTENT */ 12 : ; case /* C_PERSISTENT */ 12 : ;
LLtdecr(12); LLtdecr(12);
LL_SAFE(C_PERSISTENT); LL_SAFE(C_PERSISTENT);
# line 492 "LLgen.g" # line 490 "LLgen.g"
{ t |= PERSISTENT; } { t |= PERSISTENT; }
LLread(); LLread();
} }
} }
LLsdecr(1); LLsdecr(1);
LL5_productions( LL5_productions(
# line 494 "LLgen.g" # line 492 "LLgen.g"
&p1); &p1);
LLtdecr(28); LLtdecr(28);
LL_SCANDONE(']'); LL_SCANDONE(']');
# line 495 "LLgen.g" # line 493 "LLgen.g"
{ {
mkterm(p1,t,ln,pres); mkterm(p1,t,ln,pres);
} }
@ -1061,7 +988,7 @@ default:
break; break;
case /* C_ERRONEOUS */ 21 : ; case /* C_ERRONEOUS */ 21 : ;
LL_SAFE(C_ERRONEOUS); LL_SAFE(C_ERRONEOUS);
# line 499 "LLgen.g" # line 497 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
erroneous = 1; erroneous = 1;
@ -1079,14 +1006,14 @@ L_9: ;
LLsdecr(5); LLsdecr(5);
LLtincr(6); LLtincr(6);
LL_SSCANDONE(C_IDENT); LL_SSCANDONE(C_IDENT);
# line 507 "LLgen.g" # line 505 "LLgen.g"
{ pe = search(UNKNOWN,lextoken.t_string,BOTH); { pe = search(UNKNOWN,lextoken.t_string,BOTH);
*pres = *pe; *pres = *pe;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (erroneous) { if (erroneous) {
if (g_gettype(pres) != TERMINAL){ if (g_gettype(pres) != TERMINAL){
warning(linecount, warning(linecount,
"Erroneous only allowed on terminal"); "Erroneous only allowed on terminal", NULL);
erroneous = 0; erroneous = 0;
} }
else else
@ -1122,13 +1049,13 @@ else if (LL_12 & 1) goto L_10;}
case /* C_PARAMS */ 6 : ; case /* C_PARAMS */ 6 : ;
LLtdecr(6); LLtdecr(6);
LL_SAFE(C_PARAMS); LL_SAFE(C_PARAMS);
# line 522 "LLgen.g" # line 520 "LLgen.g"
{ if (lextoken.t_num > 15) { { if (lextoken.t_num > 15) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters", NULL);
} else g_setnpar(pres,lextoken.t_num); } else g_setnpar(pres,lextoken.t_num);
if (g_gettype(pres) == TERMINAL) { if (g_gettype(pres) == TERMINAL) {
error(linecount, error(linecount,
"Terminal with parameters"); "Terminal with parameters", NULL);
} }
} }
LLread(); LLread();
@ -1140,7 +1067,7 @@ goto L_9;
case /* C_LITERAL */ 4 : ; case /* C_LITERAL */ 4 : ;
LLsdecr(5); LLsdecr(5);
LL_SAFE(C_LITERAL); LL_SAFE(C_LITERAL);
# line 531 "LLgen.g" # line 529 "LLgen.g"
{ pe = search(LITERAL,lextoken.t_string,BOTH); { pe = search(LITERAL,lextoken.t_string,BOTH);
*pres = *pe; *pres = *pe;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
@ -1154,7 +1081,7 @@ break;
break; break;
default: default:
LLtincr(7); LLtincr(7);
# line 539 "LLgen.g" # line 537 "LLgen.g"
{ g_settype(pres,ACTION); { g_settype(pres,ACTION);
pres->g_lineno = linecount; pres->g_lineno = linecount;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
@ -1169,14 +1096,14 @@ case /* C_SUBSTART */ 20 : ;
LLtincr(23); LLtincr(23);
LLtincr(24); LLtincr(24);
LL_SAFE(C_SUBSTART); LL_SAFE(C_SUBSTART);
# line 548 "LLgen.g" # line 546 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
nsubstarts++; nsubstarts++;
#endif #endif
} }
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 555 "LLgen.g" # line 553 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
register p_gram temp; register p_gram temp;
@ -1205,7 +1132,7 @@ else if (LL_13 & 1) goto L_12;}
case /* ',' */ 23 : ; case /* ',' */ 23 : ;
LL_SAFE(','); LL_SAFE(',');
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 571 "LLgen.g" # line 569 "LLgen.g"
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
register p_gram temp; register p_gram temp;
@ -1249,24 +1176,17 @@ break;
} }
} }
static static
#if LL_ANSI_C
void void
#endif
LL8_repeats( LL8_repeats(
#if LL_ANSI_C # line 600 "LLgen.g"
# line 602 "LLgen.g"
int *kind ,int *cnt) int *kind ,int *cnt)
#else
# line 602 "LLgen.g"
kind,cnt) int *kind; int *cnt;
#endif
{ {
# line 602 "LLgen.g" # line 600 "LLgen.g"
int t1 = 0; int t1 = 0;
switch(LLcsymb) { switch(LLcsymb) {
default: default:
LL_SAFE('?'); LL_SAFE('?');
# line 604 "LLgen.g" # line 602 "LLgen.g"
{ *kind = OPT; } { *kind = OPT; }
LLread(); LLread();
break; break;
@ -1276,12 +1196,12 @@ LLtincr(3);
switch(LLcsymb) { switch(LLcsymb) {
default: default:
LL_SAFE('*'); LL_SAFE('*');
# line 605 "LLgen.g" # line 603 "LLgen.g"
{ *kind = STAR; } { *kind = STAR; }
break; break;
case /* '+' */ 31 : ; case /* '+' */ 31 : ;
LL_SAFE('+'); LL_SAFE('+');
# line 606 "LLgen.g" # line 604 "LLgen.g"
{ *kind = PLUS; } { *kind = PLUS; }
break; break;
} }
@ -1308,12 +1228,12 @@ else if (LL_14 & 1) goto L_7;}
case /* C_NUMBER */ 3 : ; case /* C_NUMBER */ 3 : ;
LLtdecr(3); LLtdecr(3);
LL9_number( LL9_number(
# line 608 "LLgen.g" # line 606 "LLgen.g"
&t1); &t1);
LLread(); LLread();
} }
} }
# line 609 "LLgen.g" # line 607 "LLgen.g"
{ if (t1 == 1) { { if (t1 == 1) {
t1 = 0; t1 = 0;
if (*kind == STAR) *kind = OPT; if (*kind == STAR) *kind = OPT;
@ -1323,52 +1243,41 @@ LLread();
break; break;
case /* C_NUMBER */ 3 : ; case /* C_NUMBER */ 3 : ;
LL9_number( LL9_number(
# line 615 "LLgen.g" # line 613 "LLgen.g"
&t1); &t1);
LLread(); LLread();
break; break;
} }
# line 616 "LLgen.g" # line 614 "LLgen.g"
{ *cnt = t1; } { *cnt = t1; }
} }
static static
#if LL_ANSI_C
void void
#endif
LL9_number( LL9_number(
#if LL_ANSI_C # line 617 "LLgen.g"
# line 619 "LLgen.g"
int *t) int *t)
#else
# line 619 "LLgen.g"
t) int *t;
#endif
{ {
LL_SAFE(C_NUMBER); LL_SAFE(C_NUMBER);
# line 621 "LLgen.g" # line 619 "LLgen.g"
{ *t = lextoken.t_num; { *t = lextoken.t_num;
if (*t <= 0 || *t >= 8192) { if (*t <= 0 || *t >= 8192) {
error(linecount,"Illegal number"); error(linecount,"Illegal number", NULL);
} }
} }
} }
static static
#if LL_ANSI_C
void void
#endif
LL4_firsts( LL4_firsts(
#if LL_ANSI_C
void void
#endif
) { ) {
# line 628 "LLgen.g" # line 626 "LLgen.g"
register string p; register string p;
LLtincr(23); LLtincr(23);
LLtincr(2); LLtincr(2);
LLtincr(24); LLtincr(24);
LL_SAFE(C_FIRST); LL_SAFE(C_FIRST);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
# line 630 "LLgen.g" # line 628 "LLgen.g"
{ p = store(lextoken.t_string); } { p = store(lextoken.t_string); }
LLtdecr(23); LLtdecr(23);
LL_NOSCANDONE(','); LL_NOSCANDONE(',');
@ -1376,7 +1285,7 @@ LLtdecr(2);
LL_NOSCANDONE(C_IDENT); LL_NOSCANDONE(C_IDENT);
LLtdecr(24); LLtdecr(24);
LL_NOSCANDONE(';'); LL_NOSCANDONE(';');
# line 632 "LLgen.g" # line 630 "LLgen.g"
{ /* { /*
* Store this %first in the list belonging * Store this %first in the list belonging
* to this input file * to this input file
@ -1393,11 +1302,11 @@ LL_NOSCANDONE(';');
} }
} }
# line 647 "LLgen.g" # line 645 "LLgen.g"
STATIC p_gram STATIC p_gram copyrule(register p_gram p,int length)
copyrule(p,length) register p_gram p; { {
/* /*
* Returns a pointer to a grammar rule that was created in * Returns a pointer to a grammar rule that was created in
* p. The space pointed to by p can now be reused * p. The space pointed to by p can now be reused

View file

@ -18,13 +18,13 @@
*/ */
{ {
# include <stdlib.h> #include <stdlib.h>
# include <string.h> #include <string.h>
# include "types.h" #include "types.h"
# include "io.h" #include "io.h"
# include "extern.h" #include "extern.h"
# include "assert.h" #include "assert.h"
# include "cclass.h" #include "cclass.h"
# ifndef NORCSID # ifndef NORCSID
static string rcsid = "$Id$"; static string rcsid = "$Id$";
@ -48,15 +48,14 @@ static int max_rules;
#define RULEINCR 32 #define RULEINCR 32
/* Here are defined : */ /* Here are defined : */
STATIC newnorder(); STATIC void newnorder(int index);
STATIC newtorder(); STATIC void newtorder(int index);
STATIC mkalt(); STATIC void mkalt(p_gram prod, int condition,int lc,register p_gram res);
STATIC mkterm(); STATIC void mkterm(p_gram prod, int flags,int lc,register p_gram result);
STATIC p_gram copyrule(); STATIC p_gram copyrule(register p_gram p,int length);
/* and of course LLparse() */ /* and of course LLparse() */
STATIC STATIC void newnorder(int index) {
newnorder(index) {
static int porder; static int porder;
if (norder != -1) { if (norder != -1) {
@ -67,8 +66,7 @@ newnorder(index) {
nonterms[porder].n_next = -1; nonterms[porder].n_next = -1;
} }
STATIC STATIC void newtorder(int index) {
newtorder(index) {
static int porder; static int porder;
if (torder != -1) { if (torder != -1) {
@ -79,7 +77,7 @@ newtorder(index) {
tokens[porder].t_next = -1; tokens[porder].t_next = -1;
} }
p_init() void p_init(void)
{ {
alt_table = (p_gram )alloc(ALTINCR*sizeof(t_gram)); alt_table = (p_gram )alloc(ALTINCR*sizeof(t_gram));
n_alts = 0; n_alts = 0;
@ -149,7 +147,7 @@ def { register string p; }
{ if (!lexical) { { if (!lexical) {
lexical = store(lextoken.t_string); lexical = store(lextoken.t_string);
} }
else error(linecount,"Duplicate %%lexical"); else error(linecount,"Duplicate %%lexical", NULL);
} }
';' ';'
| C_PREFIX C_IDENT | C_PREFIX C_IDENT
@ -160,25 +158,25 @@ def { register string p; }
prefix = store(lextoken.t_string); prefix = store(lextoken.t_string);
if (strlen(prefix) > 6) { if (strlen(prefix) > 6) {
error(linecount, error(linecount,
"%%prefix too long"); "%%prefix too long",NULL);
prefix[6] = 0; prefix[6] = 0;
} }
} }
else error(linecount,"Duplicate %%prefix"); else error(linecount,"Duplicate %%prefix", NULL);
} }
';' ';'
| C_ONERROR C_IDENT | C_ONERROR C_IDENT
{ {
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (non_corr) { if (non_corr) {
warning(linecount, "%%onerror conflicts with -n option"); warning(linecount, "%%onerror conflicts with -n option", NULL);
} }
else else
#endif #endif
if (! onerror) { if (! onerror) {
onerror = store(lextoken.t_string); onerror = store(lextoken.t_string);
} }
else error(linecount,"Duplicate %%onerror"); else error(linecount,"Duplicate %%onerror", NULL);
} }
';' ';'
| C_ACTION { acount++; } | C_ACTION { acount++; }
@ -225,7 +223,7 @@ rule { register p_nont p;
[ C_PARAMS { if (lextoken.t_num > 0) { [ C_PARAMS { if (lextoken.t_num > 0) {
p->n_flags |= PARAMS; p->n_flags |= PARAMS;
if (lextoken.t_num > 15) { if (lextoken.t_num > 15) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters", NULL);
} }
else setntparams(p,lextoken.t_num); else setntparams(p,lextoken.t_num);
} }
@ -268,7 +266,7 @@ productions(p_gram *p;)
if (t & DEF) { if (t & DEF) {
if (haddefault) { if (haddefault) {
error(n_lc, error(n_lc,
"More than one %%default in alternation"); "More than one %%default in alternation", NULL);
} }
haddefault = 1; haddefault = 1;
} }
@ -281,7 +279,7 @@ productions(p_gram *p;)
} }
]+ { if (conflres & (COND|PREFERING|AVOIDING)) { ]+ { if (conflres & (COND|PREFERING|AVOIDING)) {
error(n_lc, error(n_lc,
"Resolver on last alternative not allowed"); "Resolver on last alternative not allowed", NULL);
} }
mkalt(*p,conflres,n_lc,&alt_table[n_alts++]); mkalt(*p,conflres,n_lc,&alt_table[n_alts++]);
altcnt++; altcnt++;
@ -291,12 +289,12 @@ productions(p_gram *p;)
| |
{ if (conflres & (COND|PREFERING|AVOIDING)) { { if (conflres & (COND|PREFERING|AVOIDING)) {
error(o_lc, error(o_lc,
"No alternation conflict resolver allowed here"); "No alternation conflict resolver allowed here", NULL);
} }
/* /*
if (conflres & DEF) { if (conflres & DEF) {
error(o_lc, error(o_lc,
"No %%default allowed here"); "No %%default allowed here", NULL);
} }
*/ */
} }
@ -305,8 +303,8 @@ productions(p_gram *p;)
; ;
{ {
STATIC STATIC void mkalt(p_gram prod, int condition,int lc,register p_gram res)
mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; { {
/* /*
* Create an alternation and initialise it. * Create an alternation and initialise it.
*/ */
@ -356,7 +354,7 @@ simpleproduction(p_gram *p; register int *conflres;)
rule_table[n_rules++] = rule_table[n_rules++] =
*search(TERMINAL, "LLILLEGAL", BOTH); *search(TERMINAL, "LLILLEGAL", BOTH);
if (*conflres & DEF) { if (*conflres & DEF) {
error(linecount, "%%illegal not allowed in %%default rule"); error(linecount, "%%illegal not allowed in %%default rule", NULL);
} }
#endif #endif
} }
@ -417,7 +415,7 @@ simpleproduction(p_gram *p; register int *conflres;)
if ((q->t_flags & RESOLVER) && if ((q->t_flags & RESOLVER) &&
(kind == PLUS || kind == FIXED)) { (kind == PLUS || kind == FIXED)) {
error(linecount, error(linecount,
"%%while not allowed in this term"); "%%while not allowed in this term", NULL);
} }
/* /*
* A persistent fixed term is the same * A persistent fixed term is the same
@ -426,7 +424,7 @@ simpleproduction(p_gram *p; register int *conflres;)
if ((q->t_flags & PERSISTENT) && if ((q->t_flags & PERSISTENT) &&
kind == FIXED) { kind == FIXED) {
error(linecount, error(linecount,
"Illegal %%persistent"); "Illegal %%persistent", NULL);
} }
*/ */
} }
@ -453,8 +451,8 @@ simpleproduction(p_gram *p; register int *conflres;)
; ;
{ {
STATIC STATIC void mkterm(p_gram prod, int flags,int lc,register p_gram result)
mkterm(prod,flags,lc,result) p_gram prod; register p_gram result; { {
/* /*
* Create a term, initialise it and return * Create a term, initialise it and return
* a grammar element containing it * a grammar element containing it
@ -510,7 +508,7 @@ elem (register p_gram pres;)
if (erroneous) { if (erroneous) {
if (g_gettype(pres) != TERMINAL){ if (g_gettype(pres) != TERMINAL){
warning(linecount, warning(linecount,
"Erroneous only allowed on terminal"); "Erroneous only allowed on terminal", NULL);
erroneous = 0; erroneous = 0;
} }
else else
@ -520,11 +518,11 @@ elem (register p_gram pres;)
} }
[ C_PARAMS { if (lextoken.t_num > 15) { [ C_PARAMS { if (lextoken.t_num > 15) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters", NULL);
} else g_setnpar(pres,lextoken.t_num); } else g_setnpar(pres,lextoken.t_num);
if (g_gettype(pres) == TERMINAL) { if (g_gettype(pres) == TERMINAL) {
error(linecount, error(linecount,
"Terminal with parameters"); "Terminal with parameters", NULL);
} }
} }
]? ]?
@ -620,7 +618,7 @@ number(int *t;)
: C_NUMBER : C_NUMBER
{ *t = lextoken.t_num; { *t = lextoken.t_num;
if (*t <= 0 || *t >= 8192) { if (*t <= 0 || *t >= 8192) {
error(linecount,"Illegal number"); error(linecount,"Illegal number", NULL);
} }
} }
; ;
@ -646,8 +644,8 @@ firsts { register string p; }
; ;
{ {
STATIC p_gram STATIC p_gram copyrule(register p_gram p,int length)
copyrule(p,length) register p_gram p; { {
/* /*
* Returns a pointer to a grammar rule that was created in * Returns a pointer to a grammar rule that was created in
* p. The space pointed to by p can now be reused * p. The space pointed to by p can now be reused

View file

@ -1,9 +1,6 @@
/* LLgen generated code from source . */ /* LLgen generated code from source . */
#include "Lpars.h" #include "Lpars.h"
#define LLNOFIRSTS #define LLNOFIRSTS
#if __STDC__ || __cplusplus
#define LL_ANSI_C 1
#endif
#define LL_LEXI scanner #define LL_LEXI scanner
/* $Id$ */ /* $Id$ */
#ifdef LL_DEBUG #ifdef LL_DEBUG
@ -37,7 +34,6 @@ extern int LLstartsymb;
#define LLsincr(d) LLscnt[d]++ #define LLsincr(d) LLscnt[d]++
#define LLtincr(d) LLtcnt[d]++ #define LLtincr(d) LLtcnt[d]++
#if LL_ANSI_C
extern int LL_LEXI(void); extern int LL_LEXI(void);
extern void LLread(void); extern void LLread(void);
extern int LLskip(void); extern int LLskip(void);
@ -55,35 +51,11 @@ extern int LLfirst(int, int);
#if LL_NON_CORR #if LL_NON_CORR
extern void LLnc_recover(void); extern void LLnc_recover(void);
#endif #endif
#else /* not LL_ANSI_C */
extern LLread();
extern int LLskip();
extern int LLnext();
extern LLerror();
extern LLsafeerror();
extern LLnewlevel();
extern LLoldlevel();
#ifndef LL_FASTER
extern LLscan();
#endif
#ifndef LLNOFIRSTS
extern int LLfirst();
#endif
#if LL_NON_CORR
extern LLnc_recover();
#endif
#endif /* not LL_ANSI_C */
#define LL_SSIZE 4 #define LL_SSIZE 4
#define LL_NSETS 6 #define LL_NSETS 6
#define LL_NTERMINALS 32 #define LL_NTERMINALS 32
#if LL_ANSI_C
void LL0_spec(void); void LL0_spec(void);
#endif
#if LL_ANSI_C
void LLparse(void) void LLparse(void)
#else
LLparse()
#endif
{ {
unsigned int s[LL_NTERMINALS+LL_NSETS+2]; unsigned int s[LL_NTERMINALS+LL_NSETS+2];
LLnewlevel(s); LLnewlevel(s);
@ -401,29 +373,15 @@ int LLstartsymb;
static int fake_eof = 0; static int fake_eof = 0;
#endif #endif
#if LL_ANSI_C
#define LL_VOIDCST (void) #define LL_VOIDCST (void)
void LLmessage(int); void LLmessage(int);
#else
#define LL_VOIDCST
#endif
#ifdef LL_USERHOOK #ifdef LL_USERHOOK
#if LL_ANSI_C
static int LLdoskip(int); static int LLdoskip(int);
static int LLuserhook(int, int*); static int LLuserhook(int, int*);
#else
static int LLdoskip();
static int LLuserhook();
#endif
#endif #endif
#ifndef LL_FASTER #ifndef LL_FASTER
#if LL_ANSI_C
void LLscan(int t) void LLscan(int t)
#else
LLscan(t)
int t;
#endif
{ {
/* /*
* Check if the next symbol is equal to the parameter * Check if the next symbol is equal to the parameter
@ -469,12 +427,7 @@ LLscan(t)
} }
#endif #endif
#if LL_ANSI_C
void LLread(void) { void LLread(void) {
#else
LLread() {
#endif
#if LL_NON_CORR #if LL_NON_CORR
/* Again, check if another parser has crashed, /* Again, check if another parser has crashed,
* in that case intercept and go to the * in that case intercept and go to the
@ -506,12 +459,7 @@ LLread() {
/* NOTREACHED */ /* NOTREACHED */
} }
#if LL_ANSI_C
void LLerror(int t) void LLerror(int t)
#else
LLerror(t)
int t;
#endif
{ {
register int i; register int i;
@ -573,12 +521,7 @@ LLerror(t)
} }
} }
#if LL_ANSI_C
void LLsafeerror(int t) void LLsafeerror(int t)
#else
LLsafeerror(t)
int t;
#endif
{ {
if (t == EOFILE && LLsymb <= 0) return; if (t == EOFILE && LLsymb <= 0) return;
#ifdef LL_NEWMESS #ifdef LL_NEWMESS
@ -621,11 +564,7 @@ LLsafeerror(t)
} }
#ifndef LLNOFIRSTS #ifndef LLNOFIRSTS
#if LL_ANSI_C
int LLfirst(int x, int d) { int LLfirst(int x, int d) {
#else
int LLfirst(x, d) {
#endif
register int i; register int i;
return (i = LLindex[x]) >= 0 && return (i = LLindex[x]) >= 0 &&
@ -633,12 +572,7 @@ int LLfirst(x, d) {
} }
#endif #endif
#if LL_ANSI_C
int LLnext(int n) int LLnext(int n)
#else
int LLnext(n)
int n;
#endif
{ {
/* returns: 0 if the current symbol is'nt skipped, and it /* returns: 0 if the current symbol is'nt skipped, and it
is'nt a member of "n", is'nt a member of "n",
@ -659,11 +593,7 @@ int LLnext(n)
return retval; return retval;
} }
#if LL_ANSI_C
int LLskip(void) { int LLskip(void) {
#else
int LLskip() {
#endif
/* returns 0 if the current symbol is'nt skipped, and /* returns 0 if the current symbol is'nt skipped, and
1 if it is, t.i., we have a new symbol 1 if it is, t.i., we have a new symbol
*/ */
@ -671,14 +601,8 @@ int LLskip() {
return LLdoskip(0); return LLdoskip(0);
} }
#if LL_ANSI_C
extern void LL_USERHOOK(int, int *); extern void LL_USERHOOK(int, int *);
static int LLuserhook(int e, int *list) static int LLuserhook(int e, int *list)
#else
static int LLuserhook(e, list)
int e;
int *list;
#endif
{ {
int old = LLsymb; int old = LLsymb;
LL_USERHOOK(e, list); LL_USERHOOK(e, list);
@ -686,12 +610,7 @@ static int LLuserhook(e, list)
return LLsymb != old; return LLsymb != old;
} }
#if LL_ANSI_C
static void LLmklist(register int *list) static void LLmklist(register int *list)
#else
static LLmklist(list)
register int *list;
#endif
{ {
char Xset[LL_SSIZE]; char Xset[LL_SSIZE];
register char *p; register char *p;
@ -715,12 +634,7 @@ static LLmklist(list)
*list = 0; *list = 0;
} }
#if LL_ANSI_C
static int LLdoskip(int e) static int LLdoskip(int e)
#else
static int LLdoskip(e)
int e;
#endif
{ {
int LLx; int LLx;
int list[LL_NTERMINALS+1]; int list[LL_NTERMINALS+1];
@ -779,11 +693,7 @@ static int LLdoskip(e)
/* NOTREACHED */ /* NOTREACHED */
} }
#if LL_ANSI_C
void LLnewlevel(unsigned int *LLsinfo) { void LLnewlevel(unsigned int *LLsinfo) {
#else
LLnewlevel(LLsinfo) unsigned int *LLsinfo; {
#endif
register int i; register int i;
if (LLlevel++) { if (LLlevel++) {
@ -801,11 +711,7 @@ LLnewlevel(LLsinfo) unsigned int *LLsinfo; {
LLtincr(0); LLtincr(0);
} }
#if LL_ANSI_C
void LLoldlevel(unsigned int *LLsinfo) { void LLoldlevel(unsigned int *LLsinfo) {
#else
LLoldlevel(LLsinfo) unsigned int *LLsinfo; {
#endif
register int i; register int i;
LLtdecr(0); LLtdecr(0);

View file

@ -17,6 +17,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
# include "alloc.h"
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
@ -26,29 +27,29 @@ static string rcsid = "$Id$";
static string e_nomem = "Out of memory"; static string e_nomem = "Out of memory";
p_mem p_mem alloc(unsigned int size)
alloc(size) unsigned size; { {
/* /*
Allocate "size" bytes. Panic if it fails Allocate "size" bytes. Panic if it fails
*/ */
p_mem p; p_mem p;
if ((p = malloc(size)) == 0) fatal(linecount,e_nomem); if ((p = malloc(size)) == 0) fatal(linecount,e_nomem, NULL);
return p; return p;
} }
p_mem p_mem ralloc(p_mem p,unsigned int size)
ralloc(p,size) p_mem p; unsigned size; { {
/* /*
Re-allocate the chunk of memory indicated by "p", to Re-allocate the chunk of memory indicated by "p", to
occupy "size" bytes occupy "size" bytes
*/ */
if ((p = realloc(p,size)) == 0) fatal(linecount,e_nomem); if ((p = realloc(p,size)) == 0) fatal(linecount,e_nomem, NULL);
return p; return p;
} }
p_mem p_mem new_mem(register p_info p)
new_mem(p) register p_info p; { {
/* /*
This routine implements arrays that can grow. This routine implements arrays that can grow.
It must be called every time a new element is added to it. It must be called every time a new element is added to it.

19
util/LLgen/src/alloc.h Normal file
View file

@ -0,0 +1,19 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-16
*
*/
#ifndef ALLOC_H_
#define ALLOC_H_
#include "types.h"
p_mem alloc(unsigned int size);
p_mem ralloc(p_mem p,unsigned int size);
p_mem new_mem(register p_info p);
#endif /* ALLOC_H_ */

View file

@ -17,6 +17,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
@ -28,247 +29,287 @@
static string rcsid1 = "$Id$"; static string rcsid1 = "$Id$";
# endif # 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(); p_set setalloc();
static int level; static int level;
/* In this file are defined : */ /* In this file are defined : */
extern conflchecks(); void conflchecks(void);
STATIC prline(); STATIC void prline(char *);
STATIC printset(); STATIC void printset(register p_set, string);
STATIC int check(); STATIC int check(register p_gram);
STATIC moreverbose(); STATIC void moreverbose(register p_set);
STATIC void prrule(p_gram p); STATIC void prrule(p_gram);
STATIC cfcheck(); STATIC void cfcheck(p_set, p_set, int);
STATIC void resolve(p_gram p); STATIC void resolve(p_gram);
STATIC propagate(); STATIC void propagate(p_set, register p_gram);
STATIC spaces(); STATIC void spaces(void);
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, * unless there is a disambiguating condition.
* unless there is a disambiguating condition. * 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. */
*/ void conflchecks(void)
register p_nont p; {
register p_nont p;
register int s; register int s;
p_file x = files; p_file x = files;
f_input = x->f_name; f_input = x->f_name;
if (verbose >= 3) { if (verbose >= 3)
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);
} }
/* /*
* Check the rules in the order in which they are declared, * Check the rules in the order in which they are declared,
* and input file by input file, to give proper error messages * and input file by input file, to give proper error messages
*/ */
for (; x < maxfiles; x++) { for (; x < maxfiles; x++)
f_input = x->f_name; {
for (s = x->f_nonterminals; s != -1; s = p->n_next) { f_input = x->f_name;
p = &nonterms[s]; for (s = x->f_nonterminals; s != -1; s = p->n_next)
if (check(p->n_rule)) p->n_flags |= VERBOSE; {
} p = &nonterms[s];
} if (check(p->n_rule))
for (x = files; x < maxfiles; x++) { p->n_flags |= VERBOSE;
f_input = x->f_name;
for (s = x->f_nonterminals; s != -1; s = p->n_next) {
p = &nonterms[s];
if (p->n_flags & RECURSIVE) {
error(p->n_lineno,
"Recursion in default for nonterminal %s",
p->n_name);
} }
/*
* If a printout is needed for this rule in
* LL.output, just do it
*/
if (verbose && (p->n_flags & VERBOSE)) {
fprintf(fout,"\n%s :\n",p->n_name);
printset(p->n_first,c_first);
printset(p->n_contains,c_contains);
printset(p->n_follow,c_follow);
fprintf(fout,"> rule%s\n\t",
p->n_flags&EMPTY ? "\t(EMPTY producing)" : "");
level = 8;
prrule(p->n_rule);
level = 0;
prline("\n");
}
/*
* Now, the conflicts may be resolved
*/
resolve(p->n_rule);
}
} }
if (verbose) fclose(fout); for (x = files; x < maxfiles; x++)
{
f_input = x->f_name;
for (s = x->f_nonterminals; s != -1; s = p->n_next)
{
p = &nonterms[s];
if (p->n_flags & RECURSIVE)
{
error(p->n_lineno, "Recursion in default for nonterminal %s",
p->n_name);
}
/*
* If a printout is needed for this rule in
* LL.output, just do it
*/
if (verbose && (p->n_flags & VERBOSE))
{
fprintf(fout, "\n%s :\n", p->n_name);
printset(p->n_first, c_first);
printset(p->n_contains, c_contains);
printset(p->n_follow, c_follow);
fprintf(fout, "> rule%s\n\t",
p->n_flags & EMPTY ? "\t(EMPTY producing)" : "");
level = 8;
prrule(p->n_rule);
level = 0;
prline("\n");
}
/*
* Now, the conflicts may be resolved
*/
resolve(p->n_rule);
}
}
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(register p_set p, string 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; register int i;
register int j; register int j;
register p_token pt; register p_token pt;
string name; string name;
int k; int k;
int hulp; int hulp;
k = strlen(s) + 2 + level; k = strlen(s) + 2 + level;
/* /*
* k contains relative level of indentation * k contains relative level of indentation
*/ */
fprintf(fout,"%s{ ",s); fprintf(fout, "%s{ ", s);
j = k; j = k;
/* /*
* j will gather the total length of the line * j will gather the total length of the line
*/ */
for (i = 0, pt = tokens; i < ntokens; i++,pt++) { for (i = 0, pt = tokens; i < ntokens; i++, pt++)
if (IN(p,i)) { {
hulp = strlen(pt->t_string)+1; if (IN(p, i))
if (pt->t_tokno < 0400) hulp += 2; {
if ((j += hulp) >= 78) { hulp = strlen(pt->t_string) + 1;
if (pt->t_tokno < 0400)
hulp += 2;
if ((j += hulp) >= 78)
{
/* /*
* Line becoming too long * Line becoming too long
*/ */
j = k+hulp;
prline("\n");
fprintf(fout,">%*c",k - level - 1,' ');
}
fprintf(fout, pt->t_tokno<0400 ? "'%s' " : "%s ",pt->t_string);
}
}
if (ntprint) for (i = 0; i < nnonterms; i++) {
/*
* Nonterminals in the set must also be printed
*/
if (NTIN(p,i)) {
name = nonterms[i].n_name;
hulp = strlen(name) + 3;
if ((j += hulp) >= 78) {
j = k + hulp; j = k + hulp;
prline("\n"); prline("\n");
fprintf(fout,">%*c",k - level - 1,' '); fprintf(fout, ">%*c", k - level - 1, ' ');
} }
fprintf(fout,"<%s> ",name); fprintf(fout, pt->t_tokno < 0400 ? "'%s' " : "%s ", pt->t_string);
} }
} }
if (ntprint)
for (i = 0; i < nnonterms; i++)
{
/*
* Nonterminals in the set must also be printed
*/
if (NTIN(p, i))
{
name = nonterms[i].n_name;
hulp = strlen(name) + 3;
if ((j += hulp) >= 78)
{
j = k + hulp;
prline("\n");
fprintf(fout, ">%*c", k - level - 1, ' ');
}
fprintf(fout, "<%s> ", name);
}
}
prline("}\n"); prline("}\n");
} }
STATIC int STATIC int check(register 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; register p_set temp;
register int retval; register int retval;
retval = 0; retval = 0;
for (;;) { for (;;)
switch (g_gettype(p)) { {
case EORULE : switch (g_gettype(p))
{
case EORULE:
return retval; return retval;
case NONTERM : { case NONTERM:
{
register p_nont n; register 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, {
"Call of %s: parameter count mismatch", error(p->g_lineno, "Call of %s: parameter count mismatch",
n->n_name); n->n_name);
} }
break; } break;
case TERM : { }
case TERM:
{
register p_term q; register p_term q;
q = g_getterm(p); q = g_getterm(p);
retval |= check(q->t_rule); retval |= check(q->t_rule);
if (r_getkind(q) == FIXED) break; if (r_getkind(q) == FIXED)
if (setempty(q->t_first)) { break;
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);
} }
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);
} }
temp = setalloc(); temp = setalloc();
setunion(temp,q->t_first); setunion(temp, q->t_first);
if (!setintersect(temp,q->t_follow)) { if (!setintersect(temp, q->t_follow))
{
/* /*
* q->t_first * q->t_follow != EMPTY * q->t_first * q->t_follow != EMPTY
*/ */
if (!(q->t_flags & RESOLVER)) { if (!(q->t_flags & RESOLVER))
{
/* /*
* No conflict resolver * No conflict resolver
*/ */
error(p->g_lineno, error(p->g_lineno, "Repetition conflict", NULL);
"Repetition conflict");
retval = 1; retval = 1;
moreverbose(temp); moreverbose(temp);
} }
} }
else { else
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", NULL);
"%%while without conflict");
} }
} }
free((p_mem) temp); free((p_mem) temp);
break; } break;
case ALTERNATION : { }
case ALTERNATION:
{
register p_link l; register p_link l;
l = g_getlink(p); l = g_getlink(p);
temp = setalloc(); temp = setalloc();
setunion(temp,l->l_symbs); setunion(temp, l->l_symbs);
if(!setintersect(temp,l->l_others)) { if (!setintersect(temp, l->l_others))
{
/* /*
* temp now contains the conflicting * temp now contains the conflicting
* symbols * symbols
*/ */
if (!(l->l_flag & (COND|PREFERING|AVOIDING))) { if (!(l->l_flag & (COND | PREFERING | AVOIDING)))
error(p->g_lineno, {
"Alternation conflict"); error(p->g_lineno, "Alternation conflict", NULL);
retval = 1; retval = 1;
moreverbose(temp); moreverbose(temp);
} }
} else { }
if (l->l_flag & (COND|PREFERING|AVOIDING)) { else
{
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",
"Conflict resolver without conflict"); NULL);
} }
} }
free( (p_mem) temp); free((p_mem) temp);
if (l->l_flag & PREFERING) propagate(l->l_symbs,p+1); if (l->l_flag & PREFERING)
propagate(l->l_symbs, p + 1);
retval |= check(l->l_rule); retval |= check(l->l_rule);
break; } break;
}
} }
p++; p++;
} }
} }
STATIC STATIC void moreverbose(register 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.
@ -277,116 +318,141 @@ moreverbose(t) register p_set t; {
register int i; register int i;
register p_nont p; register p_nont p;
if (verbose == 2) for (i = 0, p = nonterms; i < nnonterms; i++, p++) { if (verbose == 2)
if (NTIN(t,i)) p->n_flags |= VERBOSE; for (i = 0, p = nonterms; i < nnonterms; i++, p++)
} {
if (NTIN(t, i))
p->n_flags |= VERBOSE;
}
} }
STATIC STATIC void prrule(p_gram p)
void prrule(p_gram p) { {
/* /*
* Create a verbose printout of grammar rule p * Create a verbose printout of grammar rule p
*/ */
register FILE *f; register FILE *f;
int present = 0; int present = 0;
int firstalt = 1; int firstalt = 1;
f = fout; f = fout;
for (;;) { for (;;)
switch (g_gettype(p)) { {
case EORULE : switch (g_gettype(p))
fputs("\n",f); {
case EORULE:
fputs("\n", f);
return; return;
case TERM : { case TERM:
register p_term q; {
register int c; register p_term q;
register int c;
q = g_getterm(p); q = g_getterm(p);
if (present) prline("\n"); if (present)
fputs("[ ",f); prline("\n");
fputs("[ ", f);
level += 4; level += 4;
if (q->t_flags & RESOLVER) { if (q->t_flags & RESOLVER)
{
prline("%while (..)\n"); prline("%while (..)\n");
} }
if (q->t_flags & PERSISTENT) { if (q->t_flags & PERSISTENT)
{
prline("%persistent\n"); prline("%persistent\n");
} }
if (r_getkind(q) != FIXED) { if (r_getkind(q) != FIXED)
if (!(q->t_flags & PERSISTENT)) { {
prline("> continue repetition on the\n"); if (!(q->t_flags & PERSISTENT))
{
prline("> continue repetition on the\n");
} }
printset(q->t_first, c_first); printset(q->t_first, c_first);
if (q->t_flags & PERSISTENT) { if (q->t_flags & PERSISTENT)
prline("> continue repetition on the\n"); {
prline("> continue repetition on the\n");
} }
printset(q->t_contains, c_contains); printset(q->t_contains, c_contains);
prline("> terminate repetition on the\n"); prline("> terminate repetition on the\n");
printset(q->t_follow,c_follow); printset(q->t_follow, c_follow);
if (q->t_flags & EMPTYFIRST) { if (q->t_flags & EMPTYFIRST)
prline(">>> empty first\n"); {
prline(">>> empty first\n");
} }
if (q->t_flags & EMPTYTERM) { if (q->t_flags & EMPTYTERM)
prline(">>> term produces empty\n"); {
prline(">>> term produces empty\n");
} }
cfcheck(q->t_first,q->t_follow, cfcheck(q->t_first, q->t_follow, q->t_flags & RESOLVER);
q->t_flags & RESOLVER);
} }
prrule(q->t_rule); prrule(q->t_rule);
level -= 4; level -= 4;
spaces(); spaces();
c = r_getkind(q); c = r_getkind(q);
fputs(c == STAR ? "]*" : c == PLUS ? "]+" : fputs(c == STAR ? "]*" : c == PLUS ? "]+" : c == OPT ? "]?" : "]",
c == OPT ? "]?" : "]", f); f);
if (c = r_getnum(q)) { if ((c = r_getnum(q)))
fprintf(f,"%d",c); {
fprintf(f, "%d", c);
} }
prline("\n"); prline("\n");
break; }
case ACTION :
fputs("{..} ",f);
break; break;
case ALTERNATION : { }
case ACTION:
fputs("{..} ", f);
break;
case ALTERNATION:
{
register p_link l; register p_link l;
l = g_getlink(p); l = g_getlink(p);
if (firstalt) { if (firstalt)
{
firstalt = 0; firstalt = 0;
} }
else prline("|\n"); else
printset(l->l_symbs,"> alternative on "); prline("|\n");
cfcheck(l->l_symbs, printset(l->l_symbs, "> alternative on ");
l->l_others, cfcheck(l->l_symbs, l->l_others,
(int)(l->l_flag&(COND|PREFERING|AVOIDING))); (int) (l->l_flag & (COND | PREFERING | AVOIDING)));
fputs(" ",f); fputs(" ", f);
level += 4; level += 4;
if (l->l_flag & DEF) { if (l->l_flag & DEF)
{
prline("%default\n"); prline("%default\n");
} }
if (l->l_flag & AVOIDING) { if (l->l_flag & AVOIDING)
{
prline("%avoid\n"); prline("%avoid\n");
} }
if (l->l_flag & PREFERING) { if (l->l_flag & PREFERING)
{
prline("%prefer\n"); prline("%prefer\n");
} }
if (l->l_flag & COND) { if (l->l_flag & COND)
{
prline("%if ( ... )\n"); prline("%if ( ... )\n");
} }
prrule(l->l_rule); prrule(l->l_rule);
level -= 4; level -= 4;
if (g_gettype(p+1) == EORULE) { if (g_gettype(p+1) == EORULE)
{
return; return;
} }
spaces(); spaces();
p++; continue; } p++;
case LITERAL : continue;
case TERMINAL : { }
case LITERAL:
case TERMINAL:
{
register p_token pt = &tokens[g_getcont(p)]; register 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); break;
break; } }
case NONTERM : case NONTERM:
fprintf(f,"%s ",nonterms[g_getcont(p)].n_name); fprintf(f, "%s ", nonterms[g_getcont(p)].n_name);
break; break;
} }
p++; p++;
@ -394,8 +460,8 @@ void prrule(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
@ -405,70 +471,82 @@ cfcheck(s1,s2,flag) p_set s1,s2; {
register p_set temp; register p_set temp;
temp = setalloc(); temp = setalloc();
setunion(temp,s1); setunion(temp, s1);
if (!setintersect(temp,s2)) { if (!setintersect(temp, s2))
if (! flag) { {
printset(temp,">>> conflict on "); if (!flag)
{
printset(temp, ">>> conflict on ");
prline("\n"); prline("\n");
} }
} else { }
if (flag) { else
{
if (flag)
{
prline(">>> %if/%while, no conflict\n"); prline(">>> %if/%while, no conflict\n");
} }
} }
free((p_mem) temp); free((p_mem) temp);
} }
STATIC STATIC void resolve(p_gram p)
void resolve(p_gram p) { {
/* /*
* resolve conflicts, as specified by the user * resolve conflicts, as specified by the user
*/ */
for (;;) { for (;;)
switch (g_gettype(p)) { {
case EORULE : switch (g_gettype(p))
{
case EORULE:
return; return;
case TERM : case TERM:
resolve(g_getterm(p)->t_rule); resolve(g_getterm(p)->t_rule);
break; break;
case ALTERNATION : { case ALTERNATION:
register p_link l; {
register p_link l;
l = g_getlink(p); l = g_getlink(p);
if (l->l_flag & AVOIDING) { if (l->l_flag & AVOIDING)
{
/* /*
* On conflicting symbols, this rule * On conflicting symbols, this rule
* is never chosen * is never chosen
*/ */
setminus(l->l_symbs,l->l_others); setminus(l->l_symbs, l->l_others);
} }
if (setempty(l->l_symbs)) { if (setempty(l->l_symbs))
{
/* /*
* 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);
} }
resolve(l->l_rule); resolve(l->l_rule);
break; } break;
}
} }
p++; p++;
} }
} }
STATIC STATIC void propagate(p_set set, register 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.
*/ */
while (g_gettype(p) != EORULE) { while (g_gettype(p) != EORULE)
setminus(g_getlink(p)->l_symbs,set); {
setminus(g_getlink(p)->l_symbs, set);
p++; p++;
} }
} }
STATIC STATIC void spaces(void)
spaces() { {
if (level > 0)
if (level > 0) fprintf(fout,"%*c",level,' '); fprintf(fout, "%*c", level, ' ');
} }

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,8 @@
* For full copyright and restrictions on use see the file COPYING in the top * For full copyright and restrictions on use see the file COPYING in the top
* level of the LLgen tree. * level of the LLgen tree.
*/ */
#ifndef EXTERN_H_
#define EXTERN_H_
/* /*
* L L G E N * L L G E N
@ -84,7 +86,6 @@ extern string nc_rec_file, nc_incl_file;
extern int low_percentage, high_percentage; extern int low_percentage, high_percentage;
extern int min_cases_for_jmptable; extern int min_cases_for_jmptable;
extern int jmptable_option; extern int jmptable_option;
extern int ansi_c;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
extern int non_corr; extern int non_corr;
extern int subpars_sim; extern int subpars_sim;
@ -92,3 +93,23 @@ extern p_gram illegal_gram;
#endif #endif
extern int strip_grammar; extern int strip_grammar;
extern int in_production; extern int in_production;
void error(int lineno,string s,string t);
void warning(int lineno,string s,string t);
void fatal(int lineno,string s,string t);
int empty(register p_gram);
int t_safety(int, int, int, int);
int t_after(int, int, int);
string store(string);
void name_init(void);
p_gram search(int, register string, int);
void co_reach(void);
void install(string, string);
void copyfile(string);
#endif /* EXTERN_H_ */

File diff suppressed because it is too large Load diff

View file

@ -16,6 +16,7 @@
* Contains declarations visible in several other source files * Contains declarations visible in several other source files
*/ */
#include <stdio.h>
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include "io.h" # include "io.h"
@ -44,8 +45,8 @@ FILE *fout;
FILE *fpars; FILE *fpars;
FILE *finput; FILE *finput;
FILE *fact; FILE *fact;
char f_pars[] = PARSERFILE; char f_pars[L_tmpnam+sizeof(char)]; /* Add one more character for NULL, just in case of buggy implementations. */
char f_temp[] = ACTFILE; char f_temp[L_tmpnam+sizeof(char)];
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
char f_nc[20]; char f_nc[20];
#endif #endif
@ -77,7 +78,6 @@ string nc_rec_file, nc_incl_file;
int low_percentage = 10, high_percentage = 30; int low_percentage = 10, high_percentage = 30;
int min_cases_for_jmptable = 8; int min_cases_for_jmptable = 8;
int jmptable_option; int jmptable_option;
int ansi_c = 0;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
int non_corr = 0; int non_corr = 0;
int subpars_sim = 0; int subpars_sim = 0;

View file

@ -21,8 +21,6 @@
/* FILES */ /* FILES */
# define OUTFILE "%s.output" /* -v option */ # define OUTFILE "%s.output" /* -v option */
# define PARSERFILE "xxxXXXXXX" /* This is what we want */
# define ACTFILE "tempXXXXXX" /* temporary file to save actions */
# define HFILE "%spars.h" /* file for "#define's " */ # define HFILE "%spars.h" /* file for "#define's " */
# define RFILE "%spars.c" /* Error recovery */ # define RFILE "%spars.c" /* Error recovery */
#ifdef NON_CORRECTING #ifdef NON_CORRECTING

View file

@ -15,48 +15,51 @@
* machdep.c * machdep.c
* Machine dependant things * Machine dependant things
*/ */
#include <stdio.h>
#ifdef USE_SYS
#include <system.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
# include "alloc.h"
# include "extern.h"
# include "types.h" # include "types.h"
# ifndef NORCSID # ifndef NORCSID
static string rcsid5 = "$Id$"; static string rcsid5 = "$Id$";
# endif # endif
/* In this file the following routines are defined: */ #ifndef LIBDIR
extern UNLINK(); #define LIBDIR "lib"
extern RENAME(); #endif
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
sys_remove(x); /* systemcall to remove file */ sys_remove(x); /* systemcall to remove file */
#else #else
unlink(x); remove(x);
#endif #endif
} }
RENAME(x,y) string x,y; { void RENAME(string x,string 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);
#endif #endif
} }
string string libpath(string s)
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; register int length;
p_mem alloc();
char* libdir = getenv("LLGEN_LIB_DIR"); char* libdir = getenv("LLGEN_LIB_DIR");
if (!libdir) if (!libdir)
@ -68,3 +71,11 @@ libpath(s) string s; {
strcat(p,s); strcat(p,s);
return p; return p;
} }
void TMPNAM(string result)
{
if (tmpnam(result)==NULL)
{
fatal(1, "Cannot create temporary file.", NULL);
}
}

View file

@ -29,96 +29,103 @@ static string rcsid6 = "$Id$";
# endif # endif
/* In this file the following routines are defined: */ /* In this file the following routines are defined: */
extern int main(); STATIC void readgrammar(int, char *[]);
STATIC readgrammar(); STATIC void doparse(register p_file);
STATIC doparse(); STATIC void comfatal(void);
extern error();
extern fatal();
extern comfatal();
extern copyfile();
extern void install();
main(argc,argv) register string argv[]; { extern void UNLINK(string);
extern void RENAME(string, string);
extern void TMPNAM(string);
extern string libpath(string);
extern void conflchecks(void);
extern void do_compute(void);
extern void gencode(int);
int main(int argc, register string argv[])
{
register string arg; register string arg;
string libpath();
TMPNAM(f_temp);
TMPNAM(f_pars);
/* Initialize */ /* Initialize */
assval = 0400; assval = 0400;
/* read options */ /* read options */
while (argc >= 2 && (arg = argv[1], *arg == '-')) { while (argc >= 2 && (arg = argv[1], *arg == '-'))
while (*++arg) { {
switch(*arg) { while (*++arg)
case 'j': {
case 'J': switch (*arg)
{
case 'j':
case 'J':
jmptable_option = 1; jmptable_option = 1;
if (*++arg) if (*++arg)
min_cases_for_jmptable = atoi(arg); min_cases_for_jmptable = atoi(arg);
break; break;
case 'w': case 'w':
case 'W': case 'W':
wflag = 1; wflag = 1;
continue; continue;
case 'v': case 'v':
case 'V': case 'V':
verbose++; verbose++;
continue; continue;
case 'l': case 'l':
case 'L': case 'L':
low_percentage = atoi(++arg); low_percentage = atoi(++arg);
break; break;
case 'h': case 'h':
case 'H': case 'H':
high_percentage = atoi(++arg); high_percentage = atoi(++arg);
break; break;
# ifndef NDEBUG # ifndef NDEBUG
case 'd': case 'd':
case 'D': case 'D':
debug++; debug++;
continue; continue;
case 'r': case 'r':
case 'R': case 'R':
if (rec_file) { if (rec_file)
fprintf(stderr,"duplicate -r flag\n"); {
fprintf(stderr, "duplicate -r flag\n");
exit(1); exit(1);
} }
rec_file = ++arg; rec_file = ++arg;
break; break;
case 'i': case 'i':
case 'I': case 'I':
if (incl_file) { if (incl_file)
fprintf(stderr,"duplicate -i flag\n"); {
fprintf(stderr, "duplicate -i flag\n");
exit(1); exit(1);
} }
incl_file = ++arg; incl_file = ++arg;
break; break;
#endif /* not NDEBUG */ #endif /* not NDEBUG */
case 'x': case 'x':
case 'X': case 'X':
ntneeded = 1; ntneeded = 1;
ntprint = 1; ntprint = 1;
continue; continue;
case 'a':
case 'A':
ansi_c = 1;
continue;
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
case 'n': case 'n':
case 'N': case 'N':
non_corr = 1; non_corr = 1;
continue; continue;
case 's': case 's':
case 'S': case 'S':
subpars_sim = 1; subpars_sim = 1;
continue; continue;
#endif #endif
case 'g': case 'g':
case 'G': case 'G':
strip_grammar = 1; strip_grammar = 1;
continue; continue;
default: default:
fprintf(stderr,"illegal option : %c\n",*arg); fprintf(stderr, "illegal option : %c\n", *arg);
exit(1); exit(1);
} }
break; break;
@ -128,55 +135,59 @@ main(argc,argv) register string argv[]; {
} }
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if ((subpars_sim) && (!non_corr)) { if ((subpars_sim) && (!non_corr))
fprintf(stderr,"option -s illegal without -n, turned off\n"); {
subpars_sim = 0; fprintf(stderr,"option -s illegal without -n, turned off\n");
subpars_sim = 0;
} }
#endif #endif
/* /*
* Now check wether the sets should include nonterminals * Now check wether the sets should include nonterminals
*/ */
if (verbose == 2) ntneeded = 1; if (verbose == 2)
ntneeded = 1;
/* /*
* Initialise * Initialise
*/ */
# ifndef NDEBUG # ifndef NDEBUG
if (!rec_file) { if (!rec_file)
{
# endif # endif
rec_file = libpath("rec"); rec_file = libpath("rec");
# ifndef NDEBUG # ifndef NDEBUG
} }
if (!incl_file) { if (!incl_file)
{
# endif # endif
incl_file = libpath("incl"); incl_file = libpath("incl");
# ifndef NDEBUG # ifndef NDEBUG
} }
# endif # endif
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (non_corr) { if (non_corr)
nc_incl_file = libpath("nc_incl"); {
nc_rec_file = libpath ("nc_rec"); nc_incl_file = libpath("nc_incl");
nc_rec_file = libpath ("nc_rec");
} }
#endif #endif
close(mkstemp(f_temp)); if ((fact = fopen(f_temp, "w")) == NULL)
close(mkstemp(f_pars)); {
if ((fact = fopen(f_temp,"w")) == NULL) { fputs("Cannot create temporary\n", stderr);
fputs("Cannot create temporary\n",stderr);
exit(1); exit(1);
} }
name_init(); name_init();
readgrammar(argc,argv); readgrammar(argc, argv);
sprintf(f_out, OUTFILE, prefix ? prefix : "LL"); sprintf(f_out, OUTFILE, prefix ? prefix : "LL");
/* for the following two filenames only one L is used; historical /* for the following two filenames only one L is used; historical
reasons ... reasons ...
*/ */
sprintf(f_include, HFILE, prefix ? prefix : "L"); sprintf(f_include, HFILE, prefix ? prefix : "L");
sprintf(f_rec, RFILE, prefix ? prefix : "L"); sprintf(f_rec, RFILE, prefix ? prefix : "L");
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
if (non_corr) if (non_corr)
sprintf(f_nc, NCFILE, prefix ? prefix : "L"); sprintf(f_nc, NCFILE, prefix ? prefix : "L");
#endif #endif
setinit(ntneeded); setinit(ntneeded);
maxnt = &nonterms[nnonterms]; maxnt = &nonterms[nnonterms];
@ -184,50 +195,60 @@ main(argc,argv) register string argv[]; {
/* /*
* Now, the grammar is read. Do some computations * Now, the grammar is read. Do some computations
*/ */
co_reach(); /* Check for undefined and unreachable */ co_reach(); /* Check for undefined and unreachable */
if (nerrors) comfatal(); if (nerrors)
comfatal();
do_compute(); do_compute();
conflchecks(); conflchecks();
if (nerrors) comfatal(); if (nerrors)
comfatal();
fclose(fact); fclose(fact);
if (argc-- == 1) { if (argc-- == 1)
{
fputs("No code generation for input from standard input\n", fputs("No code generation for input from standard input\n",
stderr); stderr);
} }
else gencode(argc); else
gencode(argc);
UNLINK(f_temp); UNLINK(f_temp);
UNLINK(f_pars); UNLINK(f_pars);
if (verbose) { if (verbose)
{
fprintf(stderr, "number of nonterminals: %d\n", nnonterms); fprintf(stderr, "number of nonterminals: %d\n", nnonterms);
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);
} }
exit(0); exit(EXIT_SUCCESS);
} }
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
*/ */
register p_file p; register p_file p;
p_mem alloc(); p_mem alloc();
linecount = 0; linecount = 0;
f_input = "no filename"; f_input = "no filename";
/* /*
* Build the file structure * Build the file structure
*/ */
files = p = (p_file) alloc((unsigned) (argc+1) * sizeof(t_file)); files = p = (p_file) alloc((unsigned) (argc + 1) * sizeof(t_file));
if (argc-- == 1) { if (argc-- == 1)
{
finput = stdin; finput = stdin;
f_input = "standard input"; f_input = "standard input";
doparse(p++); doparse(p++);
} else { }
while (argc--) { else
if ((finput = fopen(f_input=argv[1],"r")) == NULL) { {
fatal(0,e_noopen,f_input); while (argc--)
{
if ((finput = fopen(f_input = argv[1], "r")) == NULL)
{
fatal(0, e_noopen, f_input);
} }
doparse(p++); doparse(p++);
argv++; argv++;
@ -235,19 +256,21 @@ readgrammar(argc,argv) char *argv[]; {
} }
} }
maxfiles = p; maxfiles = p;
if (! lexical) lexical = "yylex"; if (!lexical)
lexical = "yylex";
/* /*
* 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);
} }
if (nerrors) comfatal(); if (nerrors)
comfatal();
} }
STATIC STATIC void doparse(register p_file p)
doparse(p) register p_file p; { {
linecount = 0; linecount = 0;
p->f_name = f_input; p->f_name = f_input;
p->f_firsts = 0; p->f_firsts = 0;
@ -259,90 +282,100 @@ doparse(p) register p_file p; {
p->f_terminals = torder; p->f_terminals = torder;
} }
/* VARARGS1 */ void error(int lineno, string s, string t)
error(lineno,s,t,u) string s,t,u; { {
/* /*
* Just an error message * Just an error message
*/ */
++nerrors; ++nerrors;
if (!lineno) lineno = 1; if (!lineno)
fprintf(stderr,"\"%s\", line %d: ",f_input, lineno); lineno = 1;
fprintf(stderr,s,t,u); fprintf(stderr, "\"%s\", line %d: ", f_input, lineno);
fputs("\n",stderr); fprintf(stderr, s, t);
fputs("\n", stderr);
} }
/* VARARGS1 */ void warning(int lineno, string s, string t)
void {
warning(lineno,s,t,u) string s,t,u; {
/* /*
* Just a warning * Just a warning
*/ */
if (wflag) return; if (wflag)
if (!lineno) lineno = 1; return;
fprintf(stderr,"\"%s\", line %d: (Warning) ",f_input, lineno); if (!lineno)
fprintf(stderr,s,t,u); lineno = 1;
fputs("\n",stderr); fprintf(stderr, "\"%s\", line %d: (Warning) ", f_input, lineno);
fprintf(stderr, s, t);
fputs("\n", stderr);
} }
/* VARARGS1 */ void fatal(int lineno, string s, string t)
fatal(lineno,s,t,u) string s,t,u; { {
/* /*
* Fatal error * Fatal error
*/ */
error(lineno,s,t,u); error(lineno, s, t);
comfatal(); comfatal();
} }
comfatal() { STATIC void comfatal(void)
{
/* /*
* Some common code for exit on errors * Some common code for exit on errors
*/ */
if (fact != NULL) { if (fact != NULL)
{
fclose(fact); fclose(fact);
UNLINK(f_temp); UNLINK(f_temp);
} }
if (fpars != NULL) fclose(fpars); if (fpars != NULL)
fclose(fpars);
UNLINK(f_pars); UNLINK(f_pars);
exit(1); exit(EXIT_FAILURE);
} }
copyfile(file) string file; { void copyfile(string file)
{
/* /*
* Copies a file indicated by the parameter to filedescriptor fpars. * Copies a file indicated by the parameter to filedescriptor fpars.
*/ */
register int c; register int c;
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);
} }
while ((c = getc(f)) != EOF) putc(c,fpars); while ((c = getc(f)) != EOF)
putc(c, fpars);
fclose(f); fclose(f);
} }
void void install(string target, string source)
install(target, source) string target, 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
* by LLgen from the source, or that the target is not present * by LLgen from the source, or that the target is not present
*/ */
register int c1, c2; register int c1, c2;
register FILE *f1, *f2; register FILE *f1, *f2;
int cnt; int cnt;
/* /*
* 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);
} }
/* /*
* Now open target for reading * Now open target for reading
*/ */
if ((f2 = fopen(target,"r")) == NULL) { if ((f2 = fopen(target, "r")) == NULL)
{
fclose(f1); fclose(f1);
RENAME(f_pars, target); RENAME(f_pars, target);
return; return;
@ -355,20 +388,24 @@ install(target, source) string target, source; {
/* /*
* Now compare the target with the temporary * Now compare the target with the temporary
*/ */
do { do
{
c1 = getc(f1); c1 = getc(f1);
c2 = getc(f2); c2 = getc(f2);
if (cnt >= 0) cnt--; if (cnt >= 0)
cnt--;
} while (c1 == c2 && c1 != EOF); } while (c1 == c2 && c1 != EOF);
fclose(f1); fclose(f1);
fclose(f2); fclose(f2);
/* /*
* Here, if c1 != c2 the target must be recreated * Here, if c1 != c2 the target must be recreated
*/ */
if (c1 != c2) { if (c1 != c2)
if (cnt >= 0) { {
fatal(0,"%s : not a file generated by LLgen",target); if (cnt >= 0)
{
fatal(0, "%s : not a file generated by LLgen", target);
} }
RENAME(f_pars,target); RENAME(f_pars, target);
} }
} }

View file

@ -18,6 +18,8 @@
*/ */
#include <string.h> #include <string.h>
#include <stdio.h>
# include "alloc.h"
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include "assert.h" # include "assert.h"
@ -30,38 +32,36 @@ static string rcsid7 = "$Id$";
# 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 */
static char *name, *maxname; static char *name, *maxname;
static p_entry h_root[HASHSIZE]; /* hash table */ static p_entry h_root[HASHSIZE]; /* hash table */
static string e_literal = "Illegal literal"; static string e_literal = "Illegal literal";
static p_entry entries, maxentries; 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(); STATIC int hash(string str);
extern name_init(); STATIC p_entry newentry(string str, p_entry next);
STATIC int hash();
STATIC p_entry newentry();
extern p_gram search();
p_mem alloc();
p_mem new_mem();
name_init() {
token_info.i_esize = sizeof (t_token); void name_init(void)
{
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);
nont_info.i_incr = 50; nont_info.i_incr = 50;
search(TERMINAL,"EOFILE",ENTERING); search(TERMINAL, "EOFILE", ENTERING);
#ifdef NON_CORRECTING #ifdef NON_CORRECTING
illegal_gram = search(TERMINAL,"LLILLEGAL",ENTERING); illegal_gram = search(TERMINAL,"LLILLEGAL",ENTERING);
#endif #endif
} }
STATIC p_entry STATIC p_entry newentry(string 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)
{
p = (p_entry) alloc(50 * sizeof(t_entry)); p = (p_entry) alloc(50 * sizeof(t_entry));
maxentries = p + 50; maxentries = p + 50;
} }
@ -75,18 +75,20 @@ newentry(str, next) string str; p_entry next; {
return p; return p;
} }
string /*
store(s) string s; { * Store a string s in the name table
/* */
* Store a string s in the name table string store(string s)
*/ {
register string s1, t ,u; register string s1, t, u;
u = name; u = name;
t = s; t = s;
s1 = u; s1 = u;
do { do
if (u >= maxname) { {
if (u >= maxname)
{
u = alloc(NMSIZ); u = alloc(NMSIZ);
maxname = u + NMSIZ; maxname = u + NMSIZ;
t = s; t = s;
@ -98,60 +100,63 @@ store(s) string s; {
return s1; return s1;
} }
STATIC int /*
hash(str) string str; { * Compute the hash for string str
/* */
* Compute the hash for string str STATIC int hash(string str)
*/ {
register int i; register int i;
register string l; register string l;
l = str; l = str;
i = 0; i = 0;
while (*l != '\0') i += *l++ & 0377; while (*l != '\0')
i += *l++ & 0377;
i += l - str; i += l - str;
return i % HASHSIZE; return i % HASHSIZE;
} }
p_gram /*
search(type,str,option) register string str; { * Search for object str.
/* * It has type UNKNOWN, LITERAL, TERMINAL or NONTERM.
* Search for object str. * option can be ENTERING or BOTH (also looking).
* It has type UNKNOWN, LITERAL, TERMINAL or NONTERM. */
* option can be ENTERING or BOTH (also looking). p_gram search(int type, register string str, int option)
*/ {
register int val = 0; register int val = 0;
register p_entry p; register p_entry p;
register int i; register int i;
int type1; int type1;
i = hash(str); i = hash(str);
/* /*
* Walk hash chain * Walk hash chain
*/ */
for (p = h_root[i]; p != (p_entry) 0; p = p->h_next) { for (p = h_root[i]; p != (p_entry) 0; p = p->h_next)
if(!strcmp(p->h_name,str)) { {
if (!strcmp(p->h_name, str))
{
type1 = g_gettype(&(p->h_type)); type1 = g_gettype(&(p->h_type));
if (type1 != type) { if (type1 != type)
if (type1 == LITERAL || type == LITERAL) { {
if (type1 == LITERAL || type == LITERAL)
{
continue; continue;
} }
if (type == TERMINAL) { if (type == TERMINAL)
error(linecount, {
"%s: is already a nonterminal", error(linecount, "%s: is already a nonterminal", str);
str);
continue; continue;
} }
else if (type == NONTERM) { else if (type == NONTERM)
error(linecount, {
"%s : is already a token", error(linecount, "%s : is already a token", str);
str);
continue; continue;
} }
} }
if (option==ENTERING) { if (option == ENTERING)
error(linecount, {
"%s : is already defined",str); error(linecount, "%s : is already defined", str);
} }
p->h_type.g_lineno = linecount; p->h_type.g_lineno = linecount;
return &(p->h_type); return &(p->h_type);
@ -159,64 +164,76 @@ search(type,str,option) register string str; {
} }
p = newentry(store(str), h_root[i]); p = newentry(store(str), h_root[i]);
h_root[i] = p; h_root[i] = p;
if (type == TERMINAL || type == LITERAL) { if (type == TERMINAL || type == LITERAL)
{
register p_token pt; register p_token pt;
pt = (p_token) new_mem(&token_info); pt = (p_token) new_mem(&token_info);
tokens = (p_token) token_info.i_ptr; tokens = (p_token) token_info.i_ptr;
pt->t_string = p->h_name; pt->t_string = p->h_name;
if (type == LITERAL) { if (type == LITERAL)
if (str[0] == '\\') { {
if (str[0] == '\\')
{
/* /*
* Handle escapes in literals * Handle escapes in literals
*/ */
if (str[2] == '\0') { if (str[2] == '\0')
switch(str[1]) { {
case 'n' : switch (str[1])
{
case 'n':
val = '\n'; val = '\n';
break; break;
case 'r' : case 'r':
val = '\r'; val = '\r';
break; break;
case 'b' : case 'b':
val = '\b'; val = '\b';
break; break;
case 'f' : case 'f':
val = '\f'; val = '\f';
break; break;
case 't' : case 't':
val = '\t'; val = '\t';
break; break;
case '\'': case '\'':
val = '\''; val = '\'';
break; break;
case '\\': case '\\':
val = '\\'; val = '\\';
break; break;
default : default:
error(linecount,e_literal); error(linecount, e_literal, NULL);
} }
} else { }
else
{
/* /*
* Here, str[2] != '\0' * Here, str[2] != '\0'
*/ */
if (str[1] > '3' || str[1] < '0' || if (str[1] > '3' || str[1] < '0' || str[2] > '7'
str[2] > '7' || str[2] < '0' || || str[2] < '0' || str[3] > '7' || str[3] < '0'
str[3] > '7' || str[3] < '0' || || str[4] != '\0')
str[4] != '\0') error(linecount,e_literal); error(linecount, e_literal, NULL);
val = 64*str[1] - 73*'0' + val = 64 * str[1] - 73 * '0' + 8 * str[2] + str[3];
8*str[2] + str[3];
} }
} else { }
else
{
/* /*
* No escape in literal * No escape in literal
*/ */
if (str[1] == '\0') val = str[0]; if (str[1] == '\0')
else error(linecount,e_literal); val = str[0];
else
error(linecount, e_literal, NULL);
} }
pt->t_tokno = val; pt->t_tokno = val;
g_settype(&(p->h_type), LITERAL); g_settype(&(p->h_type), LITERAL);
} else { }
else
{
/* /*
* Here, type = TERMINAL * Here, type = TERMINAL
*/ */

View file

@ -17,6 +17,7 @@
* are all defined. * are all defined.
*/ */
#include <stdio.h>
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include "io.h" # include "io.h"
@ -26,12 +27,18 @@
static string rcsid8 = "$Id$"; static string rcsid8 = "$Id$";
# endif # endif
/* In this file the following routines are defined: */
extern co_reach();
STATIC reachable();
STATIC void reachwalk();
co_reach() {
/* In this file the following routines are defined: */
void co_reach(void);
STATIC void reachable(register p_nont p);
STATIC void reachwalk(p_gram p);
void co_reach(void)
{
/* /*
* Check for undefined or unreachable nonterminals. * Check for undefined or unreachable nonterminals.
*/ */
@ -80,8 +87,8 @@ co_reach() {
} }
} }
STATIC STATIC void reachable(register 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 +101,8 @@ reachable(p) register p_nont p; {
} }
} }
STATIC void 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

View file

@ -26,6 +26,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include "io.h" # include "io.h"
@ -69,7 +70,8 @@ static FILE *fgram;
used when LLgen called with -n -s options */ used when LLgen called with -n -s options */
int act_nt; int act_nt;
save_grammar(f) FILE *f; { void save_grammar(FILE *f)
{
/* /*
* Save the grammar * Save the grammar
*/ */
@ -267,8 +269,8 @@ save_grammar(f) FILE *f; {
fprintf(fgram, "#define LLNNONTERMINALS %d\n", nt_highest - assval + 1); fprintf(fgram, "#define LLNNONTERMINALS %d\n", nt_highest - assval + 1);
} }
STATIC void STATIC void save_rule(register p_gram p, int tail)
save_rule(p, tail) register p_gram p; int tail; { {
/* /*
Walk through rule p, saving it. The non-terminal tail is Walk through rule p, saving it. The non-terminal tail is
appended to the rule. It needs to be appended in this function appended to the rule. It needs to be appended in this function
@ -363,8 +365,8 @@ save_rule(p, tail) register p_gram p; int tail; {
} }
} }
STATIC void STATIC void save_set(p_set p)
save_set(p) p_set p; { {
register int k; register int k;
register unsigned i; register unsigned i;
int j; int j;

View file

@ -16,25 +16,17 @@
* Set manipulation and allocation routines. * Set manipulation and allocation routines.
*/ */
#include <stdio.h>
# include <assert.h>
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include "sets.h" # include "sets.h"
# include "assert.h"
# ifndef NORCSID # ifndef NORCSID
static string rcsid9 = "$Id$"; static string rcsid9 = "$Id$";
# endif # endif
/* In this file the following routines are defined: */
extern setinit();
extern p_set setalloc();
extern p_set get_set();
extern int setunion();
extern int setintersect();
extern setminus();
extern int setempty();
extern int findindex();
extern int setcount();
int nbytes; int nbytes;
static int setsize; static int setsize;
@ -43,10 +35,11 @@ p_set *setptr, *maxptr;
static t_info set_info; static t_info set_info;
p_mem alloc(); p_mem alloc();
setinit(nt_needed) { /*
/* * Initialises some variables needed for setcomputations
* Initialises some variables needed for setcomputations */
*/ void setinit(int nt_needed)
{
register int bitset; register int bitset;
nbytes = NBYTES(ntokens); nbytes = NBYTES(ntokens);
@ -61,8 +54,8 @@ setinit(nt_needed) {
set_info.i_incr = 20; set_info.i_incr = 20;
} }
p_set p_set get_set(void)
get_set() { {
/* /*
* Allocate a set that cannot be freed * Allocate a set that cannot be freed
*/ */
@ -80,8 +73,8 @@ get_set() {
return p; return p;
} }
p_set p_set setalloc(void)
setalloc() { {
/* /*
* Allocate a set which can later be freed. * Allocate a set which can later be freed.
*/ */
@ -95,8 +88,8 @@ setalloc() {
return p; return p;
} }
int int setunion(register p_set a,register p_set b)
setunion(a,b) register p_set a,b; { {
/* /*
* a = a union b. * a = a union b.
* Return 1 if the set a changed * Return 1 if the set a changed
@ -115,8 +108,8 @@ setunion(a,b) register p_set a,b; {
return nsub; return nsub;
} }
int int setintersect(register p_set a,register p_set b)
setintersect(a,b) register p_set a,b; { {
/* /*
* a = a intersect b. * a = a intersect b.
* return 1 if the result is empty * return 1 if the result is empty
@ -132,7 +125,8 @@ setintersect(a,b) register p_set a,b; {
return nempty; return nempty;
} }
setminus(a,b) register p_set a,b; { void setminus(register p_set a,register p_set b)
{
/* /*
* a = a setminus b * a = a setminus b
*/ */
@ -144,8 +138,8 @@ setminus(a,b) register p_set a,b; {
} while (--i); } while (--i);
} }
int int setempty(register p_set p)
setempty(p) register p_set p; { {
/* /*
* Return 1 if the set p is empty * Return 1 if the set p is empty
*/ */
@ -158,8 +152,8 @@ setempty(p) register p_set p; {
return 1; return 1;
} }
int int findindex(p_set set)
findindex(set) p_set set; { {
/* /*
* The set "set" will serve as a recovery set. * The set "set" will serve as a recovery set.
* Search for it in the table. If not present, enter it. * Search for it in the table. If not present, enter it.
@ -204,8 +198,8 @@ findindex(set) p_set set; {
return nbytes * (maxptr++ - setptr); return nbytes * (maxptr++ - setptr);
} }
int int setcount(register p_set set, int *saved)
setcount(set, saved) register p_set set; int *saved; { {
register int i, j; register int i, j;
for (j = 0, i = 0; i < ntokens; i++) { for (j = 0, i = 0; i < ntokens; i++) {

View file

@ -2,6 +2,8 @@
* For full copyright and restrictions on use see the file COPYING in the top * For full copyright and restrictions on use see the file COPYING in the top
* level of the LLgen tree. * level of the LLgen tree.
*/ */
#ifndef SETS_H_
#define SETS_H_
/* /*
* L L G E N * L L G E N
@ -31,3 +33,44 @@
extern int tsetsize; extern int tsetsize;
extern p_set *setptr, *maxptr; extern p_set *setptr, *maxptr;
extern int nbytes; extern int nbytes;
/*
* Initialises some variables needed for setcomputations
*/
void setinit(int nt_needed);
/*
* Allocate a set that cannot be freed
*/
p_set get_set(void);
/*
* Allocate a set which can later be freed.
*/
p_set setalloc(void);
/*
* a = a union b.
* Return 1 if the set a changed
*/
int setunion(register p_set a,register p_set b);
/*
* a = a intersect b.
* return 1 if the result is empty
*/
int setintersect(register p_set a,register p_set b);
/*
* a = a setminus b
*/
void setminus(register p_set a,register p_set b);
/*
* Return 1 if the set p is empty
*/
int setempty(register p_set p);
/*
* The set "set" will serve as a recovery set.
* Search for it in the table. If not present, enter it.
* Here is room for improvement. At the moment, the list of
* sets is examined with linear search.
*/
int findindex(p_set set);
int setcount(register p_set set, int *saved);
#endif /* SETS_H_ */

View file

@ -2,9 +2,6 @@
#include "Lpars.h" #include "Lpars.h"
#define LL_LEXI scanner #define LL_LEXI scanner
#define LLNOFIRSTS #define LLNOFIRSTS
#if __STDC__ || __cplusplus
#define LL_ANSI_C 1
#endif
#define LL_LEXI scanner #define LL_LEXI scanner
/* $Id$ */ /* $Id$ */
#ifdef LL_DEBUG #ifdef LL_DEBUG
@ -38,7 +35,6 @@ extern int LLstartsymb;
#define LLsincr(d) LLscnt[d]++ #define LLsincr(d) LLscnt[d]++
#define LLtincr(d) LLtcnt[d]++ #define LLtincr(d) LLtcnt[d]++
#if LL_ANSI_C
extern int LL_LEXI(void); extern int LL_LEXI(void);
extern void LLread(void); extern void LLread(void);
extern int LLskip(void); extern int LLskip(void);
@ -56,29 +52,11 @@ extern int LLfirst(int, int);
#if LL_NON_CORR #if LL_NON_CORR
extern void LLnc_recover(void); extern void LLnc_recover(void);
#endif #endif
#else /* not LL_ANSI_C */
extern LLread();
extern int LLskip();
extern int LLnext();
extern LLerror();
extern LLsafeerror();
extern LLnewlevel();
extern LLoldlevel();
#ifndef LL_FASTER
extern LLscan();
#endif
#ifndef LLNOFIRSTS
extern int LLfirst();
#endif
#if LL_NON_CORR
extern LLnc_recover();
#endif
#endif /* not LL_ANSI_C */
# line 20 "tokens.g" # line 20 "tokens.g"
#include <string.h> #include <string.h>
# include "types.h" #include "types.h"
# include "io.h" # include "io.h"
# include "extern.h" # include "extern.h"
# include "assert.h" # include "assert.h"
@ -89,17 +67,17 @@ static string rcsidc = "$Id$";
# endif # endif
/* Here are defined : */ /* Here are defined : */
extern int scanner(); int scanner(void);
extern LLmessage(); void LLmessage(int d);
extern int input(); int input(void);
extern unput(); void unput(int c);
extern void skipcomment(); void skipcomment(int flag);
# ifdef LINE_DIRECTIVE # ifdef LINE_DIRECTIVE
STATIC linedirective(); STATIC void linedirective(void);
# endif # endif
STATIC string cpy(); STATIC string cpy(int s,register string p,int inserted);
STATIC string vallookup(); STATIC string vallookup(int s);
STATIC void copyact(); STATIC void copyact(char ch1,char ch2,int flag,int level);
static int nparams; static int nparams;
# line 76 "tokens.g" # line 76 "tokens.g"
@ -145,8 +123,8 @@ static t_token savedtok; /* to save lextoken in case of an insertion */
static int nostartline; /* = 0 if at the start of a line */ static int nostartline; /* = 0 if at the start of a line */
# endif # endif
STATIC void STATIC void copyact(char ch1,char ch2,int flag,int level)
copyact(ch1,ch2,flag,level) char ch1,ch2; { {
/* /*
* Copy an action to file f. Opening bracket is ch1, closing bracket * Copy an action to file f. Opening bracket is ch1, closing bracket
* is ch2. * is ch2.
@ -155,8 +133,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
*/ */
static int text_seen = 0; static int text_seen = 0;
register FILE *f; register FILE *f;
register ch; /* Current char */ register int ch; /* Current char */
register match; /* used to read strings */ register int match; /* used to read strings */
int saved = linecount; int saved = linecount;
/* save linecount */ /* save linecount */
int sav_strip = strip_grammar; int sav_strip = strip_grammar;
@ -187,7 +165,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
case ')': case ')':
case '}': case '}':
case ']': case ']':
error(linecount,"Parentheses mismatch"); error(linecount,"Parentheses mismatch", NULL);
break; break;
case '(': case '(':
text_seen = 1; text_seen = 1;
@ -218,7 +196,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
text_seen = 0; text_seen = 0;
nparams++; nparams++;
if (ch == ',' && (flag & 2)) { if (ch == ',' && (flag & 2)) {
warning(linecount, "Parameters may not be separated with a ','"); warning(linecount, "Parameters may not be separated with a ','",NULL);
ch = ';'; ch = ';';
} }
} }
@ -239,7 +217,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
ch = input(); ch = input();
} }
if (ch == '\n') { if (ch == '\n') {
error(linecount,"Newline in string"); error(linecount,"Newline in string", NULL);
unput(match); unput(match);
} }
putc(ch,f); putc(ch,f);
@ -247,7 +225,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
if (ch == match) break; if (ch == match) break;
/* Fall through */ /* Fall through */
case EOF : case EOF :
if (!level) error(saved,"Action does not terminate"); if (!level) error(saved,"Action does not terminate", NULL);
strip_grammar = sav_strip; strip_grammar = sav_strip;
return; return;
default: default:
@ -257,7 +235,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
} }
} }
scanner() { int scanner(void)
{
/* /*
* Lexical analyser, what else * Lexical analyser, what else
*/ */
@ -307,7 +286,7 @@ scanner() {
for (;;) { for (;;) {
ch = input(); ch = input();
if (ch == '\n' || ch == EOF) { if (ch == '\n' || ch == EOF) {
error(linecount,"Missing '"); error(linecount,"Missing '", NULL);
break; break;
} }
if (ch == '\'') break; if (ch == '\'') break;
@ -327,7 +306,7 @@ scanner() {
case ISSPA : case ISSPA :
continue; continue;
case ISDIG : { case ISDIG : {
register i = 0; register int i = 0;
do { do {
i = 10 * i + (ch - '0'); i = 10 * i + (ch - '0');
ch= input(); ch= input();
@ -371,7 +350,7 @@ scanner() {
} }
w++; w++;
} }
error(linecount,"Illegal reserved word"); error(linecount,"Illegal reserved word",NULL);
} }
lextoken.t_string = ltext; lextoken.t_string = ltext;
return C_IDENT; return C_IDENT;
@ -382,11 +361,12 @@ scanner() {
static int backupc; /* for unput() */ static int backupc; /* for unput() */
static int nonline; /* = 1 if last char read was a newline */ static int nonline; /* = 1 if last char read was a newline */
input() { int input(void)
{
/* /*
* Low level input routine, used by all other input routines * Low level input routine, used by all other input routines
*/ */
register c; register int c;
if (c = backupc) { if (c = backupc) {
/* Last char was "unput()". Deliver it again /* Last char was "unput()". Deliver it again
@ -413,15 +393,16 @@ input() {
return c; return c;
} }
unput(c) { void unput(int c)
{
/* /*
* "unread" c * "unread" c
*/ */
backupc = c; backupc = c;
} }
void void skipcomment(int flag)
skipcomment(flag) { {
/* /*
* Skip comment. If flag != 0, the comment is inside a fragment * Skip comment. If flag != 0, the comment is inside a fragment
* of C-code, so keep it. * of C-code, so keep it.
@ -430,7 +411,7 @@ skipcomment(flag) {
int saved; /* line count on which comment starts */ int saved; /* line count on which comment starts */
saved = linecount; saved = linecount;
if (input() != '*') error(linecount,"Illegal comment"); if (input() != '*') error(linecount,"Illegal comment",NULL);
if (flag) putc('*', fact); if (flag) putc('*', fact);
do { do {
ch = input(); ch = input();
@ -441,12 +422,12 @@ skipcomment(flag) {
if (ch == '/') return; if (ch == '/') return;
} }
} while (ch != EOF); } while (ch != EOF);
error(saved,"Comment does not terminate"); error(saved,"Comment does not terminate", NULL);
} }
# ifdef LINE_DIRECTIVE # ifdef LINE_DIRECTIVE
STATIC STATIC void linedirective(void)
linedirective() { {
/* /*
* Read a line directive * Read a line directive
*/ */
@ -463,7 +444,7 @@ linedirective() {
ch = input(); ch = input();
} while (ch != '\n' && c_class[ch] != ISDIG); } while (ch != '\n' && c_class[ch] != ISDIG);
if (ch == '\n') { if (ch == '\n') {
error(linecount,s_error); error(linecount,s_error, NULL);
return; return;
} }
i = 0; i = 0;
@ -478,7 +459,7 @@ linedirective() {
*c++ = ch = input(); *c++ = ch = input();
} while (ch != '"' && ch != '\n'); } while (ch != '"' && ch != '\n');
if (ch == '\n') { if (ch == '\n') {
error(linecount,s_error); error(linecount,s_error, NULL);
return; return;
} }
*--c = '\0'; *--c = '\0';
@ -494,8 +475,8 @@ linedirective() {
} }
# endif # endif
STATIC string STATIC string vallookup(int s)
vallookup(s) { {
/* /*
* Look up the keyword that has token number s * Look up the keyword that has token number s
*/ */
@ -508,8 +489,8 @@ vallookup(s) {
return 0; return 0;
} }
STATIC string STATIC string cpy(int s,register string p,int inserted)
cpy(s,p,inserted) register string p; { {
/* /*
* Create a piece of error message for token s and put it at p. * Create a piece of error message for token s and put it at p.
* inserted = 0 if the token s was deleted (in which case we have * inserted = 0 if the token s was deleted (in which case we have
@ -579,7 +560,9 @@ cpy(s,p,inserted) register string p; {
return p; return p;
} }
LLmessage(d) {
void LLmessage(int d)
{
/* /*
* d is either 0, in which case the current token has been deleted, * d is either 0, in which case the current token has been deleted,
* or non-zero, in which case it represents a token that is inserted * or non-zero, in which case it represents a token that is inserted

View file

@ -19,7 +19,7 @@
{ {
#include <string.h> #include <string.h>
# include "types.h" #include "types.h"
# include "io.h" # include "io.h"
# include "extern.h" # include "extern.h"
# include "assert.h" # include "assert.h"
@ -30,17 +30,17 @@ static string rcsidc = "$Id$";
# endif # endif
/* Here are defined : */ /* Here are defined : */
extern int scanner(); int scanner(void);
extern LLmessage(); void LLmessage(int d);
extern int input(); int input(void);
extern unput(); void unput(int c);
extern void skipcomment(); void skipcomment(int flag);
# ifdef LINE_DIRECTIVE # ifdef LINE_DIRECTIVE
STATIC linedirective(); STATIC void linedirective(void);
# endif # endif
STATIC string cpy(); STATIC string cpy(int s,register string p,int inserted);
STATIC string vallookup(); STATIC string vallookup(int s);
STATIC void copyact(); STATIC void copyact(char ch1,char ch2,int flag,int level);
static int nparams; static int nparams;
} }
@ -115,8 +115,8 @@ static t_token savedtok; /* to save lextoken in case of an insertion */
static int nostartline; /* = 0 if at the start of a line */ static int nostartline; /* = 0 if at the start of a line */
# endif # endif
STATIC void STATIC void copyact(char ch1,char ch2,int flag,int level)
copyact(ch1,ch2,flag,level) char ch1,ch2; { {
/* /*
* Copy an action to file f. Opening bracket is ch1, closing bracket * Copy an action to file f. Opening bracket is ch1, closing bracket
* is ch2. * is ch2.
@ -125,8 +125,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
*/ */
static int text_seen = 0; static int text_seen = 0;
register FILE *f; register FILE *f;
register ch; /* Current char */ register int ch; /* Current char */
register match; /* used to read strings */ register int match; /* used to read strings */
int saved = linecount; int saved = linecount;
/* save linecount */ /* save linecount */
int sav_strip = strip_grammar; int sav_strip = strip_grammar;
@ -157,7 +157,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
case ')': case ')':
case '}': case '}':
case ']': case ']':
error(linecount,"Parentheses mismatch"); error(linecount,"Parentheses mismatch", NULL);
break; break;
case '(': case '(':
text_seen = 1; text_seen = 1;
@ -188,7 +188,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
text_seen = 0; text_seen = 0;
nparams++; nparams++;
if (ch == ',' && (flag & 2)) { if (ch == ',' && (flag & 2)) {
warning(linecount, "Parameters may not be separated with a ','"); warning(linecount, "Parameters may not be separated with a ','",NULL);
ch = ';'; ch = ';';
} }
} }
@ -209,7 +209,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
ch = input(); ch = input();
} }
if (ch == '\n') { if (ch == '\n') {
error(linecount,"Newline in string"); error(linecount,"Newline in string", NULL);
unput(match); unput(match);
} }
putc(ch,f); putc(ch,f);
@ -217,7 +217,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
if (ch == match) break; if (ch == match) break;
/* Fall through */ /* Fall through */
case EOF : case EOF :
if (!level) error(saved,"Action does not terminate"); if (!level) error(saved,"Action does not terminate", NULL);
strip_grammar = sav_strip; strip_grammar = sav_strip;
return; return;
default: default:
@ -227,7 +227,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
} }
} }
scanner() { int scanner(void)
{
/* /*
* Lexical analyser, what else * Lexical analyser, what else
*/ */
@ -277,7 +278,7 @@ scanner() {
for (;;) { for (;;) {
ch = input(); ch = input();
if (ch == '\n' || ch == EOF) { if (ch == '\n' || ch == EOF) {
error(linecount,"Missing '"); error(linecount,"Missing '", NULL);
break; break;
} }
if (ch == '\'') break; if (ch == '\'') break;
@ -297,7 +298,7 @@ scanner() {
case ISSPA : case ISSPA :
continue; continue;
case ISDIG : { case ISDIG : {
register i = 0; register int i = 0;
do { do {
i = 10 * i + (ch - '0'); i = 10 * i + (ch - '0');
ch= input(); ch= input();
@ -341,7 +342,7 @@ scanner() {
} }
w++; w++;
} }
error(linecount,"Illegal reserved word"); error(linecount,"Illegal reserved word",NULL);
} }
lextoken.t_string = ltext; lextoken.t_string = ltext;
return C_IDENT; return C_IDENT;
@ -352,11 +353,12 @@ scanner() {
static int backupc; /* for unput() */ static int backupc; /* for unput() */
static int nonline; /* = 1 if last char read was a newline */ static int nonline; /* = 1 if last char read was a newline */
input() { int input(void)
{
/* /*
* Low level input routine, used by all other input routines * Low level input routine, used by all other input routines
*/ */
register c; register int c;
if (c = backupc) { if (c = backupc) {
/* Last char was "unput()". Deliver it again /* Last char was "unput()". Deliver it again
@ -383,15 +385,16 @@ input() {
return c; return c;
} }
unput(c) { void unput(int c)
{
/* /*
* "unread" c * "unread" c
*/ */
backupc = c; backupc = c;
} }
void void skipcomment(int flag)
skipcomment(flag) { {
/* /*
* Skip comment. If flag != 0, the comment is inside a fragment * Skip comment. If flag != 0, the comment is inside a fragment
* of C-code, so keep it. * of C-code, so keep it.
@ -400,7 +403,7 @@ skipcomment(flag) {
int saved; /* line count on which comment starts */ int saved; /* line count on which comment starts */
saved = linecount; saved = linecount;
if (input() != '*') error(linecount,"Illegal comment"); if (input() != '*') error(linecount,"Illegal comment",NULL);
if (flag) putc('*', fact); if (flag) putc('*', fact);
do { do {
ch = input(); ch = input();
@ -411,12 +414,12 @@ skipcomment(flag) {
if (ch == '/') return; if (ch == '/') return;
} }
} while (ch != EOF); } while (ch != EOF);
error(saved,"Comment does not terminate"); error(saved,"Comment does not terminate", NULL);
} }
# ifdef LINE_DIRECTIVE # ifdef LINE_DIRECTIVE
STATIC STATIC void linedirective(void)
linedirective() { {
/* /*
* Read a line directive * Read a line directive
*/ */
@ -433,7 +436,7 @@ linedirective() {
ch = input(); ch = input();
} while (ch != '\n' && c_class[ch] != ISDIG); } while (ch != '\n' && c_class[ch] != ISDIG);
if (ch == '\n') { if (ch == '\n') {
error(linecount,s_error); error(linecount,s_error, NULL);
return; return;
} }
i = 0; i = 0;
@ -448,7 +451,7 @@ linedirective() {
*c++ = ch = input(); *c++ = ch = input();
} while (ch != '"' && ch != '\n'); } while (ch != '"' && ch != '\n');
if (ch == '\n') { if (ch == '\n') {
error(linecount,s_error); error(linecount,s_error, NULL);
return; return;
} }
*--c = '\0'; *--c = '\0';
@ -464,8 +467,8 @@ linedirective() {
} }
# endif # endif
STATIC string STATIC string vallookup(int s)
vallookup(s) { {
/* /*
* Look up the keyword that has token number s * Look up the keyword that has token number s
*/ */
@ -478,8 +481,8 @@ vallookup(s) {
return 0; return 0;
} }
STATIC string STATIC string cpy(int s,register string p,int inserted)
cpy(s,p,inserted) register string p; { {
/* /*
* Create a piece of error message for token s and put it at p. * Create a piece of error message for token s and put it at p.
* inserted = 0 if the token s was deleted (in which case we have * inserted = 0 if the token s was deleted (in which case we have
@ -549,7 +552,9 @@ cpy(s,p,inserted) register string p; {
return p; return p;
} }
LLmessage(d) {
void LLmessage(int d)
{
/* /*
* d is either 0, in which case the current token has been deleted, * d is either 0, in which case the current token has been deleted,
* or non-zero, in which case it represents a token that is inserted * or non-zero, in which case it represents a token that is inserted

View file

@ -2,6 +2,8 @@
* For full copyright and restrictions on use see the file COPYING in the top * For full copyright and restrictions on use see the file COPYING in the top
* level of the LLgen tree. * level of the LLgen tree.
*/ */
#ifndef TYPES_H_
#define TYPES_H_
/* /*
* L L G E N * L L G E N
@ -270,3 +272,5 @@ typedef struct info_alloc {
# else /* not NDEBUG */ # else /* not NDEBUG */
# define STATIC extern # define STATIC extern
# endif /* not NDEBUG */ # endif /* not NDEBUG */
#endif /* TYPES_H_ */