bits.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/* bits.c -- manage creation and output of bit sets used by the parser.
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#include "dlgdef.h"
/* char is only thing that is pretty much always known == 8 bits
* This allows output of antlr (set stuff, anyway) to be androgynous (portable)
*/
typedef unsigned char SetWordType;
#define BitsPerByte 8
int setnum = -1;
int wordnum = 0;
int esetnum = 0;
/* Used to convert native wordsize, which ANTLR uses (via set.c) to manipulate sets,
to bytes that are most portable size-wise.
*/
void
#ifdef __USE_PROTOS
#else
FILE *f;
char *format;
unsigned wd;
#endif
{
int i;
/* uses max of 32 bit unsigned integer for the moment */
static unsigned long byte_mask[sizeof(unsigned long)] =
{ 0xFF, 0xFF00UL, 0xFF0000UL, 0xFF000000UL }; /* MR20 G. Hobbelt */
/* 0xFF00000000, 0xFF0000000000, 0xFF000000000000, 0xFF00000000000000 };*/
/* for each byte in the word */
for (i=0; i<sizeof(unsigned); i++)
{
/* mask out the ith byte and shift down to the first 8 bits */
}
}
/* Create a new setwd (ignoring [Ep] token on end) */
void
#ifdef __USE_PROTOS
NewSetWd( void )
#else
NewSetWd( )
#endif
{
SetWordType *p;
{
}
wordnum++;
}
void
#ifdef __USE_PROTOS
DumpSetWd( void )
#else
DumpSetWd( )
#endif
{
if ( GenCC ) DumpSetWdForCC();
else DumpSetWdForC();
}
/* Dump the current setwd to ErrFile. 0..MaxTokenVal */
void
#ifdef __USE_PROTOS
DumpSetWdForC( void )
#else
#endif
{
int i,c=1;
for (i=0; i<TokenNum-1; i++)
{
}
}
/* Dump the current setwd to Parser.C file. 0..MaxTokenVal;
* Only used if -CC on.
*/
void
#ifdef __USE_PROTOS
DumpSetWdForCC( void )
#else
#endif
{
int i,c=1;
TokenNum-1);
for (i=0; i<TokenNum-1; i++)
{
}
}
/* Make a new set. Dump old setwd and create new setwd if current setwd is full */
void
#ifdef __USE_PROTOS
NewSet( void )
#else
NewSet( )
#endif
{
setnum++;
{
}
}
/* s is a set of tokens. Turn on bit at each token position in set 'setnum' */
void
#ifdef __USE_PROTOS
#else
FillSet( s )
set s;
#endif
{
unsigned int e;
while ( !set_nil(s) )
{
e = set_int(s);
set_rm(e, s);
}
}
/* E r r o r C l a s s S t u f f */
/* compute the FIRST of a rule for the error class stuff */
static set
#ifdef __USE_PROTOS
#else
char *rule;
#endif
{
Junction *r;
if ( q == NULL )
{
return empty;
}
return a;
}
/*
* scan the list of tokens/eclasses/nonterminals filling the new eclass
* with the set described by the list. Note that an eclass can be
* quoted to allow spaces etc... However, an eclass must not conflict
* with a reg expr found elsewhere. The reg expr will be taken over
* the eclass name.
*/
static void
#ifdef __USE_PROTOS
#else
char *eclass;
#endif
{
TermEntry *q;
ECnode *p;
ListNode *e;
unsigned int t;
unsigned deg=0;
set a;
{
q = NULL; /* MR23 */
{
set_free( a );
continue;
}
else if ( *((char *)e->elem)=='"' )
{
t = 0;
if ( q == NULL )
{
/* if quoted and not an expr look for eclass name */
}
else t = q->token;
}
{
if ( q != NULL )
{
{
(char *)e->elem));
continue;
}
else
t = q->token;
}
else t=0;
}
if ( t!=0 )
{
if (isTermEntryTokClass(q)) { /* MR23 */
} /* MR23 */
else {
deg++;
}
}
}
}
void
#ifdef __USE_PROTOS
ComputeErrorSets( void )
#else
#endif
{
#ifdef __cplusplus
#else
#ifdef __USE_PROTOS
#else
#endif
#endif
}
void
#ifdef __USE_PROTOS
ComputeTokSets( void )
#else
#endif
{
int something_changed;
int i;
TCnode *p;
{
/* if wild card, then won't have entries in tclass, assume all_tokens */
if ( p->tok == WildCardToken )
{
continue;
}
/* instantiate all tokens/token_classes into the tset */
{
char *tokstr;
if ( *tokstr == '"' ) {
} else if (tokstr[0] == '.') {
e=e2;
}
}
} else {
}
} else {
}
}
}
/* Go thru list of tokclasses again looking for tokclasses in sets */
something_changed = 0;
{
{
int tk;
/* replace refs to tokclasses with the associated set of tokens */
something_changed = 1;
{
{
}
}
}
}
if ( something_changed ) goto again;
}
void
#ifdef __USE_PROTOS
DumpRemainingTokSets(void)
#else
#endif
{
TCnode *p;
ListNode *t;
/* Go thru tclasses (for the last time) and dump the sets not dumped
* during code gen; yes, this is a bogus way to do this, but ComputeTokSets()
* can't dump the defs as the error file and tok file has not been created
* yet etc...
*/
{
unsigned e;
if ( p->dumped ) continue;
p->dumped = 1;
p->setnum = e;
}
}
/* replace a subset of an error set with an error class name if a subset is found
* repeat process until no replacements made
*/
void
#ifdef __USE_PROTOS
SubstErrorClass( set *f )
#else
SubstErrorClass( f )
set *f;
#endif
{
ListNode *p;
set a;
while ( !done )
{
max = 0;
{
{
}
}
{
set_free(*f);
*f = a;
}
else done = 1;
}
}
int
#ifdef __USE_PROTOS
#else
int nilOK;
set *f;
int subst; /* should be substitute error classes? */
char *name;
#endif
{
}
int
#ifdef __USE_PROTOS
#else
set *f;
int subst; /* should be substitute error classes? */
char *name;
#endif
{
}
int
#ifdef __USE_PROTOS
#else
int nilOK;
set *f;
int subst; /* should be substitute error classes? */
char *name;
char *suffix;
#endif
{
}
/* Define a new error set. WARNING...set-implementation dependent.
*/
int
#ifdef __USE_PROTOS
#else
int nilOK; /* MR13 */
set *f;
int subst; /* should be substitute error classes? */
char *name;
const char *suffix;
#endif
{
unsigned *p, *endp;
int e=1;
if ( subst ) SubstErrorClass(f);
p = f->setword;
esetnum++;
else
name,
}
else {
}
while ( p < endp )
{
if ( e == 3 )
{
e=1;
}
else e++;
}
return esetnum;
}
int
#ifdef __USE_PROTOS
#else
set *f;
int subst; /* should be substitute error classes? */
char *name;
#endif
{
}
/* Define a new error set. WARNING...set-implementation dependent;
* Only used when -CC on.
*/
int
#ifdef __USE_PROTOS
#else
int nilOK; /* MR13 */
set *f;
int subst; /* should be substitute error classes? */
char *name;
const char *suffix;
#endif
{
unsigned *p, *endp;
int e=1;
if ( subst ) SubstErrorClass(f);
p = f->setword;
esetnum++;
name,
}
else {
}
while ( p < endp )
{
if ( e == 3 )
{
e=1;
}
else e++;
}
return esetnum;
}
int
#ifdef __USE_PROTOS
#else
set *f;
int subst; /* should be substitute error classes? */
char *name;
#endif
{
}
void
#ifdef __USE_PROTOS
GenParser_c_Hdr(void)
#else
#endif
{
int i,j;
if ( UserTokenDefsFile != NULL )
else
CurrentClassName); /* MR1 */
/* Dump a Parser::tokens for each automaton */
CurrentClassName); /* MR20 */
{
if ( i == EpToken ) continue;
/* remapped to invalid token? */
{
continue;
}
if ( TokenString(i) != NULL ) {
} else {
}
}
else
{
/* look in all lexclasses for the reg expr */
for (j=0; j<NumLexClasses; j++)
{
lexmode(j);
if ( ExprString(i) != NULL )
{
break;
}
}
if ( j>=NumLexClasses )
{
if ( UserDefdTokens )
{
}
else
}
}
}
/* Build constructors */
if (TraceGen) {
} else {
};
free ( (void *) hasAkaName);
}
void
#ifdef __USE_PROTOS
GenParser_h_Hdr(void)
#else
#endif
{
int i;
if (TraceGen) {
};
/* MR10 */ } else {
/* MR10 */ };
}
/* Currently, this is only used in !GenCC mode */
void
#ifdef __USE_PROTOS
GenErrHdr( void )
#else
GenErrHdr( )
#endif
{
int i, j;
if ( FoundGuessBlk )
{
}
if (TraceGen) {
};
#ifdef DUM
if ( LexGen ) fprintf(ErrFile, "#define zzEOF_TOKEN %d\n", (TokenInd!=NULL?TokenInd[EofToken]:EofToken));
#endif
/* still need this one as it has the func prototypes */
/* Dump a zztokens for each automaton */
{
}
else
{
}
{
if ( i == EpToken ) continue;
/* remapped to invalid token? */
{
continue;
}
if ( TokenString(i) != NULL ) {
} else {
}
}
else
{
/* look in all lexclasses for the reg expr */
for (j=0; j<NumLexClasses; j++)
{
lexmode(j);
if ( ExprString(i) != NULL )
{
break;
}
}
if ( j>=NumLexClasses )
{
if ( UserDefdTokens )
{
}
else
}
}
}
}
void
#ifdef __USE_PROTOS
#else
dumpExpr( f, e )
FILE *f;
char *e;
#endif
{
while ( *e!='\0' )
{
if ( *e=='\\' && *(e+1)=='\\' )
else if ( *e=='\\' && *(e+1)=='"' )
else {putc(*e, f); e++;}
}
}
int
#ifdef __USE_PROTOS
#else
#endif
{
ListNode *t;
TCnode *p;
TermEntry *q;
char *tokstr;
{
if (q == te) return 1;
}
return 0;
}