/* MasAsm compiler
   written by Jared Bruni
   www.LostSideDead.com

  translates from  masasm to C
  then shells to gcc 

*/

#include<iostream>
#include<cstring>
#include<cstdarg>
#include<fstream>
#include"masterstring2.h"

const int MAX = 255;

using namespace std;
using namespace masterstring;

namespace masasm 
{
	int errors = 0;
	char path[255];

	enum { VAR_STRING, VAR_INTEGER, VAR_FLOAT };

	enum { MOV = 1, PRINT,INPUT, PAUSE, RETURN ,INC, DEC, ADD, SUB, MUL , DIV, AND, OR, XOR, NOT, CMP,JMP, JNE, JE, JGE, JG, JL, JLE};

	struct Variable
	{
		char name[MAX];
		char *val;
		int type;
		bool on;

		Variable()
		{
			val = NULL;
			on = false;
		}

		~Variable()
		{
			if(val != NULL)
			{
				delete [] val;
			}
		}

		void set(char *s)
		{
			if(val != NULL)
			{
				delete [] val;
			}

			val = new char [ strlen(s) + 1 ];

			strcpy(val,s);
		}
	};


	struct CodeBlock
	{
		char inc[MAX];
		char op1[MAX];
		char op2[MAX];
		int  op_num;
		bool on;
		bool label_on;
		char label[MAX];

		CodeBlock()
		{
			on = false;
			label_on = false;
		}
	};

	// Sybmol Table
	class Program
	{
	public:
		Variable *var;
		int vsize;
		CodeBlock *code;
		int csize;
	
		Program()
		{
			var = 0;
			code = 0;
		}

		~Program()
		{
			if(var != 0)
			{
				delete [] var;
			}
		}

		void sizevar(int size)
		{
			var = new Variable[size];
			vsize = size;
		}

		void sizecode(int size)
		{
			code = new CodeBlock[size];
			csize = size;
		}

		int getoffvar()
		{
			for(int i = 0; i < vsize; i++)
			{
				if(var[i].on == false)
				{
					return i;
				}
			}
			return (-1);
		}

		int getvarbyname(char *name)
		{
			for(int i = 0; i < csize; i++)
			{
				if(strcmp(var[i].name,name) == 0)
				{
					return i;
				}
			}

			return (-1);
		}

		void addvar(char *name, char *val, int type)
		{
			int off = getoffvar();
			if(off != -1)
			{

			strcpy(var[off].name,name);
			var[off].set(val);
			var[off].on = true;
			var[off].type = type;

			}
		}

		int getoffcode()
		{
			for(int i = 0; i < csize; i++)
			{
				if(code[i].on == false)
				{
					return i;
				}
			}
			return -1;
		}
		
		void addcode(char *inc , char *op1, char *op2)
		{
			int off = getoffcode();
			if(off != -1)
			{
				strcpy(code[off].inc,inc);
				strcpy(code[off].op1,op1);
				strcpy(code[off].op2,op2);
				code[off].on = true;
				if(strlen(code[off].op2) == 0)
				{
					code[off].op_num = 1;
				}
				else
				{
					code[off].op_num = 2;
				}
			}
		}

		void addlabel(char *label)
		{
			int off = getoffcode();
			strcpy(code[off].label,label);
			code[off].on = true;
			code[off].label_on = true;
			
		}
	};

	Program prog;

	void getfname(char *str, char *name);
	bool isfile(const char *sfile);
	unsigned long filelen(const char *sfile);
	void readfile(const char *source, char *pfile);
	unsigned int quotesearch(unsigned int start, const char *source, const char *search);
	void assemble(char *source, char *output);
	void addvar(char *str);
	void addcode(char *str);
	void output(char *name, char *output);
	void printerrorf(const char *str, ...);
	void killspace(char *str);
	void lcase(char* str);
	void trimcom(char* str);
	int  focc(char *str, char c);
	void trimr(char *str);
	int  firstchar(char *str);
	int  isinc(char *inc);
	void check();
}


