⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexyy.c

📁 LEX程序 用来生成词法分析器
💻 C
📖 第 1 页 / 共 2 页
字号:
#line 1"test.lex"
int cc[5] = {0,0,0,0,0} ; /* 五种单词符号计数 */ 

#ifdef _NEVER_ 
/*--------------------------------------
 *DFA (start state is 0) is: 
 *
 * state 0 [nonaccepting]
 *	goto  6 on +
 *	goto  5 on ,
 *	goto  4 on -
 *	goto  3 on 0123456789
 *	goto 11 on :
 *	goto  2 on ;
 *	goto  1 on ABCDEFGHIJKLMNOPQ
 *	goto 24 on R
 *	goto  1 on STU
 *	goto 18 on V
 *	goto  1 on WXYZabcd
 *	goto 23 on e
 *	goto  1 on fghijklmnopq
 *	goto 22 on r
 *	goto  1 on stu
 *	goto 17 on v
 *	goto  1 on wxyz
 * state 1 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
 *				vwxyz
 * state 2 [accepting, line 9 <{ cc[4]++;}>]
 * state 3 [accepting, line 13 <{cc[2]++; }>]
 *	goto  3 on 0123456789
 * state 4 [accepting, line 6 <{cc[3]++; }>]
 * state 5 [accepting, line 8 <{ cc[4]++;}>]
 * state 6 [accepting, line 5 <{cc[3]++;}>]
 * state 7 [accepting, line 7 <{ cc[4]++;}>]
 * state 8 [accepting, line 10 <{cc[1]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
 *				vwxyz
 * state 9 [accepting, line 11 <{cc[1]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu
 *				vwxyz
 * state 10 [accepting, line 14 <{ printf("\\nident:%>]
 * state 11 [nonaccepting]
 *	goto  7 on =
 * state 12 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq
 *	goto  8 on r
 *	goto  1 on stuvwxyz
 * state 13 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQ
 *	goto  8 on R
 *	goto  1 on STUVWXYZabcdefghijklmnopqrstuvwxyz
 * state 14 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc
 *	goto  9 on d
 *	goto  1 on efghijklmnopqrstuvwxyz
 * state 15 [accepting, line 12 <{cc[0]++; }>]
 *	goto 10 on \x000\x001\x002\x003\x004\x005\x006\x007\b\t\n\x00b\f\r\x00e
 *				\x00f\x010\x011\x012\x013\x014\x015\x016\x017\x018\x019\x01a
 *				\x01b\x01c\x01d\x01e\x01f !"#$%&\'()*+,-./
 *	goto  1 on 0123456789
 *	goto 10 on :;<=>?@
 *	goto  1 on ABCDEFGHIJKLMNOPQRSTUVWXYZ
 *	goto 10 on [\\]^_`
 *	goto  1 on abcdefghijklmnopqrstuvwxyz
 *	goto 10 on {|}~\x07f
 * state 16 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABC
 *	goto  9 on D
 *	goto  1 on EFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
 * state 17 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
 *	goto 12 on a
 *	goto  1 on bcdefghijklmnopqrstuvwxyz
 * state 18 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789
 *	goto 13 on A
 *	goto  1 on BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
 * state 19 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
 *	goto 14 on a
 *	goto  1 on bcdefghijklmnopqrstuvwxyz
 * state 20 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc
 *	goto 15 on d
 *	goto  1 on efghijklmnopqrstuvwxyz
 * state 21 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789
 *	goto 16 on A
 *	goto  1 on BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
 * state 22 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd
 *	goto 19 on e
 *	goto  1 on fghijklmnopqrstuvwxyz
 * state 23 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm
 *	goto 20 on n
 *	goto  1 on opqrstuvwxyz
 * state 24 [accepting, line 12 <{cc[0]++; }>]
 *	goto  1 on 0123456789ABCD
 *	goto 21 on E
 *	goto  1 on FGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
 */

#endif 

#line 1 "lex.par"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <io.h>

#define COPY(d,s,a) memmove(d,s,a)

#define STDIN	0

#define BUFSIZE 1024

#define EOLN    257

typedef unsigned char	uchar ;

uchar Start_buf[BUFSIZE] ;
uchar *End_buf = Start_buf;
uchar *Next = Start_buf;
uchar *sMark = Start_buf;
uchar *eMark = Start_buf;

int Inp_file = STDIN;
int	Lineno = 0;
int	Mline = 0;
int Termchar = 0;


int	(*Openp)() =(int (*)())open;
int	(*Closep)() =(int (*)())close;
int	(*Readp)(int, char *, int ) =(int (*)(int,char *, int))read;


