#ifndef SYN_DEF
 #define SYN_DEF


//------------------- SYNTAX ANALYZER Module --------------------//
//						  v 08 . 04 .  2007						 //
//																 //
//								MT								 //
//---------------------------------------------------------------//



//---------------------- Incudes 

#include "stdio.h"
#include "ctype.h"
#include "strings.h"
#include "../../ui/onerror.hpp"
#include "stack.hpp"

#include "lex.hpp"
#include "sem.hpp"
//====================== Includes


//---------------------- Defines
#define INT_SIZE 10
#define LEX_OVER "lexems are over. \0"
//====================== Defines


enum type {t_var, t_var_array, t_not_var};

class CSyntax {
private:
	CError Error;
	CRun *exe;
	CStack<char> stack;
	
	Lexeme* begin, *prev, *current, *next;
	bool passed;

	unsigned int ifelse;
public:
	void ShowError(const char *message);
	bool GetPassed() const { return passed; };

	//---
	void SetToBeginLex() {prev=NULL; current=begin; next=begin->next;};
	void BackLex() { next = current; current = prev; };
	void NextLex();
	bool Comp(char *s);

	//--- Some things for poliz
	void Push(char *c) 
	{ char *s = strdup(c); stack.Push(s); };

	void Push(char c) 
	{ char *s = new char[1]; (*s)=c; stack.Push(s); };

	bool IsO1HigherO2(char o1, char o2);
	//--- Poliz helper funcs
	void StackToPOLIZ();
	PolizElem inline *AddToPOLIZ(char c);
	void AddOperPOLIZ(char o2, bool gonext=true);
	void AddLabelPOLIZ(char *s);
	void AddVarPOLIZ(char *var_name, type tmp_type);
					
	//---
	type  sx_Identifier(bool adr);
	void  sx_RobotData();

	void  sx_Expression();
	void  sx_Expression_And();
	void  sx_Expression_Or();
	void  sx_Expression_Bool();
	void  sx_Expression_Term();
	void  sx_Expression_Primary();

	void  sx_Statement();
	void  sx_Statement_Indetifier();
	void  sx_Statement_IfElse();
	void  sx_Statement_IfElse_Else(char *label_else);
	void  sx_Statement_Cycle();
	void  sx_Statement_Goto();
	void  sx_Statement_Robot();
	void  sx_Statement_Robot_Print();

	void sx_Program();
	//===

	public:

		CSyntax(Lexeme* begin_lex, CRun *e) { 
			begin = begin_lex; SetToBeginLex(); 
			exe=e; passed = true;
			ifelse = 0;
		};
		~CSyntax() {  };

		bool MakeAnalysis();
};



//---------------------- GRAMMER 


//==============================


#endif
