home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
flex-2.4.6-src.lha
/
src
/
amiga
/
flex-2.4.6
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-04
|
25KB
|
990 lines
/* flex - tool to generate fast lexical analyzers */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Vern Paxson.
*
* The United States Government has rights in this work pursuant
* to contract no. DE-AC03-76SF00098 between the United States
* Department of Energy and the University of California.
*
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
/* $Header: main.c,v 1.2 94/01/04 14:33:11 vern Exp $ */
#include "flexdef.h"
#include "version.h"
static char flex_version[] = FLEX_VERSION;
/* declare functions that have forward references */
void flexinit PROTO((int, char**));
void readin PROTO((void));
void set_up_initial_allocations PROTO((void));
/* these globals are all defined and commented in flexdef.h */
int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
int interactive, caseins, lex_compat, useecs, fulltbl, usemecs;
int fullspd, gen_line_dirs, performance_report, backing_up_report;
int C_plus_plus, long_align, use_read, yytext_is_array, csize;
int yymore_used, reject, real_reject, continued_action;
int yymore_really_used, reject_really_used;
int datapos, dataline, linenum;
FILE *skelfile = NULL;
int skel_ind = 0;
char *action_array;
int action_size, defs1_offset, prolog_offset, action_offset, action_index;
char *infilename = NULL;
int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
int current_mns, num_rules, num_eof_rules, default_rule;
int current_max_rules, lastnfa;
int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
int *accptnum, *assoc_rule, *state_type;
int *rule_type, *rule_linenum, *rule_useful;
int current_state_type;
int variable_trailing_context_rules;
int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
int tecbck[CSIZE + 1];
int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
char **scname;
int current_max_dfa_size, current_max_xpairs;
int current_max_template_xpairs, current_max_dfas;
int lastdfa, *nxt, *chk, *tnxt;
int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
union dfaacc_union *dfaacc;
int *accsiz, *dhash, numas;
int numsnpairs, jambase, jamstate;
int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
int current_max_ccl_tbl_size;
Char *ccltbl;
char nmstr[MAXLINE];
int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
int num_backing_up, bol_needed;
FILE *backing_up_file;
int end_of_buffer_state;
char **input_files;
int num_input_files;
char *program_name;
#ifndef SHORT_FILE_NAMES
static char *outfile_template = "lex.%s.%s";
#else
static char *outfile_template = "lex%s.%s";
#endif
static char outfile_path[64];
static int outfile_created = 0;
static int use_stdout;
static char *skelname = NULL;
static char *prefix = "yy";
int main( argc, argv )
int argc;
char **argv;
{
int i;
flexinit( argc, argv );
readin();
ntod();
for ( i = 1; i <= num_rules; ++i )
if ( ! rule_useful[i] && i != default_rule )
line_warning( "rule cannot be matched",
rule_linenum[i] );
if ( spprdflt && ! reject && rule_useful[default_rule] )
line_warning( "-s option given but default rule can be matched",
rule_linenum[default_rule] );
/* Generate the C state transition tables from the DFA. */
make_tables();
/* Note, flexend does not return. It exits with its argument
* as status.
*/
flexend( 0 );
return 0; /* keep compilers/lint happy */
}
/* flexend - terminate flex
*
* note
* This routine does not return.
*/
void flexend( exit_status )
int exit_status;
{
int tblsiz;
int unlink();
if ( skelfile != NULL )
{
if ( ferror( skelfile ) )
flexfatal(
"error occurred when reading skeleton file" );
else if ( fclose( skelfile ) )
flexfatal(
"error occurred when closing skeleton file" );
}
if ( exit_status != 0 && outfile_created )
{
if ( ferror( stdout ) )
flexfatal( "error occurred when writing output file" );
else if ( fclose( stdout ) )
flexfatal( "error occurred when closing output file" );
else if ( unlink( outfile_path ) )
flexfatal( "error occurred when deleting output file" );
}
if ( backing_up_report && backing_up_file )
{
if ( num_backing_up == 0 )
fprintf( backing_up_file, "No backing up.\n" );
else if ( fullspd || fulltbl )
fprintf( backing_up_file,
"%d backing up (non-accepting) states.\n",
num_backing_up );
else
fprintf( backing_up_file,
"Compressed tables always back up.\n" );
if ( ferror( backing_up_file ) )
flexfatal( "error occurred when writing backup file" );
else if ( fclose( backing_up_file ) )
flexfatal( "error occurred when closing backup file" );
}
if ( printstats )
{
fprintf( stderr, "%s version %s usage statistics:\n",
program_name, flex_version );
fprintf( stderr, " scanner options: -" );
if ( C_plus_plus )
putc( '+', stderr );
if ( backing_up_report )
putc( 'b', stderr );
if ( ddebug )
putc( 'd', stderr );
if ( caseins )
putc( 'i', stderr );
if ( lex_compat )
putc( 'l', stderr );
if ( performance_report > 0 )
putc( 'p', stderr );
if ( performance_report > 1 )
putc( 'p', stderr );
if ( spprdflt )
putc( 's', stderr );
if ( use_stdout )
putc( 't', stderr );
if ( printstats )
putc( 'v', stderr ); /* always true! */
if ( nowarn )
putc( 'w', stderr );
if ( ! interactive )
putc( 'B', stderr );
if ( interactive )
putc( 'I', stderr );
if ( ! gen_line_dirs )
putc( 'L', stderr );
if ( trace )
putc( 'T', stderr );
if ( csize == 128 )
putc( '7', stderr );
else
putc( '8', stderr );
fprintf( stderr, " -C" );
if ( long_align )
putc( 'a', stderr );
if ( fulltbl )
putc( 'f', stderr );
if ( fullspd )
putc( 'F', stderr );
if ( useecs )
putc( 'e', stderr );
if ( usemecs )
putc( 'm', stderr );
if ( use_read )
putc( 'r', stderr );
if ( skelname )
fprintf( stderr, " -S%s", skelname );
if ( strcmp( prefix, "yy" ) )
fprintf( stderr, " -P%s", prefix );
putc( '\n', stderr );
fprintf( stderr, " %d/%d NFA states\n", lastnfa, current_mns );
fprintf( stderr, " %d/%d DFA states (%d words)\n", lastdfa,
current_max_dfas, totnst );
fprintf( stderr, " %d rules\n",
num_rules + num_eof_rules - 1 /* - 1 for def. rule */ );
if ( num_backing_up == 0 )
fprintf( stderr, " No backing up\n" );
else if ( fullspd || fulltbl )
fprintf( stderr,
" %d backing-up (non-accepting) states\n",
num_backing_up );
else
fprintf( stderr,
" Compressed tables always back-up\n" );
if ( bol_needed )
fprintf( stderr,
" Beginning-of-line patterns used\n" );
fprintf( stderr, " %d/%d start conditions\n", lastsc,
current_max_scs );
fprintf( stderr,
" %d epsilon states, %d double epsilon states\n",
numeps, eps2 );
if ( lastccl == 0 )