int main(int argc, char *argv[])
{
	if(argc != 3)
	{
		cout << "[invalid syntax]\nmasasm source.masasm output.exe\n" << endl;
		return (0);
	}

	char t[255];
	masasm::getfname(argv[0],t);
	strcpy(masasm::path,t);

	if(masasm::isfile(argv[1]))
	{
		if(mstrfind(argv[2],"\\") == -1)
		{
			char temp[255];
			char name[255];
			masasm::getfname(argv[0],name);
			strcpy(temp,name);
			strcat(temp,argv[2]);
			masasm::assemble(argv[1],temp);
		}
		else
		{
			masasm::assemble(argv[1],argv[2]);

		}
	}
	else
	{
		cout << "file " << argv[1] << " not found .. " << endl;
	}

	return (0);
}

void masasm::getfname(char *source, char *name)
{
	int pos;
	pos = mstrbfind(source,"\\") + 1;
	mstrleft(source,name,pos);
}

bool masasm::isfile(const char *sfile)
{
	FILE *file;
	file = fopen(sfile,"rb+");
	if(file == NULL)
	{
		return false;
	}
	fclose(file);
	return true;
}

unsigned long masasm::filelen(const char *sfile)
{
	unsigned long len = 0;
	if(isfile(sfile) == true)
	{

		FILE *file;
		file = fopen(sfile,"rb+");

		while(1)
		{
			char c = fgetc(file);
			if(feof(file))
			{
				break;
			}
			len++;
		}
	}
	else
	{
		return -1;
	}

	return len;
}

void masasm::readfile(const char *source, char* pfile)
{
	unsigned long pos = 0;
	FILE* file;
	
	file = fopen(source,"rb+");
	while(1)
	{
		char c = fgetc(file);
		if(feof(file))
		{
			break;
		}
		else
		{
			pfile[pos] = c;
			pos++;
		}
	}
	
	pfile[pos] = 0;
	
	fclose(file);
}

unsigned int masasm::quotesearch(unsigned int startx, const char *body, const char *search)
{
	int len = strlen(body);
	int len2 = strlen(search); // search len

	bool go = true;

	for(int i = startx+1; i < len; i++)
	{

		if(body[i] == '\"')
		{
			go = !go;
		}

		if(body[i] == search[0] && go == true)
		{
			bool ichk = true;

			for(int z = 0; z < len2; z++)
			{
				if(body[i+z] == search[z])
				{
				}
				else
				{
					ichk = false;
				}
			}

			if(ichk == true)
			{
				return i;
			}
		}
	}

	return -1; // failure
}


void masasm::assemble(char *source, char *output)
{
	char *code = new char [ filelen(source) + 1 ];

	readfile(source,code);
	lcase(code);
	trimcom(code);

	char *pcode = new char [ strlen(code) + 1 ];
	char *pvar = new char [ strlen(code) + 1 ];

	int bo,bc;
	bo = focc(code,'{');
	bc = focc(code,'}');
	if(bo != bc)
	{
		printerrorf(" { } blocks missalligned");
		goto exit;
	}

	int mas;
	mas = quotesearch(0,code,"mas");
	if(mas == -1)
	{
		printerrorf("mas block not found");
		goto exit;
	}
	int maso;
	maso = quotesearch(mas,code,"{");
	if(maso == -1)
	{
		printerrorf("mas opening brace ({) not found");
		goto exit;
	}

	char name[255];
	mstrmid(code,name,mas+3,maso);
	killspace(name);

	int var;
	var = quotesearch(0,code,"var");
	if(var == -1)
	{
		printerrorf("var block not found");
		goto exit;
	}
	int varo,varc;
	varo = quotesearch(var,code,"{");
	varc = quotesearch(varo,code,"}");

	if(varo == -1 || varc == -1)
	{
		printerrorf("var { or } not found");
		goto exit;
	}
	mstrmid(code,pvar,varo+1,varc);
	addvar(pvar);
	int begin;
	begin = quotesearch(0,code,"begin");
	int begino,beginc;
	begino = quotesearch(begin,code,"{");
	beginc = quotesearch(begino,code,"}");
	if( begin == -1 )
	{
		printerrorf(" begin block not found ");
		goto exit;
	}

	if(begino == -1 || beginc == -1)
	{
		printerrorf(" begin missing { or } ");
		goto exit;
	}
	mstrmid(code,pcode,begino+1,beginc);
	addcode(pcode);
 
exit:
	delete [] code;
	delete [] pvar;
	delete [] pcode;

	if(errors == 0)
	{
		masasm::output(name,output);
		cout << "assembled with (0) errors, executable outputed to " << output << endl;
		system("pause");
	}
	else
	{
		cout << " assembled with (" << errors << ") error(s) " << endl;
		system("pause");
	}
}

