home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
f2c-1993.04.28-src.lha
/
f2c-1993.04.28
/
src
/
lex.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-28
|
30KB
|
1,495 lines
/****************************************************************
Copyright 1990, 1992 by AT&T Bell Laboratories and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T Bell Laboratories or
Bellcore or any of their entities not be used in advertising or
publicity pertaining to distribution of the software without
specific, written prior permission.
AT&T and Bellcore disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall AT&T or Bellcore be liable for
any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
****************************************************************/
#include "defs.h"
#include "tokdefs.h"
#include "p1defs.h"
#ifdef NO_EOF_CHAR_CHECK
#undef EOF_CHAR
#else
#ifndef EOF_CHAR
#define EOF_CHAR 26 /* ASCII control-Z */
#endif
#endif
#define BLANK ' '
#define MYQUOTE (2)
#define SEOF 0
/* card types */
#define STEOF 1
#define STINITIAL 2
#define STCONTINUE 3
/* lex states */
#define NEWSTMT 1
#define FIRSTTOKEN 2
#define OTHERTOKEN 3
#define RETEOS 4
LOCAL int stkey; /* Type of the current statement (DO, END, IF, etc) */
extern char token[]; /* holds the actual token text */
static int needwkey;
ftnint yystno;
flag intonly;
extern int new_dcl;
LOCAL long int stno;
LOCAL long int nxtstno; /* Statement label */
LOCAL int parlev; /* Parentheses level */
LOCAL int parseen;
LOCAL int expcom;
LOCAL int expeql;
LOCAL char *nextch;
LOCAL char *lastch;
LOCAL char *nextcd = NULL;
LOCAL char *endcd;
LOCAL long prevlin;
LOCAL long thislin;
LOCAL int code; /* Card type; INITIAL, CONTINUE or EOF */
LOCAL int lexstate = NEWSTMT;
LOCAL char *sbuf; /* Main buffer for Fortran source input. */
LOCAL char *send; /* Was = sbuf+20*66 with sbuf[1390]. */
LOCAL int maxcont;
LOCAL int nincl = 0; /* Current number of include files */
LOCAL long firstline;
LOCAL char *laststb, *stb0;
extern int addftnsrc;
static char **linestart;
LOCAL int ncont;
LOCAL char comstart[Table_size];
#define USC (unsigned char *)
static char anum_buf[Table_size];
#define isalnum_(x) anum_buf[x]
#define isalpha_(x) (anum_buf[x] == 1)
#define COMMENT_BUF_STORE 4088
typedef struct comment_buf {
struct comment_buf *next;
char *last;
char buf[COMMENT_BUF_STORE];
} comment_buf;
static comment_buf *cbfirst, *cbcur;
static char *cbinit, *cbnext, *cblast;
static void flush_comments();
extern flag use_bs;
/* Comment buffering data
Comments are kept in a list until the statement before them has
been parsed. This list is implemented with the above comment_buf
structure and the pointers cbnext and cblast.
The comments are stored with terminating NULL, and no other
intervening space. The last few bytes of each block are likely to
remain unused.
*/
/* struct Inclfile holds the state information for each include file */
struct Inclfile
{
struct Inclfile *inclnext;
FILEP inclfp;
char *inclname;
int incllno;
char *incllinp;
int incllen;
int inclcode;
ftnint inclstno;
};
LOCAL struct Inclfile *inclp = NULL;
struct Keylist {
char *keyname;
int keyval;
char notinf66;
};
struct Punctlist {
char punchar;
int punval;
};
struct Fmtlist {
char fmtchar;
int fmtval;
};
struct Dotlist {
char *dotname;
int dotval;
};
LOCAL struct Keylist *keystart[26], *keyend[26];
/* KEYWORD AND SPECIAL CHARACTER TABLES
*/
static struct Punctlist puncts[ ] =
{
'(', SLPAR,
')', SRPAR,
'=', SEQUALS,
',', SCOMMA,
'+', SPLUS,
'-', SMINUS,
'*', SSTAR,
'/', SSLASH,
'$', SCURRENCY,
':', SCOLON,
'<', SLT,
'>', SGT,
0, 0 };
LOCAL struct Dotlist dots[ ] =
{
"and.", SAND,
"or.", SOR,
"not.", SNOT,
"true.", STRUE,
"false.", SFALSE,
"eq.", SEQ,
"ne.", SNE,
"lt.", SLT,
"le.", SLE,
"gt.", SGT,
"ge.", SGE,
"neqv.", SNEQV,
"eqv.", SEQV,
0, 0 };
LOCAL struct Keylist keys[ ] =
{
{ "assign", SASSIGN },
{ "automatic", SAUTOMATIC, YES },
{ "backspace", SBACKSPACE },
{ "blockdata", SBLOCK },
{ "call", SCALL },
{ "character", SCHARACTER, YES },
{ "close", SCLOSE, YES },
{ "common", SCOMMON },
{ "complex", SCOMPLEX },
{ "continue", SCONTINUE },
{ "data", SDATA },
{ "dimension", SDIMENSION },
{ "doubleprecision", SDOUBLE },
{ "doublecomplex", SDCOMPLEX, YES },
{ "elseif", SELSEIF, YES },
{ "else", SELSE, YES },
{ "endfile", SENDFILE },
{ "endif", SENDIF, YES },
{ "enddo", SENDDO, YES },
{ "end", SEND },
{ "entry", SENTRY, YES },
{ "equivalence", SEQUIV },
{ "external", SEXTERNAL },
{ "format", SFORMAT },
{ "function", SFUNCTION },
{ "goto", SGOTO },
{ "implicit", SIMPLICIT, YES },
{ "include", SINCLUDE, YES },
{ "inquire", SINQUIRE, YES },
{ "intrinsic", SINTRINSIC, YES },
{ "integer", SINTEGER },
{ "logical", SLOGICAL },
{ "namelist", SNAMELIST, YES },
{ "none", SUNDEFINED, YES },
{ "open", SOPEN, YES },
{ "parameter", SPARAM, YES },
{ "pause", SPAUSE },
{ "print", SPRINT },
{ "program", SPROGRAM, YES },
{ "punch", SPUNCH, YES },
{ "read", SREAD },
{ "real", SREAL },
{ "return", SRETURN },
{ "rewind", SREWIND },
{ "save", SSAVE, YES },
{ "static", SSTATIC, YES },
{ "stop", SSTOP },
{ "subroutine", SSUBROUTINE },
{ "then", STHEN, YES },
{ "undefined", SUNDEFINED, YES },
{ "while", SWHILE, YES },
{ "write", SWRITE },
{ 0, 0 }
};
LOCAL void analyz(), crunch(), store_comment();
LOCAL int getcd(), getcds(), getkwd(), gettok();
LOCAL char *stbuf[3];
inilex(name)
char *name;
{
stbuf[0] = Alloc(3*P1_STMTBUFSIZE);
stbuf[1] = stbuf[0] + P1_STMTBUFSIZE;
stbuf[2] = stbuf[1] + P1_STMTBUFSIZE;
nincl = 0;
inclp = NULL;
doinclude(name);
lexstate = NEWSTMT;
return(NO);
}
/* throw away the rest of the current line */
flline()
{
lexstate = RETEOS;
}
char *lexline(n)
int *n;
{
*n = (lastch - nextch) + 1;
return(nextch);
}
doinclude(name)
char *name;
{
FILEP fp;
struct Inclfile *t;
if(inclp)
{
inclp->incllno = thislin;
inclp->inclcode = code;
inclp->inclstno = nxtstno;
if(nextcd)
inclp->incllinp = copyn(inclp->incllen = endcd-nextcd , nextcd);
else
inclp->incllinp = 0;
}
nextcd = NULL;
if(++nincl >= MAXINCLUDES)
Fatal("includes nested too deep");
if(name[0] == '\0')
fp = stdin;
else
fp = fopen(name, textread);
if (fp)
{
t = inclp;
inclp = ALLOC(Inclfile);
inclp->inclnext = t;
prevlin = thislin = 0;
infname = inclp->inclname = name;
infile = inclp->inclfp = fp;
}
else
{
fprintf(diagfile, "Cannot open file %s\n", name);
done(1);
}
}
LOCAL popinclude()
{
struct Inclfile *t;
register char *p;
register int k;
if(infile != stdin)
clf(&infile, infname, 1); /* Close the input file */
free(infname);
--nincl;
t = inclp->inclnext;
free( (charptr) inclp);
inclp = t;
if(inclp == NULL) {
infname = 0;
return(NO);
}
infile = inclp->inclfp;
infname = inclp->inclname;
prevlin = thislin = inclp->incllno;
code = inclp->inclcode;
stno = nxtstno = inclp->inclstno;
if(inclp->incllinp)
{
endcd = nextcd = sbuf;
k = inclp->incllen;
p = inclp->incllinp;
while(--k >= 0)
*endcd++ = *p++;
free( (charptr) (inclp->incllinp) );
}
else
nextcd = NULL;
return(YES);
}
static void
putlineno()
{
static long lastline;
static char *lastfile = "??", *lastfile0 = "?";
static char fbuf[P1_FILENAME_MAX];
extern int gflag;
register char *s0, *s1;
if (gflag) {
if (lastline) {
if (lastfile != lastfile0) {
p1puts(P1_FILENAME, fbuf);
lastfile0 = lastfile;
}
p1_line_number(lastline);
}
lastline = firstline;
if (lastfile != infname)
if (lastfile = infname) {
strnc