// Lexical Analyzer 1
// By DreamVB 1:19 PM 29-Sep-16

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;
using std::cout;
using std::endl;

string expression = "";
int pos = 0;

vector<string>tokens;

bool IsWhite(char c){
	switch(c){
	case '\ ':
	case '\r':
	case '\n':
	case '\t':
		return true;
	}
	return false;
}

bool IsOp(char c){
	switch(c){
	case '+':
	case '-':
	case '/':
	case '*':
	case '(':
	case ')':
	case ';':
		return true;
	}
	return false;
}

void GetTokens(){
	string tok = "";

	while(pos < expression.length()){

		//Eat white space
		while(IsWhite(expression[pos])){
			pos++;
		}

		//Scan digits
		if(isdigit(expression[pos])){
			while(isdigit(expression[pos])){
				tok+=expression[pos];
				pos++;
			}
			tokens.push_back(tok);
			tok.clear();
		//Scan operators
		}else if(IsOp(expression[pos])){
			tok = expression[pos];
			tokens.push_back(tok);
			tok.clear();
			pos++;
		}
		//Scan alpha
		else if(isalpha(expression[pos])){
			while(isalpha(expression[pos])){
				tok+=expression[pos];
				pos++;
			}
			tokens.push_back(tok);
			tok.clear();
		}
		else{
			break;
		}
		//pos++;
		//Inc counter
	}
}

int main(int argc, char *argv[]){
	string sToken = "";
	int count = 0;

	//Expression to scan
	expression = "Echo ((20 + 16 * (10+6) + A / Log(10/2));";

	//Scan tokens
	GetTokens();
	//Output tokens

	for(std::vector<string>::iterator it = tokens.begin(); it != tokens.end();it++){
		cout << "Token = " << *it << endl;
	}


	system("pause");
	return 0;
}