void masasm::output(char *name, char *output)
{
	char sourcename[255];
	sprintf(sourcename,"%s%s.c",path,name);
 	
	ofstream fout(sourcename);

	fout << "#define bool unsigned char\r\n#define true 1 \r\n#define false 0 \r\n#include<stdio.h>\r\n#include<stdlib.h>\r\n#include<string.h>\r\n";
	fout << "int main()\r\n{\r\n\r\nbool flags[25];\r\n\r\n\r\n";


	/* print out variables */
	for(int i = 0; i < prog.vsize; i++)
	{
		if(prog.var[i].on == true)
		{
			switch(prog.var[i].type)
			{
			case VAR_INTEGER:
				{

				fout << "int " << prog.var[i].name << " = " << prog.var[i].val << ";\r\n";
				break;

				}
			case VAR_STRING:
				{

				if(strlen(prog.var[i].val) == 0)
				{
					fout << "char " << prog.var[i].name << " [" << MAX << "];\r\n";
				}
				else
				{
					fout <<"char *" << prog.var[i].name << " = " << prog.var[i].val << ";\r\n";
				}

				break;

				}
			case VAR_FLOAT:
				{

				fout << "double " << prog.var[i].name << " = " << prog.var[i].val << ";\r\n";

				}
				break;

			}
		}
	}

	/* print out the code blocks */

	for(i = 0; i < prog.csize; i++)
	{
		if(prog.code[i].label_on == true)
		{
			fout << prog.code[i].label << "\r\n";
		}
		else
		{
			if(prog.code[i].on == true)
			{
				int inc = isinc(prog.code[i].inc);
				if(inc == -1)
				{
					printerrorf("invalid instruction [%s]", prog.code[i].inc);
					continue;
				}
				switch(inc)
				{
				case MOV:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);
 	
						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
								fout << "strcpy(" << prog.code[i].op1 << "," << prog.code[i].op2 << ");\r\n";
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " = " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case INC:
					{
						fout << prog.code[i].op1 << "++;\r\n";
					}
					break;
				case DEC:
					{
						fout << prog.code[i].op1 << "--;\r\n";
					}
					break;
				case ADD:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
								fout << "strcat(" << prog.code[i].op1 << "," << prog.code[i].op2 << ");\r\n";
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " += " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case SUB:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " -= " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case MUL:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " *= " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case DIV:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
						
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " /= " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case AND:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
					
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " & " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case OR:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
						
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " | " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case XOR:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
						
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " ^ " << prog.code[i].op2 << ";\r\n";
							}
							break;
						}
					}
					break;
				case NOT:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
					
							}
							break;
						case VAR_INTEGER:
						case VAR_FLOAT:
							{
								fout << prog.code[i].op1 << " =  ! " << prog.code[i].op1<< ";\r\n";
							}
							break;
						}
					}
					break;
				case PRINT:
					{
						if(mstrfind(prog.code[i].op1,"\"") != -1)
						{
							fout << "printf(" << prog.code[i].op1 << ");\r\n";

						}
						else
						{
							int v;
							v = prog.getvarbyname(prog.code[i].op1);

							if(v == -1)
							{
								printerrorf("invalid variable %s",prog.code[i].op1);
								continue;
							}


							switch(prog.var[v].type)
							{
							case VAR_STRING:
								{
									fout << "printf(" << prog.code[i].op1 <<");\r\n";
								}
								break;
							case VAR_FLOAT:
								{
									fout <<"printf(\"%d\"," << prog.code[i].op1 << ");\r\n";
								}
								break;
							case VAR_INTEGER:
								{
									fout <<"printf(\"%i\"," << prog.code[i].op1 << ");\r\n";
								}
								break;
							}

						
						}
					}
					break;
				case INPUT:
					{
						int v;
						v = prog.getvarbyname(prog.code[i].op1);

						switch(prog.var[v].type)
						{
						case VAR_STRING:
							{
								fout << "scanf(\"%s\"," << prog.code[i].op1 << ");\r\n";
							}
							break;
						case VAR_INTEGER:
							{
								fout << "scanf(\"%i\",&" << prog.code[i].op1 << ");\r\n";
							}
							break;
						case VAR_FLOAT:
							{
								fout << "scanf(\"%d\",&" << prog.code[i].op1 << ");\r\n";
							}
							break;
						}
					}
					break;
				case PAUSE:
					{
						fout << "system(\"pause\");\r\n";
					}
					break;
				case RETURN:
					{
						fout <<"return (0);\r\n";
					}
					break;
				case CMP:
					{

						fout << "\r\nflags[0] = false;";
						fout << "\r\nflags[1] = false;";
						fout << "\r\nflags[2] = false;";
						fout << "\r\nflags[3] = false;";
						fout << "\r\nflags[4] = false;";
						fout << "\r\nflags[5] = false;";
						fout << "\r\nflags[6] = false;\r\n";
					  	fout << "if(" << prog.code[i].op1 << " == " << prog.code[i].op2 << ")\r\n{";
						fout << "\r\nflags[0] = true;\r\n";
						fout << "}\r\n";
						fout <<"if(" << prog.code[i].op1 << " >  " << prog.code[i].op2 << ")\r\n{";
						fout <<"\r\nflags[1] = true;\r\n";
						fout <<"}\r\n";
						fout <<"if(" << prog.code[i].op1 << " >= " << prog.code[i].op2 << ")\r\n{";
						fout <<"\r\nflags[2] = true;\r\n";
						fout <<"}\r\n";
						fout <<"if(" << prog.code[i].op1 << " < " << prog.code[i].op2 << ")\r\n{";
						fout <<"\r\nflags[3] = true;\r\n";
						fout <<"}\r\n";
						fout <<"if(" << prog.code[i].op1 << " <= " << prog.code[i].op2 << ")\r\n{";
						fout <<"\r\nflags[4] = true;\r\n";
						fout <<"}\r\n";		
						fout <<"if(" << prog.code[i].op1 << " != " << prog.code[i].op2 << ")\r\n{";
						fout << "\r\nflags[5] = true;\r\n";
						fout << "}\r\n";
					}
					break;
					case JMP:
						{
							fout << "goto " << prog.code[i].op1 << ";\r\n";
						}
						break;
						//JE, JGE, JG, JL, JLE};
					case JNE:
						{
							fout <<" if(flags[5] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
					case JE:// jump equal
						{
							fout <<" if(flags[0] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
					case JGE:// jump >= 
						{
							fout <<" if(flags[2] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
					case JG:// jump >
						{
							fout <<" if(flags[1] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
					case JL: // jump lower 
						{
							fout <<" if(flags[3] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
					case JLE:// jump <=
						{
							fout <<" if(flags[4] == true )\r\n { \r\n goto " << prog.code[i].op1 << ";\r\n}\r\n\r\n";
						}
						break;
				}
			}
		}

	}

	fout << "\r\nreturn (0);\r\n}\r\n";
	fout.close();

	// shell gcc
	char shell[255];
	sprintf(shell,"bin\\gcc %s -o %s",sourcename,output);
	system(shell);
}

