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

📄 pgc.l

📁 PostgreSQL7.4.6 for Linux
💻 L
📖 第 1 页 / 共 2 页
字号:
						}						if (ptr == NULL)						{							/* Is it an SQL keyword? */							keyword = ScanKeywordLookup(yytext);							if (keyword != NULL)								return keyword->value;							/* Is it an ECPG keyword? */							keyword = ScanECPGKeywordLookup( yytext);							if (keyword != NULL)								return keyword->value;							/* Is it a C keyword? */							keyword = ScanCKeywordLookup(yytext);							if (keyword != NULL)								return keyword->value;							/*							 * None of the above.  Return it as an identifier.							 *							 * The backend would attempt to truncate and case-fold							 * the identifier, but I see no good reason for ecpg							 * to do so; that's just another way that ecpg could get							 * out of step with the backend.							 */							if (ptr == NULL)							{								yylval.str = mm_strdup(yytext);								return IDENT;							}						}					}<SQL>{other}		{ return yytext[0]; }<C>{exec_sql}		{ BEGIN SQL; return SQL_START; }<C>{informix_special}	{ 			  /* are we simulating Informix? */			  if (INFORMIX_MODE)			  {			  	BEGIN SQL;				return SQL_START;			  }			  else			  	return S_ANYTHING;			 }<C>{ccomment}		 { ECHO; }<C>{xch}			{						char* endptr;						errno = 0;						yylval.ival = strtoul((char *)yytext,&endptr,16);						if (*endptr != '\0' || errno == ERANGE)						{							errno = 0;							yylval.str = mm_strdup(yytext);							return SCONST;						}						return ICONST;					}<C>{cppinclude}		{					  if (system_includes)					  {					  	BEGIN(incl);					  }					  else					  {						yylval.str = mm_strdup(yytext);						return(CPP_LINE);					  }			}<C>{cppline}		{						yylval.str = mm_strdup(yytext);						return(CPP_LINE);					}<C>{identifier} 	{						ScanKeyword		*keyword;						struct _defines *ptr;						/* is it a define? */						for (ptr = defines; ptr; ptr = ptr->next)						{							if (strcmp(yytext, ptr->old) == 0 && ptr->used == NULL)							{								struct _yy_buffer *yb;								yb = mm_alloc(sizeof(struct _yy_buffer));								yb->buffer =  YY_CURRENT_BUFFER;								yb->lineno = yylineno;								yb->filename = mm_strdup(input_filename);								ptr->used = yb->next = yy_buffer;								yy_buffer = yb;								yy_scan_string(ptr->new);								break;							}						}						if (ptr == NULL)						{							keyword = ScanCKeywordLookup(yytext);							if (keyword != NULL)								return keyword->value;							else {								yylval.str = mm_strdup(yytext);								return IDENT;							}						}					}<C>";"				{ return(';'); }<C>","				{ return(','); }<C>"*"				{ return('*'); }<C>"%"				{ return('%'); }<C>"/"				{ return('/'); }<C>"+"				{ return('+'); }<C>"-"				{ return('-'); }<C>"("				{ return('('); }<C>")"				{ return(')'); }<C,xskip>{space}		{ ECHO; }<C>\{				{ return('{'); }<C>\}				{ return('}'); }<C>\[				{ return('['); }<C>\]				{ return(']'); }<C>\=				{ return('='); }<C>"->"				{ return(S_MEMBER); }<C>">>"				{ return(S_RSHIFT); }<C>"<<"				{ return(S_LSHIFT); }<C>"||"				{ return(S_OR); }<C>"&&"				{ return(S_AND); }<C>"++"				{ return(S_INC); }<C>"--"				{ return(S_DEC); }<C>"=="				{ return(S_EQUAL); }<C>"!="				{ return(S_NEQUAL); }<C>"+="				{ return(S_ADD); }<C>"-="				{ return(S_SUB); }<C>"*="				{ return(S_MUL); }<C>"/="				{ return(S_DIV); }<C>"%="				{ return(S_MOD); }<C>"->*"			{ return(S_MEMPOINT); }<C>".*"				{ return(S_DOTPOINT); }<C>{other}			{ return S_ANYTHING; }<C>{exec_sql}{define}{space}*	{ BEGIN(def_ident); }<C>{informix_special}{define}{space}*	{						/* are we simulating Informix? */						if (INFORMIX_MODE)						{							BEGIN(def_ident);						}						else						{							yyless(1);							return (S_ANYTHING);						}					}<C>{exec_sql}{include}{space}*	{ BEGIN(incl); }<C>{informix_special}{include}{space}* { 					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						  BEGIN(incl);					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<C,xskip>{exec_sql}{ifdef}{space}*	{ ifcond = TRUE; BEGIN(xcond); }<C,xskip>{informix_special}{ifdef}{space}* { 					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						  ifcond = TRUE;						  BEGIN(xcond);					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<C,xskip>{exec_sql}{ifndef}{space}* { ifcond = FALSE; BEGIN(xcond); }<C,xskip>{informix_special}{ifndef}{space}* { 					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						  ifcond = FALSE;						  BEGIN(xcond);					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<C,xskip>{exec_sql}{elif}{space}*	{	/* pop stack */						if ( preproc_tos == 0 ) {							mmerror(PARSE_ERROR, ET_FATAL, "Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");						}						else if ( stacked_if_value[preproc_tos].else_branch )							mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");						else							preproc_tos--;						ifcond = TRUE; BEGIN(xcond);					}<C,xskip>{informix_special}{elif}{space}* { 					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						if ( preproc_tos == 0 ) {							mmerror(PARSE_ERROR, ET_FATAL, "Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");						}						else if ( stacked_if_value[preproc_tos].else_branch )							mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");						else							preproc_tos--;						ifcond = TRUE; BEGIN(xcond);					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<C,xskip>{exec_sql}{else}{space}*";" {	/* only exec sql endif pops the stack, so take care of duplicated 'else' */						if ( stacked_if_value[preproc_tos].else_branch ) {							mmerror(PARSE_ERROR, ET_FATAL, "Duplicated 'EXEC SQL ELSE;'");						}						else {							stacked_if_value[preproc_tos].else_branch = TRUE;							stacked_if_value[preproc_tos].condition =							(stacked_if_value[preproc_tos-1].condition &&							 ! stacked_if_value[preproc_tos].condition);							if ( stacked_if_value[preproc_tos].condition )								BEGIN(C);							else								BEGIN(xskip);						}					}<C,xskip>{informix_special}{else}{space}*	{					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						if ( stacked_if_value[preproc_tos].else_branch ) {							mmerror(PARSE_ERROR, ET_FATAL, "Duplicated 'EXEC SQL ELSE;'");						}						else {							stacked_if_value[preproc_tos].else_branch = TRUE;							stacked_if_value[preproc_tos].condition =							(stacked_if_value[preproc_tos-1].condition &&							 ! stacked_if_value[preproc_tos].condition);							if ( stacked_if_value[preproc_tos].condition )								BEGIN(C);							else								BEGIN(xskip);						}					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<C,xskip>{exec_sql}{endif}{space}*";" {						if ( preproc_tos == 0 )							mmerror(PARSE_ERROR, ET_FATAL, "Unmatched 'EXEC SQL ENDIF;'");						else							preproc_tos--;						if ( stacked_if_value[preproc_tos].condition )						   BEGIN(C);						else						   BEGIN(xskip);					}<C,xskip>{informix_special}{endif}{space}*";"	{					  /* are we simulating Informix? */					  if (INFORMIX_MODE)					  {						if ( preproc_tos == 0 )							mmerror(PARSE_ERROR, ET_FATAL, "Unmatched 'EXEC SQL ENDIF;'");						else							preproc_tos--;						if ( stacked_if_value[preproc_tos].condition )						   BEGIN(C);						else						   BEGIN(xskip);					  }					  else					  {						  yyless(1);						  return (S_ANYTHING);					  }					}<xskip>{other}		{ /* ignore */ }<xcond>{identifier}{space}*";" {						if ( preproc_tos >= MAX_NESTED_IF-1 ) {							mmerror(PARSE_ERROR, ET_FATAL, "Too many nested 'EXEC SQL IFDEF' conditions");						}						else 						{							struct _defines *defptr;							unsigned int i;							/* skip the ";" and trailing whitespace. Note that yytext contains							   at least one non-space character plus the ";" */							for ( i = strlen(yytext)-2;								  i > 0 && isspace((unsigned char) yytext[i]);								  i-- )							{}							yytext[i+1] = '\0';							for ( defptr = defines; defptr != NULL &&								  ( strcmp(yytext, defptr->old) != 0 ); defptr = defptr->next );							preproc_tos++;							stacked_if_value[preproc_tos].else_branch = FALSE;							stacked_if_value[preproc_tos].condition =							( (defptr ? ifcond : !ifcond) && stacked_if_value[preproc_tos-1].condition );						}						if ( stacked_if_value[preproc_tos].condition )						   BEGIN C;						else						   BEGIN(xskip);					}<def_ident>{identifier} {				old = mm_strdup(yytext);				BEGIN(def);				startlit();			}<def>{space}*";"	{						struct _defines *ptr, *this;						for (ptr = defines; ptr != NULL; ptr = ptr->next)						{							 if (strcmp(old, ptr->old) == 0)							 {								free(ptr->new);								/* ptr->new = mm_strdup(scanstr(literalbuf));*/								ptr->new = mm_strdup(literalbuf);							 }						}						if (ptr == NULL)						{							this = (struct _defines *) mm_alloc(sizeof(struct _defines));							/* initial definition */							this->old = old;							this->new = mm_strdup(literalbuf);							this->next = defines;							this->used = NULL;							defines = this;						}						BEGIN(C);					}<def>[^;]			{ addlit(yytext, yyleng); }<incl>\<[^\>]+\>{space}*";"?		{	parse_include(); }<incl>{dquote}{xdinside}{dquote}{space}*";"?	{	parse_include(); }<incl>[^;\<\>\"]+";"		{ parse_include(); }<<EOF>>				{				  		if (yy_buffer == NULL) {				  		if ( preproc_tos > 0 ) 						{					  		preproc_tos = 0;							mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");				  		}							yyterminate();							}				  		else				  		{							struct _yy_buffer *yb = yy_buffer;							int i;							struct _defines *ptr;							for (ptr = defines; ptr; ptr = ptr->next)								if (ptr->used == yy_buffer)							        {									ptr->used = NULL;							                break;							        }														if (yyin != NULL)								fclose(yyin);							yy_delete_buffer( YY_CURRENT_BUFFER );							yy_switch_to_buffer(yy_buffer->buffer);							yylineno = yy_buffer->lineno;							/* We have to output the filename only if we change files here */							i = strcmp(input_filename, yy_buffer->filename);							free(input_filename);							input_filename = yy_buffer->filename;							yy_buffer = yy_buffer->next;							free(yb);							if (i != 0)								output_line_number();				  		}					}%%voidlex_init(void){	braces_open = 0;	preproc_tos = 0;	yylineno = 1;	ifcond = TRUE;	stacked_if_value[preproc_tos].condition = ifcond;	stacked_if_value[preproc_tos].else_branch = FALSE;	/* initialize literal buffer to a reasonable but expansible size */	if (literalbuf == NULL)	{		literalalloc = 128;		literalbuf = (char *) malloc(literalalloc);	}	startlit();	BEGIN C;}static voidaddlit(char *ytext, int yleng){	/* enlarge buffer if needed */	if ((literallen+yleng) >= literalalloc)	{		do 			literalalloc *= 2;		while ((literallen+yleng) >= literalalloc);		literalbuf = (char *) realloc(literalbuf, literalalloc);	}	/* append new data, add trailing null */	memcpy(literalbuf+literallen, ytext, yleng);	literallen += yleng;	literalbuf[literallen] = '\0';}static voidaddlitchar(unsigned char ychar){	/* enlarge buffer if needed */        if ((literallen+1) >= literalalloc)        {                literalalloc *= 2;                literalbuf = (char *) realloc(literalbuf, literalalloc);        }	/* append new data, add trailing null */	literalbuf[literallen] = ychar;	literallen += 1;	literalbuf[literallen] = '\0';}static voidparse_include(void){	/* got the include file name */	struct _yy_buffer *yb;  	struct _include_path *ip;  	char inc_file[MAXPGPATH];  	unsigned int i;  	yb = mm_alloc(sizeof(struct _yy_buffer));  	yb->buffer =	YY_CURRENT_BUFFER;  	yb->lineno = yylineno;  	yb->filename = input_filename;  	yb->next = yy_buffer;  	yy_buffer = yb;  	/*	 * skip the ";" if there is one and trailing whitespace. Note that	 * yytext contains at least one non-space character plus the ";" 	 */  	for ( i = strlen(yytext)-2;		i > 0 && isspace((unsigned char) yytext[i]);		i-- )  		{}	if (yytext[i] == ';')		i--;	yytext[i+1] = '\0';		yyin = NULL;	/* If file name is enclosed in '"' remove these and look only in '.' */	/* Informix does look into all include paths though, except filename starts with '/' */	if ((yytext[0] == '"' && yytext[i] == '"') &&	    ((compat != ECPG_COMPAT_INFORMIX && compat != ECPG_COMPAT_INFORMIX_SE) || yytext[1] == '/'))	{		yytext[i] = '\0';		memmove(yytext, yytext+1, strlen(yytext));			strncpy(inc_file, yytext, sizeof(inc_file));		yyin = fopen(inc_file, "r");		if (!yyin)		{			if (strcmp(inc_file + strlen(inc_file) - 2, ".h"))			{				strcat(inc_file, ".h");				yyin = fopen(inc_file, "r");			}		}			}	else	{		if ((yytext[0] == '"' && yytext[i] == '"') || (yytext[0] == '<' && yytext[i] == '>'))		{			yytext[i] = '\0';			memmove(yytext, yytext+1, strlen(yytext));		}			  	for (ip = include_paths; yyin == NULL && ip != NULL; ip = ip->next)	  	{			if (strlen(ip->path) + strlen(yytext) + 3 > MAXPGPATH)			{				fprintf(stderr, "Error: Path %s/%s is too long in line %d, skipping.\n", ip->path, yytext, yylineno);				continue;			}			snprintf (inc_file, sizeof(inc_file), "%s/%s", ip->path, yytext);			yyin = fopen(inc_file, "r");			if (!yyin)			{				if (strcmp(inc_file + strlen(inc_file) - 2, ".h"))				{					strcat(inc_file, ".h");					yyin = fopen( inc_file, "r" );				}			}		}	}	if (!yyin)	{		snprintf(errortext, sizeof(errortext), "Cannot open include file %s in line %d\n", yytext, yylineno);		mmerror(NO_INCLUDE_FILE, ET_FATAL, errortext);  	}	input_filename = mm_strdup(inc_file);	yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE ));	yylineno = 1;	output_line_number();  	BEGIN C;}

⌨️ 快捷键说明

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