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

📄 error_.c

📁 一个C语言的词法分析器
💻 C
字号:
/*++
	module name: error_.c
	handle the error in whole process
--*/
#include <stdio.h>
#include "error_.h"
/***************************************************************************/
int	  error_count = 0; 
int	  line	 = 1;
ERROR_NODE  error_table[MAX_ERROR_NUM];
/* error handle functions     */
/* write error info to error table  */
void report_error(int error_code, int line, void *p_item)
{
	ERROR_NODE	err_node = { error_code, line, p_item };
	if( error_count == MAX_ERROR_NUM )
		return;
	error_table[error_count++] = err_node;
	/*	already have too much errors, can store a fatal error only	*/
	if( error_count +1 == MAX_ERROR_NUM )
	{
		ERROR_NODE err = { ERROR_TOO_MANY, 0, NULL };
		error_table[error_count++] = err; 
	}
}

void print_error (void )
{
	int i;
	for(i=0; i <error_count; i++ )
	{	switch( error_table[i].error_code )
		{
		case ERROR_UNKNOWN_CHAR:
			fprintf(stdout, "line (%3d) error %d: unknown character: 0x%2x.\n", 
				error_table[i].line, error_table[i].error_code, (*(char*)error_table[i].p_item & 0xFF) );
			break;
		case ERROR_ILLEGAL_CHAR:
			fprintf(stdout, "line (%3d) error %d: illegal character asignment...\n", 
			    error_table[i].line, error_table[i].error_code );
			break;
		case ERROR_ILLEGAL_STR:
			fprintf(stdout, "line (%3d) error %d: illegal const string asignment...\n", 
				error_table[i].line, error_table[i].error_code );
			break;
		case ERROR_ILLEGAL_REAL:
			fprintf(stdout, "line (%3d) error %d: illegal double asignment...\n", 
				error_table[i].line, error_table[i].error_code );
			break;
		case ERROR_TOO_MANY:
			fprintf(stdout, "fatal error %d: too many errors, refuse to continue...\n", 
				error_table[i].error_code );
			break;
		default:
			break;
		}/* switch */
	}/* for */
	printf(" %3d error(s)\n", error_count );
}
/*******************************end of file********************************/
 

⌨️ 快捷键说明

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