void masasm::addvar(char *str)
{
 	TokenizeQuotes token;
	token.tokenize(str,'\n');
	prog.sizevar(token.length);

	for(int i = 0; i < token.length; i++)
	{
		if(strlen(token[i]) > 3)
		{
			TokenizeQuotes vtoken;
			vtoken.tokenize(token[i],' ');

			if(vtoken.length > 1 )
			{

			if(strcmp(vtoken[0],"var&") == 0)
			{
				if(vtoken.length == 2)
				{
					trimr(vtoken[1]);
					prog.addvar(vtoken[1],"0",VAR_INTEGER);
					continue;
				}

				if(vtoken.length == 4 && strcmp(vtoken[2],":=") == 0)
				{
					trimr(vtoken[1]);
					trimr(vtoken[3]);
				 	prog.addvar(vtoken[1],vtoken[3],VAR_INTEGER);
				}
				else
				{
					printerrorf("invalid variable decleration");
				}

				continue;
			}

			if(strcmp(vtoken[0],"var$") == 0)
			{
				if(vtoken.length == 2)
				{
					if(vtoken.length == 2)
					{
						trimr(vtoken[1]);
						prog.addvar(vtoken[1],"",VAR_STRING);
						continue;
					}
				}

				if(vtoken.length == 4 && strcmp(vtoken[2],":=") == 0)
				{
					trimr(vtoken[1]);
					trimr(vtoken[3]);
					prog.addvar(vtoken[1],vtoken[3],VAR_STRING);
				}
				else
				{
					printerrorf("invalid variable decleration");
				}


				continue;

			}

			if(strcmp(vtoken[0],"var#") == 0)
			{
				if(vtoken.length == 2)
				{
					trimr(vtoken[1]);
					prog.addvar(vtoken[1],"0",VAR_FLOAT);
					continue;
				}

				if(vtoken.length == 4 && strcmp(vtoken[2],":=") == 0)
				{
					trimr(vtoken[1]);
					trimr(vtoken[3]);
					prog.addvar(vtoken[1],vtoken[3],VAR_FLOAT);
				}
				else
				{
					printerrorf("invalid variable decleration");
				}

				continue;
			}


			printerrorf("invalid variable decleration");


			}
			else
			{
				printerrorf("invalid variable decleration");
			}

		}
	}
}

