#ifndef LEX_DEF
 #define LEX_DEF


//------------------- LEXICAL ANALYZER Module -------------------//
//						  v 03 . 04 .  2007						 //
//																 //
//								MT								 //
//---------------------------------------------------------------//



//---------------------- Incudes 
#include "stdio.h"
#include "ctype.h"
#include "strings.h"
#include "../ui/onerror.hpp"
//====================== Includes



//---------------------- Defines

//====================== Defines


enum lxType {	
			err,

			robotdata,
			assign,
			space,			
			intconst,		
			strconst,		
			variable,		
			label,			
			function,		
			keyword 
};


enum lxStatus {	
		H,	// begin state
		N,	// int analysis
		I,	// id analysis
		K,	// keyword analysis
		A,	// assigment analysis
		S,	// string processing
		X	// placebo :)
};


enum lxCorrect { 
		ok,
		ok_all,
		not_ok_all 
};


class Lexeme {
public:
	char *s;
	int line;

	lxType id;	
	lxCorrect sign;	

	Lexeme *next;
	
	Lexeme () {	sign = not_ok_all;	s = NULL;	next = NULL; id = err;	};
	~Lexeme() {	if (s != NULL)	delete[] s;	if (next != NULL)	delete next;	};
};


class CLexic {
	FILE *fp;
	char c, c_prev, is_prev, for_prev;
	CError Error;

	int current_line;
	Lexeme *begin;
		
		void GetChar();
		void GetPrevChar();
	
		void Make_Ok(Lexeme *a, char *s, int is_only_char = 0);

		lxStatus GetStatus(char c);
		int IsStatusTrue(lxStatus t, char c);
		void NIKS(lxStatus t, Lexeme *a, int c);
		Lexeme* GetNextLexem();

public:
		CLexic (char *s) { fp = fopen(s, "r"); if (fp==NULL) Error.OnError("File .bot not open.",-511); begin = NULL; current_line = 1;   c[0]=0; c[1]=0; is_prev = 0; for_prev = 0; };
		~CLexic () { delete begin; };

		bool MakeAnalysis();
		void Print(Lexeme *l);
		Lexeme *GetBeginLexeme();
};


#endif
