U E D R , A S I H C RSS

Building Parser/Lexical Analyzer

Lexical Analyzer

State Graph


Source Code

~cpp
unsigned int			g_token_size			=	0;
PTOKEN_DEC				g_token_array			=	NULL;

FILE*					g_source_fp				=	NULL;

unsigned int			next_token				=	-1;
char					next_string[_SBUFF]		=	{0,};

char					next_char				=	0;

int lexical()
{
	assert( g_source_fp && g_token_array );
	memset( next_string, 0, sizeof(next_string) );
	next_token	=	KEYWORD_EXCEPTION;

	if ( feof(g_source_fp) ) return _lex_set_last_error(next_token, ERRORCODE_END_OF_FILE);

	for(;_lex_is_char() == TYPE_UNKNOWN;)
	_lex_get_char();
	
	switch( _lex_is_char() )
	{
	case TYPE_LITTERAL:
		_lex_add_char();
		_lex_get_char();
		while( _lex_is_char() == TYPE_LITTERAL || _lex_is_char() == TYPE_DIGIT )
		{
			_lex_add_char();
			_lex_get_char();
		}
		return _lex_lookup(next_string);
		break;

	case TYPE_DIGIT:
		_lex_add_char();
		_lex_get_char();
		while( _lex_is_char() == TYPE_DIGIT || (strlen(next_string) != 0 && next_char == '.') )
		{
			_lex_add_char();
			_lex_get_char();
		}
		return (next_token	= KEYWORD_NUMERAL);
		break;

	case TYPE_ETC:
		_lex_add_char();
		_lex_get_char();
		while( _lex_is_char() == TYPE_ETC )
		{
			_lex_add_char();
			_lex_get_char();
		}
		return _lex_lookup(next_string);
		break;

	default:
		break;
	}

	_lex_rewind_char();
	return _lex_set_last_error(KEYWORD_EXCEPTION, ERRORCODE_UNKNOWN_CHARACTER);
}
대충 이런형태로 구현함.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0910 sec