void masasm::addcode(char *str)
{
	TokenizeQuotes token;
	token.tokenize(str,'\n');
	prog.sizecode(token.length);

	for(int i = 0; i < token.length; i++)
	{
		if(strlen(token[i]) > 3)
		{
			if(quotesearch(0,token[i],":") != -1)// label
			{
				trimr(token[i]);
				prog.addlabel(token[i]);
			 	continue;
			}
			else// instruction
			{
				int pos = firstchar(token[i]);
				int sp = quotesearch(pos,token[i]," ");

				if(sp == -1)
				{
					killspace(token[i]);
					prog.addcode(token[i],"","");
					continue;
				}

				char cinc[MAX];
				char cop1[MAX];
				char cop2[MAX];
				mstrmid(token[i],cinc,pos,sp);
				int com = quotesearch(sp,token[i],",");
				if(com == -1)
				{
					mstrmid(token[i],cop1,sp+1,strlen(token[i])-1);
					prog.addcode(cinc,cop1,"");
				}
				else
				{
					mstrmid(token[i],cop1,sp+1,com);
					mstrmid(token[i],cop2,com+1,strlen(token[i])-1);
					prog.addcode(cinc,cop1,cop2);
				}
				
			}
		}
	}

	check();
}

void masasm::printerrorf(const char *str, ...)
{
	va_list list; 
	char string[5000];
	va_start(list, str); 
	vsprintf((char*)string,str,list);
	va_end(list); 
	errors++;
	cout << "error(" << errors << ") " << string << endl;
}

void masasm::killspace(char *str)
{
	char *temp = new char [ strlen(str) + 1 ];
	int pos = 0;
	for(int i = 0; i < strlen(str); i++)
	{
		if(str[i] != ' ')
		{
			temp[pos] = str[i];
			pos++;
		}
	}

	temp[pos] = 0;
	strcpy(str,temp);
	delete [] temp;
}

void masasm::lcase(char *str)
{
	for(int i = 0; i < strlen(str); i++)
	{
		str[i] = tolower(str[i]);
	}
}

void masasm::trimcom(char *str)
{
	char* temp = new char [ mstrlen(str) + 1 ];
	int off_pos = 0;
	bool go = true;
	
	for(int i = 0; i < mstrlen(str); i++)
	{
		if( str[i] == ';' )
		{
			go = false;
		}
		
		if( str[i] == '\n' && go == false )
		{
			go = true;
		}
		
		if(go == true)
		{
			temp[off_pos] = str[i];
			off_pos++;
		}
	}
	
	temp[off_pos] = 0;
	strcpy(str,temp);
	delete [] temp;
	temp = 0;
}

int  masasm::focc(char *str, char c)
{
	int count = 0;

	for(int i = 0; i < strlen(str); i++)
	{
		if(str[i] == c)
		{
			count++;
		}
	}

	return count;
}

void masasm::trimr(char *str)
{
	char *temp = new char [ strlen(str) + 1 ];
	int off = 0;
	for(int i = 0; i < strlen(str); i++)
	{
		if(str[i] != '\n'  && str[i] != '\r')
		{
			temp[off] = str[i];
			off++;
		}
	}

	temp[off] = 0;
	strcpy(str,temp);
	delete [] temp;
}

int masasm::firstchar(char *str)
{
	for(int i = 0; i< strlen(str); i++)
	{
		if(str[i] != ' ')
		{
			return i;
		}
	}

	return (-1);
}

int masasm::isinc(char *inc)
{

	if(strcmp(inc,"mov") == 0)
	{
		return MOV;
	}

	if(strcmp(inc,"print") == 0)
	{

		return PRINT;
	}

	if(strcmp(inc,"input") == 0)
	{
		return INPUT;
	}

	if(strcmp(inc,"pause") == 0)
	{
		return PAUSE;
	}
	if(strcmp(inc,"return") == 0)
	{
		return RETURN;
	}

	if(strcmp(inc,"inc") == 0)
	{
		return INC;
	}

	if(strcmp(inc,"dec") == 0)
	{
		return DEC;
	}

	if(strcmp(inc,"add") == 0)
	{
		return ADD;
	}

	if(strcmp(inc,"sub") == 0)
	{
		return SUB;
	}

	if(strcmp(inc,"mul") == 0)
	{
		return MUL;
	}

	if(strcmp(inc,"div") == 0)
	{
		return DIV;
	}

	if(strcmp(inc,"and") == 0)
	{
		return AND;
	}

	if(strcmp(inc,"or") == 0)
	{

		return OR;
	}

	if(strcmp(inc,"xor") == 0)
	{
		return XOR;
	}

	if(strcmp(inc,"not") == 0)
	{
		return NOT;
	}

	if(strcmp(inc,"cmp") == 0)
	{
		return CMP;
	}

	if(strcmp(inc,"jmp") == 0)
	{
		return JMP;
	}

	if(strcmp(inc,"jne") == 0)
	{
		return JNE;
	}
	if(strcmp(inc,"je") == 0)
	{
		return JE;
	}
	if(strcmp(inc,"jge") == 0)
	{
		return JGE;
	}

	if(strcmp(inc,"jg") == 0)
	{
		return JG;
	}

	if(strcmp(inc,"jl") == 0)
	{
		return JL;
	}

	if(strcmp(inc,"jle") == 0)
	{
		return JLE;
	}

	return (-1);
}

void masasm::check()
{


}
