//------------------------- CLexeme ------------------------

//------------------------- CLexic -------------------------

//--- CLexem :: Get Init Status
EStatus CLexic :: GetStatus()
{
	if (IsDigit(c))  return lx_int_const;
	if (IsLetter(c)) return lx_keyword;
	if (IsSpacer(c)) return lx_spacer;	

	switch (c) {
		'@' : return lx_label;
		':' : return lx_assignment;
		'"' : return lx_str_const;

		'$' : return lx_var;
		'?' : return lx_func;
		'.' : return lx_robotdata;

		default : return lx_err;
	}
};


//--- CLexec :: Is Status Change?
bool CLexic :: IsStatusChange()
{
	switch (state) {
		case S_NUMBR: if (IsDigit(c)) return false; break;

		case S_VARBL : 
		case S_ROBOT : 
		case S_LABEL : 
		case S_FUNCT : 
			if (IsDigit(c)||IsLetter(c)) return false; break;

		case S_KEYWD: if (IsSymbol(c)) return false; break;

		case S_STRNG: if ( c != '"' && c != EOF) return false; break;

		case S_INIT : return true; break;
		default : break;
	};
	return true;

//	S_ASSGN, ?
};


//--- CLexem :: GetLexeme
void CLexic :: GetLexeme()
{
	while (file.GetChar() != EOF)
	{
		if (file.c==13 || file.c=='\n') { line++; continue; };
		if (file.c==' ' && file.c=='\t') continue;
		Parse();
	}
};


//--- CLexem :: Parse Automat
void CLexic :: Parse_Init()
{
	lex.MakeOk(file.GetBuf());
	file.Clear();
	state = GetState();
	lex->next = new Lexeme;
	lex = lex->next;
};


//--- CLexem :: Parse Automat
void CLexic :: Parse()
{
	switch (state) {
		case S_INIT : Parse_Init();	break;
		
		case S_VARBL : lex.id = lx_var; break;
		case S_ROBOT : lex.id = lx_robotdata; break;
		case S_SPACE : lex.id = lx_spacer; break;
	};
	
	if (IsStatusChange())  state = S_INIT;
};


