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

View file

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

View file

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

View file

@ -17,6 +17,7 @@
*/
#include <stdlib.h>
# include "alloc.h"
# include "types.h"
# include "extern.h"
@ -26,29 +27,29 @@ static string rcsid = "$Id$";
static string e_nomem = "Out of memory";
p_mem
alloc(size) unsigned size; {
p_mem alloc(unsigned int size)
{
/*
Allocate "size" bytes. Panic if it fails
*/
p_mem p;
if ((p = malloc(size)) == 0) fatal(linecount,e_nomem);
if ((p = malloc(size)) == 0) fatal(linecount,e_nomem, NULL);
return p;
}
p_mem
ralloc(p,size) p_mem p; unsigned size; {
p_mem ralloc(p_mem p,unsigned int size)
{
/*
Re-allocate the chunk of memory indicated by "p", to
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;
}
p_mem
new_mem(p) register p_info p; {
p_mem new_mem(register p_info p)
{
/*
This routine implements arrays that can grow.
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 <stdio.h>
#include <string.h>
# include "types.h"
# include "extern.h"
@ -28,247 +29,287 @@
static string rcsid1 = "$Id$";
# endif
static string c_first = "> firstset ";
static string c_contains = "> containset ";
static string c_follow = "> followset ";
p_set setalloc();
static int level;
static string c_first = "> firstset ";
static string c_contains = "> containset ";
static string c_follow = "> followset ";
p_set setalloc();
static int level;
/* In this file are defined : */
extern conflchecks();
STATIC prline();
STATIC printset();
STATIC int check();
STATIC moreverbose();
STATIC void prrule(p_gram p);
STATIC cfcheck();
STATIC void resolve(p_gram p);
STATIC propagate();
STATIC spaces();
void conflchecks(void);
STATIC void prline(char *);
STATIC void printset(register p_set, string);
STATIC int check(register p_gram);
STATIC void moreverbose(register p_set);
STATIC void prrule(p_gram);
STATIC void cfcheck(p_set, p_set, int);
STATIC void resolve(p_gram);
STATIC void propagate(p_set, register p_gram);
STATIC void spaces(void);
conflchecks() {
/*
* Check for conflicts, that is,
* in a repeating term, the FIRST and FOLLOW must be disjunct,
* unless there is a disambiguating condition.
* in an alternation, the sets that determine the direction to take,
* must be disjunct.
*/
register p_nont p;
/*
* Check for conflicts, that is,
* in a repeating term, the FIRST and FOLLOW must be disjunct,
* unless there is a disambiguating condition.
* in an alternation, the sets that determine the direction to take,
* must be disjunct.
*/
void conflchecks(void)
{
register p_nont p;
register int s;
p_file x = files;
p_file x = files;
f_input = x->f_name;
if (verbose >= 3) {
for (p = nonterms; p < maxnt; p++) p->n_flags |= VERBOSE;
if (verbose >= 3)
{
for (p = nonterms; p < maxnt; p++)
p->n_flags |= VERBOSE;
}
if (verbose) {
if ((fout = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out);
if (verbose)
{
if ((fout = fopen(f_out, "w")) == NULL)
fatal(1, e_noopen, f_out);
}
/*
* Check the rules in the order in which they are declared,
* and input file by input file, to give proper error messages
*/
for (; x < maxfiles; x++) {
f_input = x->f_name;
for (s = x->f_nonterminals; s != -1; s = p->n_next) {
p = &nonterms[s];
if (check(p->n_rule)) p->n_flags |= VERBOSE;
}
}
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);
for (; x < maxfiles; x++)
{
f_input = x->f_name;
for (s = x->f_nonterminals; s != -1; s = p->n_next)
{
p = &nonterms[s];
if (check(p->n_rule))
p->n_flags |= VERBOSE;
}
/*
* 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
prline(s) char *s; {
STATIC void prline(char *s)
{
fputs(s, fout);
spaces();
}
STATIC
printset(p,s) register p_set p; string s; {
STATIC void printset(register p_set p, string s)
{
/*
* Print the elements of a set
*/
register int i;
register int j;
register int i;
register int j;
register p_token pt;
string name;
int k;
int hulp;
string name;
int k;
int hulp;
k = strlen(s) + 2 + level;
/*
* k contains relative level of indentation
*/
fprintf(fout,"%s{ ",s);
fprintf(fout, "%s{ ", s);
j = k;
/*
* j will gather the total length of the line
*/
for (i = 0, pt = tokens; i < ntokens; i++,pt++) {
if (IN(p,i)) {
hulp = strlen(pt->t_string)+1;
if (pt->t_tokno < 0400) hulp += 2;
if ((j += hulp) >= 78) {
for (i = 0, pt = tokens; i < ntokens; i++, pt++)
{
if (IN(p, i))
{
hulp = strlen(pt->t_string) + 1;
if (pt->t_tokno < 0400)
hulp += 2;
if ((j += hulp) >= 78)
{
/*
* 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;
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");
}
STATIC int
check(p) register p_gram p; {
STATIC int check(register p_gram p)
{
/*
* Search for conflicts in a grammar rule.
*/
register p_set temp;
register p_set temp;
register int retval;
retval = 0;
for (;;) {
switch (g_gettype(p)) {
case EORULE :
for (;;)
{
switch (g_gettype(p))
{
case EORULE:
return retval;
case NONTERM : {
case NONTERM:
{
register p_nont n;
n = &nonterms[g_getcont(p)];
if (g_getnpar(p) != getntparams(n)) {
error(p->g_lineno,
"Call of %s: parameter count mismatch",
n->n_name);
if (g_getnpar(p) != getntparams(n))
{
error(p->g_lineno, "Call of %s: parameter count mismatch",
n->n_name);
}
break; }
case TERM : {
break;
}
case TERM:
{
register p_term q;
q = g_getterm(p);
retval |= check(q->t_rule);
if (r_getkind(q) == FIXED) break;
if (setempty(q->t_first)) {
if (r_getkind(q) == FIXED)
break;
if (setempty(q->t_first))
{
q->t_flags |= EMPTYFIRST;
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;
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();
setunion(temp,q->t_first);
if (!setintersect(temp,q->t_follow)) {
setunion(temp, q->t_first);
if (!setintersect(temp, q->t_follow))
{
/*
* q->t_first * q->t_follow != EMPTY
*/
if (!(q->t_flags & RESOLVER)) {
if (!(q->t_flags & RESOLVER))
{
/*
* No conflict resolver
*/
error(p->g_lineno,
"Repetition conflict");
error(p->g_lineno, "Repetition conflict", NULL);
retval = 1;
moreverbose(temp);
}
}
else {
if (q->t_flags & RESOLVER) {
else
{
if (q->t_flags & RESOLVER)
{
q->t_flags |= NOCONF;
warning(p->g_lineno,
"%%while without conflict");
warning(p->g_lineno, "%%while without conflict", NULL);
}
}
free((p_mem) temp);
break; }
case ALTERNATION : {
break;
}
case ALTERNATION:
{
register p_link l;
l = g_getlink(p);
temp = setalloc();
setunion(temp,l->l_symbs);
if(!setintersect(temp,l->l_others)) {
setunion(temp, l->l_symbs);
if (!setintersect(temp, l->l_others))
{
/*
* temp now contains the conflicting
* symbols
*/
if (!(l->l_flag & (COND|PREFERING|AVOIDING))) {
error(p->g_lineno,
"Alternation conflict");
if (!(l->l_flag & (COND | PREFERING | AVOIDING)))
{
error(p->g_lineno, "Alternation conflict", NULL);
retval = 1;
moreverbose(temp);
}
} else {
if (l->l_flag & (COND|PREFERING|AVOIDING)) {
}
else
{
if (l->l_flag & (COND | PREFERING | AVOIDING))
{
l->l_flag |= NOCONF;
warning(p->g_lineno,
"Conflict resolver without conflict");
warning(p->g_lineno, "Conflict resolver without conflict",
NULL);
}
}
free( (p_mem) temp);
if (l->l_flag & PREFERING) propagate(l->l_symbs,p+1);
free((p_mem) temp);
if (l->l_flag & PREFERING)
propagate(l->l_symbs, p + 1);
retval |= check(l->l_rule);
break; }
break;
}
}
p++;
}
}
STATIC
moreverbose(t) register p_set t; {
STATIC void moreverbose(register p_set t)
{
/*
* t points to a set containing conflicting symbols and pssibly
* also containing nonterminals.
@ -277,116 +318,141 @@ moreverbose(t) register p_set t; {
register int i;
register p_nont p;
if (verbose == 2) for (i = 0, p = nonterms; i < nnonterms; i++, p++) {
if (NTIN(t,i)) p->n_flags |= VERBOSE;
}
if (verbose == 2)
for (i = 0, p = nonterms; i < nnonterms; i++, p++)
{
if (NTIN(t, i))
p->n_flags |= VERBOSE;
}
}
STATIC
void prrule(p_gram p) {
STATIC void prrule(p_gram p)
{
/*
* Create a verbose printout of grammar rule p
*/
register FILE *f;
int present = 0;
int firstalt = 1;
register FILE *f;
int present = 0;
int firstalt = 1;
f = fout;
for (;;) {
switch (g_gettype(p)) {
case EORULE :
fputs("\n",f);
for (;;)
{
switch (g_gettype(p))
{
case EORULE:
fputs("\n", f);
return;
case TERM : {
register p_term q;
register int c;
case TERM:
{
register p_term q;
register int c;
q = g_getterm(p);
if (present) prline("\n");
fputs("[ ",f);
if (present)
prline("\n");
fputs("[ ", f);
level += 4;
if (q->t_flags & RESOLVER) {
if (q->t_flags & RESOLVER)
{
prline("%while (..)\n");
}
if (q->t_flags & PERSISTENT) {
if (q->t_flags & PERSISTENT)
{
prline("%persistent\n");
}
if (r_getkind(q) != FIXED) {
if (!(q->t_flags & PERSISTENT)) {
prline("> continue repetition on the\n");
if (r_getkind(q) != FIXED)
{
if (!(q->t_flags & PERSISTENT))
{
prline("> continue repetition on the\n");
}
printset(q->t_first, c_first);
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_contains, c_contains);
prline("> terminate repetition on the\n");
printset(q->t_follow,c_follow);
if (q->t_flags & EMPTYFIRST) {
prline(">>> empty first\n");
printset(q->t_follow, c_follow);
if (q->t_flags & EMPTYFIRST)
{
prline(">>> empty first\n");
}
if (q->t_flags & EMPTYTERM) {
prline(">>> term produces empty\n");
if (q->t_flags & EMPTYTERM)
{
prline(">>> term produces empty\n");
}
cfcheck(q->t_first,q->t_follow,
q->t_flags & RESOLVER);
cfcheck(q->t_first, q->t_follow, q->t_flags & RESOLVER);
}
prrule(q->t_rule);
level -= 4;
spaces();
c = r_getkind(q);
fputs(c == STAR ? "]*" : c == PLUS ? "]+" :
c == OPT ? "]?" : "]", f);
if (c = r_getnum(q)) {
fprintf(f,"%d",c);
fputs(c == STAR ? "]*" : c == PLUS ? "]+" : c == OPT ? "]?" : "]",
f);
if ((c = r_getnum(q)))
{
fprintf(f, "%d", c);
}
prline("\n");
break; }
case ACTION :
fputs("{..} ",f);
break;
case ALTERNATION : {
}
case ACTION:
fputs("{..} ", f);
break;
case ALTERNATION:
{
register p_link l;
l = g_getlink(p);
if (firstalt) {
if (firstalt)
{
firstalt = 0;
}
else prline("|\n");
printset(l->l_symbs,"> alternative on ");
cfcheck(l->l_symbs,
l->l_others,
(int)(l->l_flag&(COND|PREFERING|AVOIDING)));
fputs(" ",f);
else
prline("|\n");
printset(l->l_symbs, "> alternative on ");
cfcheck(l->l_symbs, l->l_others,
(int) (l->l_flag & (COND | PREFERING | AVOIDING)));
fputs(" ", f);
level += 4;
if (l->l_flag & DEF) {
if (l->l_flag & DEF)
{
prline("%default\n");
}
if (l->l_flag & AVOIDING) {
if (l->l_flag & AVOIDING)
{
prline("%avoid\n");
}
if (l->l_flag & PREFERING) {
if (l->l_flag & PREFERING)
{
prline("%prefer\n");
}
if (l->l_flag & COND) {
if (l->l_flag & COND)
{
prline("%if ( ... )\n");
}
prrule(l->l_rule);
level -= 4;
if (g_gettype(p+1) == EORULE) {
if (g_gettype(p+1) == EORULE)
{
return;
}
spaces();
p++; continue; }
case LITERAL :
case TERMINAL : {
p++;
continue;
}
case LITERAL:
case TERMINAL:
{
register p_token pt = &tokens[g_getcont(p)];
fprintf(f,pt->t_tokno<0400 ?
"'%s' " : "%s ", pt->t_string);
break; }
case NONTERM :
fprintf(f,"%s ",nonterms[g_getcont(p)].n_name);
fprintf(f, pt->t_tokno < 0400 ? "'%s' " : "%s ", pt->t_string);
break;
}
case NONTERM:
fprintf(f, "%s ", nonterms[g_getcont(p)].n_name);
break;
}
p++;
@ -394,8 +460,8 @@ void prrule(p_gram p) {
}
}
STATIC
cfcheck(s1,s2,flag) p_set s1,s2; {
STATIC void cfcheck(p_set s1, p_set s2, int flag)
{
/*
* Check if s1 and s2 have elements in common.
* 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;
temp = setalloc();
setunion(temp,s1);
if (!setintersect(temp,s2)) {
if (! flag) {
printset(temp,">>> conflict on ");
setunion(temp, s1);
if (!setintersect(temp, s2))
{
if (!flag)
{
printset(temp, ">>> conflict on ");
prline("\n");
}
} else {
if (flag) {
}
else
{
if (flag)
{
prline(">>> %if/%while, no conflict\n");
}
}
free((p_mem) temp);
}
STATIC
void resolve(p_gram p) {
STATIC void resolve(p_gram p)
{
/*
* resolve conflicts, as specified by the user
*/
for (;;) {
switch (g_gettype(p)) {
case EORULE :
for (;;)
{
switch (g_gettype(p))
{
case EORULE:
return;
case TERM :
case TERM:
resolve(g_getterm(p)->t_rule);
break;
case ALTERNATION : {
register p_link l;
case ALTERNATION:
{
register p_link l;
l = g_getlink(p);
if (l->l_flag & AVOIDING) {
if (l->l_flag & AVOIDING)
{
/*
* On conflicting symbols, this rule
* 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
*/
error(p->g_lineno,"Alternative never chosen");
error(p->g_lineno, "Alternative never chosen", NULL);
}
resolve(l->l_rule);
break; }
break;
}
}
p++;
}
}
STATIC
propagate(set,p) p_set set; register p_gram p; {
STATIC void propagate(p_set set, register p_gram p)
{
/*
* Propagate the fact that on the elements of set the grammar rule
* p will not be chosen.
*/
while (g_gettype(p) != EORULE) {
setminus(g_getlink(p)->l_symbs,set);
while (g_gettype(p) != EORULE)
{
setminus(g_getlink(p)->l_symbs, set);
p++;
}
}
STATIC
spaces() {
if (level > 0) fprintf(fout,"%*c",level,' ');
STATIC void spaces(void)
{
if (level > 0)
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
* level of the LLgen tree.
*/
#ifndef EXTERN_H_
#define EXTERN_H_
/*
* 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 min_cases_for_jmptable;
extern int jmptable_option;
extern int ansi_c;
#ifdef NON_CORRECTING
extern int non_corr;
extern int subpars_sim;
@ -92,3 +93,23 @@ extern p_gram illegal_gram;
#endif
extern int strip_grammar;
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
*/
#include <stdio.h>
# include "types.h"
# include "extern.h"
# include "io.h"
@ -44,8 +45,8 @@ FILE *fout;
FILE *fpars;
FILE *finput;
FILE *fact;
char f_pars[] = PARSERFILE;
char f_temp[] = ACTFILE;
char f_pars[L_tmpnam+sizeof(char)]; /* Add one more character for NULL, just in case of buggy implementations. */
char f_temp[L_tmpnam+sizeof(char)];
#ifdef NON_CORRECTING
char f_nc[20];
#endif
@ -77,7 +78,6 @@ string nc_rec_file, nc_incl_file;
int low_percentage = 10, high_percentage = 30;
int min_cases_for_jmptable = 8;
int jmptable_option;
int ansi_c = 0;
#ifdef NON_CORRECTING
int non_corr = 0;
int subpars_sim = 0;

View file

@ -21,8 +21,6 @@
/* FILES */
# 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 RFILE "%spars.c" /* Error recovery */
#ifdef NON_CORRECTING

View file

@ -15,48 +15,51 @@
* machdep.c
* Machine dependant things
*/
#include <stdio.h>
#ifdef USE_SYS
#include <system.h>
#endif
#include <stdlib.h>
#include <string.h>
# include "alloc.h"
# include "extern.h"
# include "types.h"
# ifndef NORCSID
static string rcsid5 = "$Id$";
# endif
/* In this file the following routines are defined: */
extern UNLINK();
extern RENAME();
extern string libpath();
#ifndef LIBDIR
#define LIBDIR "lib"
#endif
UNLINK(x) string x; {
void UNLINK(string x)
{
/* Must remove the file "x" */
#ifdef USE_SYS
sys_remove(x); /* systemcall to remove file */
#else
unlink(x);
remove(x);
#endif
}
RENAME(x,y) string x,y; {
void RENAME(string x,string y)
{
/* Must move the file "x" to the file "y" */
#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
if (rename(x, y) == -1)
fatal(1, "Cannot rename to %s", y);
#endif
}
string
libpath(s) string s; {
string libpath(string s)
{
/* Must deliver a full pathname to the library file "s" */
register string p;
register length;
p_mem alloc();
register int length;
char* libdir = getenv("LLGEN_LIB_DIR");
if (!libdir)
@ -68,3 +71,11 @@ libpath(s) string s; {
strcat(p,s);
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
/* In this file the following routines are defined: */
extern int main();
STATIC readgrammar();
STATIC doparse();
extern error();
extern fatal();
extern comfatal();
extern copyfile();
extern void install();
STATIC void readgrammar(int, char *[]);
STATIC void doparse(register p_file);
STATIC void comfatal(void);
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;
string libpath();
TMPNAM(f_temp);
TMPNAM(f_pars);
/* Initialize */
assval = 0400;
/* read options */
while (argc >= 2 && (arg = argv[1], *arg == '-')) {
while (*++arg) {
switch(*arg) {
case 'j':
case 'J':
while (argc >= 2 && (arg = argv[1], *arg == '-'))
{
while (*++arg)
{
switch (*arg)
{
case 'j':
case 'J':
jmptable_option = 1;
if (*++arg)
min_cases_for_jmptable = atoi(arg);
break;
case 'w':
case 'W':
case 'w':
case 'W':
wflag = 1;
continue;
case 'v':
case 'V':
case 'v':
case 'V':
verbose++;
continue;
case 'l':
case 'L':
case 'l':
case 'L':
low_percentage = atoi(++arg);
break;
case 'h':
case 'H':
case 'h':
case 'H':
high_percentage = atoi(++arg);
break;
# ifndef NDEBUG
case 'd':
case 'D':
case 'd':
case 'D':
debug++;
continue;
case 'r':
case 'R':
if (rec_file) {
fprintf(stderr,"duplicate -r flag\n");
case 'r':
case 'R':
if (rec_file)
{
fprintf(stderr, "duplicate -r flag\n");
exit(1);
}
rec_file = ++arg;
break;
case 'i':
case 'I':
if (incl_file) {
fprintf(stderr,"duplicate -i flag\n");
case 'i':
case 'I':
if (incl_file)
{
fprintf(stderr, "duplicate -i flag\n");
exit(1);
}
incl_file = ++arg;
break;
#endif /* not NDEBUG */
case 'x':
case 'X':
case 'x':
case 'X':
ntneeded = 1;
ntprint = 1;
continue;
case 'a':
case 'A':
ansi_c = 1;
continue;
#ifdef NON_CORRECTING
case 'n':
case 'N':
case 'n':
case 'N':
non_corr = 1;
continue;
case 's':
case 'S':
case 's':
case 'S':
subpars_sim = 1;
continue;
#endif
case 'g':
case 'G':
case 'g':
case 'G':
strip_grammar = 1;
continue;
default:
fprintf(stderr,"illegal option : %c\n",*arg);
default:
fprintf(stderr, "illegal option : %c\n", *arg);
exit(1);
}
break;
@ -128,55 +135,59 @@ main(argc,argv) register string argv[]; {
}
#ifdef NON_CORRECTING
if ((subpars_sim) && (!non_corr)) {
fprintf(stderr,"option -s illegal without -n, turned off\n");
subpars_sim = 0;
if ((subpars_sim) && (!non_corr))
{
fprintf(stderr,"option -s illegal without -n, turned off\n");
subpars_sim = 0;
}
#endif
/*
* Now check wether the sets should include nonterminals
*/
if (verbose == 2) ntneeded = 1;
if (verbose == 2)
ntneeded = 1;
/*
* Initialise
*/
# ifndef NDEBUG
if (!rec_file) {
if (!rec_file)
{
# endif
rec_file = libpath("rec");
# ifndef NDEBUG
}
if (!incl_file) {
if (!incl_file)
{
# endif
incl_file = libpath("incl");
# ifndef NDEBUG
}
# endif
#ifdef NON_CORRECTING
if (non_corr) {
nc_incl_file = libpath("nc_incl");
nc_rec_file = libpath ("nc_rec");
if (non_corr)
{
nc_incl_file = libpath("nc_incl");
nc_rec_file = libpath ("nc_rec");
}
#endif
close(mkstemp(f_temp));
close(mkstemp(f_pars));
if ((fact = fopen(f_temp,"w")) == NULL) {
fputs("Cannot create temporary\n",stderr);
if ((fact = fopen(f_temp, "w")) == NULL)
{
fputs("Cannot create temporary\n", stderr);
exit(1);
}
name_init();
readgrammar(argc,argv);
readgrammar(argc, argv);
sprintf(f_out, OUTFILE, prefix ? prefix : "LL");
/* for the following two filenames only one L is used; historical
reasons ...
*/
reasons ...
*/
sprintf(f_include, HFILE, prefix ? prefix : "L");
sprintf(f_rec, RFILE, prefix ? prefix : "L");
#ifdef NON_CORRECTING
if (non_corr)
sprintf(f_nc, NCFILE, prefix ? prefix : "L");
sprintf(f_nc, NCFILE, prefix ? prefix : "L");
#endif
setinit(ntneeded);
maxnt = &nonterms[nnonterms];
@ -184,50 +195,60 @@ main(argc,argv) register string argv[]; {
/*
* Now, the grammar is read. Do some computations
*/
co_reach(); /* Check for undefined and unreachable */
if (nerrors) comfatal();
co_reach(); /* Check for undefined and unreachable */
if (nerrors)
comfatal();
do_compute();
conflchecks();
if (nerrors) comfatal();
if (nerrors)
comfatal();
fclose(fact);
if (argc-- == 1) {
if (argc-- == 1)
{
fputs("No code generation for input from standard input\n",
stderr);
stderr);
}
else gencode(argc);
else
gencode(argc);
UNLINK(f_temp);
UNLINK(f_pars);
if (verbose) {
if (verbose)
{
fprintf(stderr, "number of nonterminals: %d\n", nnonterms);
fprintf(stderr, "number of tokens: %d\n", ntokens);
fprintf(stderr, "number of term structures: %d\n", nterms);
fprintf(stderr, "number of alternation structures: %d\n", nalts);
}
exit(0);
exit(EXIT_SUCCESS);
}
STATIC
readgrammar(argc,argv) char *argv[]; {
STATIC void readgrammar(int argc, char *argv[])
{
/*
* Do just what the name suggests : read the grammar
*/
register p_file p;
p_mem alloc();
register p_file p;
p_mem alloc();
linecount = 0;
f_input = "no filename";
/*
* Build the file structure
*/
files = p = (p_file) alloc((unsigned) (argc+1) * sizeof(t_file));
if (argc-- == 1) {
files = p = (p_file) alloc((unsigned) (argc + 1) * sizeof(t_file));
if (argc-- == 1)
{
finput = stdin;
f_input = "standard input";
doparse(p++);
} else {
while (argc--) {
if ((finput = fopen(f_input=argv[1],"r")) == NULL) {
fatal(0,e_noopen,f_input);
}
else
{
while (argc--)
{
if ((finput = fopen(f_input = argv[1], "r")) == NULL)
{
fatal(0, e_noopen, f_input);
}
doparse(p++);
argv++;
@ -235,19 +256,21 @@ readgrammar(argc,argv) char *argv[]; {
}
}
maxfiles = p;
if (! lexical) lexical = "yylex";
if (!lexical)
lexical = "yylex";
/*
* There must be a start symbol!
*/
if (! nerrors && start == 0) {
fatal(linecount,"Missing %%start");
if (!nerrors && start == 0)
{
fatal(linecount, "Missing %%start", NULL);
}
if (nerrors) comfatal();
if (nerrors)
comfatal();
}
STATIC
doparse(p) register p_file p; {
STATIC void doparse(register p_file p)
{
linecount = 0;
p->f_name = f_input;
p->f_firsts = 0;
@ -259,90 +282,100 @@ doparse(p) register p_file p; {
p->f_terminals = torder;
}
/* VARARGS1 */
error(lineno,s,t,u) string s,t,u; {
void error(int lineno, string s, string t)
{
/*
* Just an error message
*/
++nerrors;
if (!lineno) lineno = 1;
fprintf(stderr,"\"%s\", line %d: ",f_input, lineno);
fprintf(stderr,s,t,u);
fputs("\n",stderr);
if (!lineno)
lineno = 1;
fprintf(stderr, "\"%s\", line %d: ", f_input, lineno);
fprintf(stderr, s, t);
fputs("\n", stderr);
}
/* VARARGS1 */
void
warning(lineno,s,t,u) string s,t,u; {
void warning(int lineno, string s, string t)
{
/*
* Just a warning
*/
if (wflag) return;
if (!lineno) lineno = 1;
fprintf(stderr,"\"%s\", line %d: (Warning) ",f_input, lineno);
fprintf(stderr,s,t,u);
fputs("\n",stderr);
if (wflag)
return;
if (!lineno)
lineno = 1;
fprintf(stderr, "\"%s\", line %d: (Warning) ", f_input, lineno);
fprintf(stderr, s, t);
fputs("\n", stderr);
}
/* VARARGS1 */
fatal(lineno,s,t,u) string s,t,u; {
void fatal(int lineno, string s, string t)
{
/*
* Fatal error
*/
error(lineno,s,t,u);
error(lineno, s, t);
comfatal();
}
comfatal() {
STATIC void comfatal(void)
{
/*
* Some common code for exit on errors
*/
if (fact != NULL) {
if (fact != NULL)
{
fclose(fact);
UNLINK(f_temp);
}
if (fpars != NULL) fclose(fpars);
if (fpars != NULL)
fclose(fpars);
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.
*/
register int c;
register FILE *f;
register int c;
register FILE *f;
if ((f = fopen(file,"r")) == NULL) {
fatal(0,"Cannot open library file %s, call an expert",file);
if ((f = fopen(file, "r")) == NULL)
{
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);
}
void
install(target, source) string target, source; {
void install(string target, string source)
{
/*
* Copy the temporary file generated from source to target
* if allowed (which means that the target must be generated
* by LLgen from the source, or that the target is not present
*/
register int c1, c2;
register FILE *f1, *f2;
int cnt;
register int c1, c2;
register FILE *f1, *f2;
int cnt;
/*
* First open temporary, generated for source
*/
if ((f1 = fopen(f_pars,"r")) == NULL) {
fatal(0,e_noopen,f_pars);
if ((f1 = fopen(f_pars, "r")) == NULL)
{
fatal(0, e_noopen, f_pars);
}
/*
* Now open target for reading
*/
if ((f2 = fopen(target,"r")) == NULL) {
if ((f2 = fopen(target, "r")) == NULL)
{
fclose(f1);
RENAME(f_pars, target);
return;
@ -355,20 +388,24 @@ install(target, source) string target, source; {
/*
* Now compare the target with the temporary
*/
do {
do
{
c1 = getc(f1);
c2 = getc(f2);
if (cnt >= 0) cnt--;
if (cnt >= 0)
cnt--;
} while (c1 == c2 && c1 != EOF);
fclose(f1);
fclose(f2);
/*
* Here, if c1 != c2 the target must be recreated
*/
if (c1 != c2) {
if (cnt >= 0) {
fatal(0,"%s : not a file generated by LLgen",target);
if (c1 != c2)
{
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 <stdio.h>
# include "alloc.h"
# include "types.h"
# include "extern.h"
# include "assert.h"
@ -30,38 +32,36 @@ static string rcsid7 = "$Id$";
# define HASHSIZE 128
# define NMSIZ 2048 /* Room for names allocated NMSIZ bytes at a time */
static char *name, *maxname;
static p_entry h_root[HASHSIZE]; /* hash table */
static string e_literal = "Illegal literal";
static p_entry entries, maxentries;
static t_info token_info, nont_info;
static char *name, *maxname;
static p_entry h_root[HASHSIZE]; /* hash table */
static string e_literal = "Illegal literal";
static p_entry entries, maxentries;
static t_info token_info, nont_info;
/* Defined in this file are: */
extern string store();
extern name_init();
STATIC int hash();
STATIC p_entry newentry();
extern p_gram search();
STATIC int hash(string str);
STATIC p_entry newentry(string str, p_entry next);
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;
nont_info.i_esize = sizeof (t_nont);
nont_info.i_esize = sizeof(t_nont);
nont_info.i_incr = 50;
search(TERMINAL,"EOFILE",ENTERING);
search(TERMINAL, "EOFILE", ENTERING);
#ifdef NON_CORRECTING
illegal_gram = search(TERMINAL,"LLILLEGAL",ENTERING);
#endif
}
STATIC p_entry
newentry(str, next) string str; p_entry next; {
STATIC p_entry newentry(string str, p_entry next)
{
register p_entry p;
if ((p = entries) == maxentries) {
if ((p = entries) == maxentries)
{
p = (p_entry) alloc(50 * sizeof(t_entry));
maxentries = p + 50;
}
@ -75,18 +75,20 @@ newentry(str, next) string str; p_entry next; {
return p;
}
string
store(s) string s; {
/*
* Store a string s in the name table
*/
register string s1, t ,u;
/*
* Store a string s in the name table
*/
string store(string s)
{
register string s1, t, u;
u = name;
t = s;
s1 = u;
do {
if (u >= maxname) {
do
{
if (u >= maxname)
{
u = alloc(NMSIZ);
maxname = u + NMSIZ;
t = s;
@ -98,60 +100,63 @@ store(s) string s; {
return s1;
}
STATIC int
hash(str) string str; {
/*
* Compute the hash for string str
*/
register int i;
/*
* Compute the hash for string str
*/
STATIC int hash(string str)
{
register int i;
register string l;
l = str;
i = 0;
while (*l != '\0') i += *l++ & 0377;
while (*l != '\0')
i += *l++ & 0377;
i += l - str;
return i % HASHSIZE;
}
p_gram
search(type,str,option) register string str; {
/*
* Search for object str.
* It has type UNKNOWN, LITERAL, TERMINAL or NONTERM.
* option can be ENTERING or BOTH (also looking).
*/
register int val = 0;
register p_entry p;
register int i;
int type1;
/*
* Search for object str.
* 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 p_entry p;
register int i;
int type1;
i = hash(str);
/*
* Walk hash chain
*/
for (p = h_root[i]; p != (p_entry) 0; p = p->h_next) {
if(!strcmp(p->h_name,str)) {
for (p = h_root[i]; p != (p_entry) 0; p = p->h_next)
{
if (!strcmp(p->h_name, str))
{
type1 = g_gettype(&(p->h_type));
if (type1 != type) {
if (type1 == LITERAL || type == LITERAL) {
if (type1 != type)
{
if (type1 == LITERAL || type == LITERAL)
{
continue;
}
if (type == TERMINAL) {
error(linecount,
"%s: is already a nonterminal",
str);
if (type == TERMINAL)
{
error(linecount, "%s: is already a nonterminal", str);
continue;
}
else if (type == NONTERM) {
error(linecount,
"%s : is already a token",
str);
else if (type == NONTERM)
{
error(linecount, "%s : is already a token", str);
continue;
}
}
if (option==ENTERING) {
error(linecount,
"%s : is already defined",str);
if (option == ENTERING)
{
error(linecount, "%s : is already defined", str);
}
p->h_type.g_lineno = linecount;
return &(p->h_type);
@ -159,64 +164,76 @@ search(type,str,option) register string str; {
}
p = newentry(store(str), h_root[i]);
h_root[i] = p;
if (type == TERMINAL || type == LITERAL) {
if (type == TERMINAL || type == LITERAL)
{
register p_token pt;
pt = (p_token) new_mem(&token_info);
tokens = (p_token) token_info.i_ptr;
pt->t_string = p->h_name;
if (type == LITERAL) {
if (str[0] == '\\') {
if (type == LITERAL)
{
if (str[0] == '\\')
{
/*
* Handle escapes in literals
*/
if (str[2] == '\0') {
switch(str[1]) {
case 'n' :
if (str[2] == '\0')
{
switch (str[1])
{
case 'n':
val = '\n';
break;
case 'r' :
case 'r':
val = '\r';
break;
case 'b' :
case 'b':
val = '\b';
break;
case 'f' :
case 'f':
val = '\f';
break;
case 't' :
case 't':
val = '\t';
break;
case '\'':
case '\'':
val = '\'';
break;
case '\\':
case '\\':
val = '\\';
break;
default :
error(linecount,e_literal);
default:
error(linecount, e_literal, NULL);
}
} else {
}
else
{
/*
* Here, str[2] != '\0'
*/
if (str[1] > '3' || str[1] < '0' ||
str[2] > '7' || str[2] < '0' ||
str[3] > '7' || str[3] < '0' ||
str[4] != '\0') error(linecount,e_literal);
val = 64*str[1] - 73*'0' +
8*str[2] + str[3];
if (str[1] > '3' || str[1] < '0' || str[2] > '7'
|| str[2] < '0' || str[3] > '7' || str[3] < '0'
|| str[4] != '\0')
error(linecount, e_literal, NULL);
val = 64 * str[1] - 73 * '0' + 8 * str[2] + str[3];
}
} else {
}
else
{
/*
* No escape in literal
*/
if (str[1] == '\0') val = str[0];
else error(linecount,e_literal);
if (str[1] == '\0')
val = str[0];
else
error(linecount, e_literal, NULL);
}
pt->t_tokno = val;
g_settype(&(p->h_type), LITERAL);
} else {
}
else
{
/*
* Here, type = TERMINAL
*/

View file

@ -17,6 +17,7 @@
* are all defined.
*/
#include <stdio.h>
# include "types.h"
# include "extern.h"
# include "io.h"
@ -26,12 +27,18 @@
static string rcsid8 = "$Id$";
# 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.
*/
@ -80,8 +87,8 @@ co_reach() {
}
}
STATIC
reachable(p) register p_nont p; {
STATIC void reachable(register p_nont p)
{
/*
* Enter the fact that p is reachable, and look for implications
*/
@ -94,8 +101,8 @@ reachable(p) register p_nont p; {
}
}
STATIC void
reachwalk(p) register p_gram p; {
STATIC void reachwalk(p_gram p)
{
/*
* Walk through rule p, looking for nonterminals.
* The nonterminals found are entered as reachable

View file

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

View file

@ -16,25 +16,17 @@
* Set manipulation and allocation routines.
*/
#include <stdio.h>
# include <assert.h>
# include "types.h"
# include "extern.h"
# include "sets.h"
# include "assert.h"
# ifndef NORCSID
static string rcsid9 = "$Id$";
# 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;
static int setsize;
@ -43,10 +35,11 @@ p_set *setptr, *maxptr;
static t_info set_info;
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;
nbytes = NBYTES(ntokens);
@ -61,8 +54,8 @@ setinit(nt_needed) {
set_info.i_incr = 20;
}
p_set
get_set() {
p_set get_set(void)
{
/*
* Allocate a set that cannot be freed
*/
@ -80,8 +73,8 @@ get_set() {
return p;
}
p_set
setalloc() {
p_set setalloc(void)
{
/*
* Allocate a set which can later be freed.
*/
@ -95,8 +88,8 @@ setalloc() {
return p;
}
int
setunion(a,b) register p_set a,b; {
int setunion(register p_set a,register p_set b)
{
/*
* a = a union b.
* Return 1 if the set a changed
@ -115,8 +108,8 @@ setunion(a,b) register p_set a,b; {
return nsub;
}
int
setintersect(a,b) register p_set a,b; {
int setintersect(register p_set a,register p_set b)
{
/*
* a = a intersect b.
* return 1 if the result is empty
@ -132,7 +125,8 @@ setintersect(a,b) register p_set a,b; {
return nempty;
}
setminus(a,b) register p_set a,b; {
void setminus(register p_set a,register p_set b)
{
/*
* a = a setminus b
*/
@ -144,8 +138,8 @@ setminus(a,b) register p_set a,b; {
} while (--i);
}
int
setempty(p) register p_set p; {
int setempty(register p_set p)
{
/*
* Return 1 if the set p is empty
*/
@ -158,8 +152,8 @@ setempty(p) register p_set p; {
return 1;
}
int
findindex(set) p_set set; {
int findindex(p_set set)
{
/*
* The set "set" will serve as a recovery set.
* Search for it in the table. If not present, enter it.
@ -204,8 +198,8 @@ findindex(set) p_set set; {
return nbytes * (maxptr++ - setptr);
}
int
setcount(set, saved) register p_set set; int *saved; {
int setcount(register p_set set, int *saved)
{
register int i, j;
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
* level of the LLgen tree.
*/
#ifndef SETS_H_
#define SETS_H_
/*
* L L G E N
@ -31,3 +33,44 @@
extern int tsetsize;
extern p_set *setptr, *maxptr;
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"
#define LL_LEXI scanner
#define LLNOFIRSTS
#if __STDC__ || __cplusplus
#define LL_ANSI_C 1
#endif
#define LL_LEXI scanner
/* $Id$ */
#ifdef LL_DEBUG
@ -38,7 +35,6 @@ extern int LLstartsymb;
#define LLsincr(d) LLscnt[d]++
#define LLtincr(d) LLtcnt[d]++
#if LL_ANSI_C
extern int LL_LEXI(void);
extern void LLread(void);
extern int LLskip(void);
@ -56,29 +52,11 @@ extern int LLfirst(int, int);
#if LL_NON_CORR
extern void LLnc_recover(void);
#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"
#include <string.h>
# include "types.h"
#include "types.h"
# include "io.h"
# include "extern.h"
# include "assert.h"
@ -89,17 +67,17 @@ static string rcsidc = "$Id$";
# endif
/* Here are defined : */
extern int scanner();
extern LLmessage();
extern int input();
extern unput();
extern void skipcomment();
int scanner(void);
void LLmessage(int d);
int input(void);
void unput(int c);
void skipcomment(int flag);
# ifdef LINE_DIRECTIVE
STATIC linedirective();
STATIC void linedirective(void);
# endif
STATIC string cpy();
STATIC string vallookup();
STATIC void copyact();
STATIC string cpy(int s,register string p,int inserted);
STATIC string vallookup(int s);
STATIC void copyact(char ch1,char ch2,int flag,int level);
static int nparams;
# 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 */
# endif
STATIC void
copyact(ch1,ch2,flag,level) char ch1,ch2; {
STATIC void copyact(char ch1,char ch2,int flag,int level)
{
/*
* Copy an action to file f. Opening bracket is ch1, closing bracket
* is ch2.
@ -155,8 +133,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
*/
static int text_seen = 0;
register FILE *f;
register ch; /* Current char */
register match; /* used to read strings */
register int ch; /* Current char */
register int match; /* used to read strings */
int saved = linecount;
/* save linecount */
int sav_strip = strip_grammar;
@ -187,7 +165,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
case ')':
case '}':
case ']':
error(linecount,"Parentheses mismatch");
error(linecount,"Parentheses mismatch", NULL);
break;
case '(':
text_seen = 1;
@ -218,7 +196,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
text_seen = 0;
nparams++;
if (ch == ',' && (flag & 2)) {
warning(linecount, "Parameters may not be separated with a ','");
warning(linecount, "Parameters may not be separated with a ','",NULL);
ch = ';';
}
}
@ -239,7 +217,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
ch = input();
}
if (ch == '\n') {
error(linecount,"Newline in string");
error(linecount,"Newline in string", NULL);
unput(match);
}
putc(ch,f);
@ -247,7 +225,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
if (ch == match) break;
/* Fall through */
case EOF :
if (!level) error(saved,"Action does not terminate");
if (!level) error(saved,"Action does not terminate", NULL);
strip_grammar = sav_strip;
return;
default:
@ -257,7 +235,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
}
}
scanner() {
int scanner(void)
{
/*
* Lexical analyser, what else
*/
@ -307,7 +286,7 @@ scanner() {
for (;;) {
ch = input();
if (ch == '\n' || ch == EOF) {
error(linecount,"Missing '");
error(linecount,"Missing '", NULL);
break;
}
if (ch == '\'') break;
@ -327,7 +306,7 @@ scanner() {
case ISSPA :
continue;
case ISDIG : {
register i = 0;
register int i = 0;
do {
i = 10 * i + (ch - '0');
ch= input();
@ -371,7 +350,7 @@ scanner() {
}
w++;
}
error(linecount,"Illegal reserved word");
error(linecount,"Illegal reserved word",NULL);
}
lextoken.t_string = ltext;
return C_IDENT;
@ -382,11 +361,12 @@ scanner() {
static int backupc; /* for unput() */
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
*/
register c;
register int c;
if (c = backupc) {
/* Last char was "unput()". Deliver it again
@ -413,15 +393,16 @@ input() {
return c;
}
unput(c) {
void unput(int c)
{
/*
* "unread" c
*/
backupc = c;
}
void
skipcomment(flag) {
void skipcomment(int flag)
{
/*
* Skip comment. If flag != 0, the comment is inside a fragment
* of C-code, so keep it.
@ -430,7 +411,7 @@ skipcomment(flag) {
int saved; /* line count on which comment starts */
saved = linecount;
if (input() != '*') error(linecount,"Illegal comment");
if (input() != '*') error(linecount,"Illegal comment",NULL);
if (flag) putc('*', fact);
do {
ch = input();
@ -441,12 +422,12 @@ skipcomment(flag) {
if (ch == '/') return;
}
} while (ch != EOF);
error(saved,"Comment does not terminate");
error(saved,"Comment does not terminate", NULL);
}
# ifdef LINE_DIRECTIVE
STATIC
linedirective() {
STATIC void linedirective(void)
{
/*
* Read a line directive
*/
@ -463,7 +444,7 @@ linedirective() {
ch = input();
} while (ch != '\n' && c_class[ch] != ISDIG);
if (ch == '\n') {
error(linecount,s_error);
error(linecount,s_error, NULL);
return;
}
i = 0;
@ -478,7 +459,7 @@ linedirective() {
*c++ = ch = input();
} while (ch != '"' && ch != '\n');
if (ch == '\n') {
error(linecount,s_error);
error(linecount,s_error, NULL);
return;
}
*--c = '\0';
@ -494,8 +475,8 @@ linedirective() {
}
# endif
STATIC string
vallookup(s) {
STATIC string vallookup(int s)
{
/*
* Look up the keyword that has token number s
*/
@ -508,8 +489,8 @@ vallookup(s) {
return 0;
}
STATIC string
cpy(s,p,inserted) register string p; {
STATIC string cpy(int s,register string p,int inserted)
{
/*
* 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
@ -579,7 +560,9 @@ cpy(s,p,inserted) register string p; {
return p;
}
LLmessage(d) {
void LLmessage(int d)
{
/*
* 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

View file

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

View file

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