char 	*ii_mark_start( void );
char 	*ii_mark_end( void );
char 	*ii_to_mark( void );
int 	ii_advance( void );
int 	ii_fillbuf( unsigned char *starting_at );
int		ii_look( int );
int 	ii_pushback( int );
void 	ii_term( void );
void 	ii_unterm( void );


void prnt( int (*ofunct)(char,void *), void *funct_arg, char *format, va_list args )
{
	char buf[256], *p;
	vsprintf( buf, format, args );
	for ( p = buf; *p; p ++ )
		(*ofunct)( *p, funct_arg );
}

int on_ferr( void )
{
	extern int errno ;
	return errno ;
}

int ferr( char *fmt, ... )
{
	va_list	args ;
	va_start( args, fmt ) ;

	if( fmt ) prnt ( (int(*)(char,void *))fputc, stderr, fmt , args ) ;
	else	perror( va_arg( args, char* ) ) ;

	va_end( args ) ;
	exit ( on_ferr() ) ;
	return 0;
}

/*-------------------------------------------------------------------------
  VISIT ROUTINE & MARK-MOVING
*/

char *ii_text	(void) { return sMark ; }
int	ii_length	(void) { return eMark-sMark ; }
int	ii_lineno	(void) { return Lineno ; }

char *ii_mark_start(void)
{
	if ( Next >= End_buf )
	{
		ii_fillbuf( Start_buf );
		Next = Start_buf;
		Lineno ++;
	}
	Mline = Lineno;
	eMark = sMark = Next;
	return sMark;
}

char *ii_mark_end(void)
{
	Mline =Lineno ;
	return( eMark =Next ) ;
}

char *ii_to_mark(void)
{
	Lineno =Mline ;
	return( Next =eMark ) ;
}


/*-------------------------------------------------------------------------
  INPUT ROUTINE
*/

int ii_advance(void)
{
	return( *Next++ ) ;
}

/*-------------------------------------------------------------------------*/

int ii_fillbuf( unsigned char *starting_at )
{
	int got;

	if( (got =(*Readp)(Inp_file, starting_at, BUFSIZE)) ==-1 )
		ferr("Cannot erad input file \n");

	End_buf =starting_at + got;

	return got ;
}

/*-------------------------------------------------------------------------
  LOOKAHEAD
*/

int	ii_look( int n )
{
	uchar	*p ;

	p =Next +(n-1) ;

	return (p>=End_buf)? EOLN : *p ;
}

/*-------------------------------------------------------------------------
  PUSH n CHARACTERS BACK INTO THE INPUT.
*/

int ii_pushback( int n )
{
	while( --n >=0 && Next >sMark )
	{
		--Next;
	}

	if( Next <eMark )
	{
		eMark =Next ;
	}
	return( Next> sMark ) ;
}

/*-------------------------------------------------------------------------*/

void ii_term(void)
{
	Termchar =*Next ;
	*Next ='\0' ;
}

void ii_unterm(void)
{
	if( Termchar )
	{
		*Next =Termchar ;
		Termchar =0 ;
	}
}

/*-------------------------------------------------------------*/
#ifndef	YYPRIVATE
#	define YYPRIVATE 	static
#endif

#ifndef	NULL
# 	include <stdio.h>
#endif

#ifdef	YYDEBUG
	int yydebug =0 ;
#	define YY_D(x) 	if( yydebug ) { x; } else
#else
#	define YY_D(x)
#endif

typedef unsigned    char    YY_TTYPE ;
#define	YYF	(( YY_TTYPE )(-1) )


/*-----------------------------------------------
*The Yy_cmap[] and Yy_rmap arrays are used as follows:
*
* next_state =YyDtran[ Yy_rmap[ current_state] ][ Yy_cmap[input_char] ];
*
*Character positions in the Yy_cmap array are:
*
*  ^@  ^A  ^B  ^C  ^D  ^E  ^F  ^G  ^H  ^I  ^J  ^K  ^L  ^M  ^N  ^O
*  ^P  ^Q  ^R  ^S  ^T  ^U  ^V  ^W  ^X  ^Y  ^Z  ^[  ^\ ^]  ^^  ^_
*       !  "   #   $   %   &   '   (   )   *   +   ,   -   .   /
*   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
*   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
*   P   Q   R   S   T   U   V   W   X   Y   Z   [   \  ]   ^   _
*   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
*   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~   DEL
*/

YYPRIVATE YY_TTYPE Yy_cmap[128] =
{
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  0,  0,
       4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  5,  6,  0,  7,  0,  0,
       0,  8,  9,  9, 10, 11,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
       9,  9, 12,  9,  9,  9, 13,  9,  9,  9,  9,  0,  0,  0,  0,  0,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -