Category : C Source Code
Archive   : TBISON0.ZIP
Filename : NULLABLE.C
copyright (C) 1984 Bob Corbett and Richard Stallman */
/* set up nullable, a vector saying which nonterminals can expand
into the null string.
nullable[i - ntokens] is nonzero if symbol i can do so. */
#include
#include "types.h"
#include "gram.h"
#include "new.h"
/* 4 calls to temp_allocate */
/* 1 call to allocate */
/* 4 calls to free */
/* 1 call to temp_free */
char *nullable;
set_nullable()
{
register short *r;
register short *s1;
register short *s2;
register int ruleno;
register int symbol;
register shorts *p;
short *squeue;
short *rcount;
shorts **rsets;
shorts *relts;
char any_tokens;
short *r1;
if (verboseflag) fprintf(stderr,"nullable\n");
#ifdef ALLOC_TRACE
alloc_flag = 1;
#else
alloc_flag = 0;
#endif
#ifdef TRACE
fprintf(stderr, "Entering set_nullable");
#endif
/* 1st application of allocate in NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"null 1 ");
#endif
nullable = NEW2(nvars, char) - ntokens;
/* 2nd application of allocate in NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"null 2 ");
#endif
squeue = TEMPNEW2(nvars, short);
s1 = s2 = squeue;
/* 3rd application of allocate in NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"null 3 ");
#endif
rcount = TEMPNEW2(nrules + 1, short);
/* 4th application of allocate in NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"null 4 ");
#endif
rsets = TEMPNEW2(nvars, shorts *) - ntokens;
/* 5th application of allocate in NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"null 5 ");
#endif
relts = TEMPNEW2(nitems + nvars + 1, shorts);
p = relts;
r = ritem;
while (*r)
{
if (*r < 0)
{
symbol = rlhs[-(*r++)];
if (!nullable[symbol])
{
nullable[symbol] = 1;
*s2++ = symbol;
}
}
else
{
r1 = r;
any_tokens = 0;
for (symbol = *r++; symbol > 0; symbol = *r++)
{
if (ISTOKEN(symbol))
any_tokens = 1;
}
if (!any_tokens)
{
ruleno = -symbol;
r = r1;
for (symbol = *r++; symbol > 0; symbol = *r++)
{
rcount[ruleno]++;
p->next = rsets[symbol];
p->value = ruleno;
rsets[symbol] = p;
p++;
}
}
}
}
while (s1 < s2)
{
p = rsets[*s1++];
while (p)
{
ruleno = p->value;
p = p->next;
if (--rcount[ruleno] == 0)
{
symbol = rlhs[ruleno];
if (!nullable[symbol])
{
nullable[symbol] = 1;
*s2++ = symbol;
}
}
}
}
#ifdef SMALL_MODEL
/* 1st application of free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE null 1 ");
#endif
FREE(squeue);
/* 2nd application of free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE null 2 ");
#endif
FREE(rcount);
/* 3rd application of free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE null 3 ");
#endif
FREE(rsets + ntokens);
/* 4th application of free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE null 4 ");
#endif
FREE(relts);
#else
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE 2 - 5 ");
#endif
TEMPFREE(squeue);
if (verboseflag) alloc_status();
#endif
}
free_nullable()
{
/* 5th application of free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE null 5 ");
#endif
FREE(nullable + ntokens);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/