#include "Lexer.h" Lexer::Lexer() { string keys[] = {"function", "class", "for", "while", "if", "else"}; keywords.assign(keys, keys+6); char punct[] = {'.', ',', ';', '{', '}', '[', ']', '(', ')'}; punctuation.assign(punct, punct+9); string oper[] = {"<", ">", "+", "-", "/", "*", "%", "&", "|", "=", ":", "==", "+=", "-=", "<=", ">=", "!=", "&&", "||"}; operators.assign(oper, oper +19); } Lexer::~Lexer() { //dtor } void Lexer::add_keyword(string word) { if(!is_keyword(word)) { keywords.push_back(word); } } void Lexer::add_punctuation_char(char c) { if(!is_punctuation(c)) { punctuation.push_back(c); } } void Lexer::add_operator(string oper) { if(!is_operator(oper)) { operators.push_back(oper); } } vector Lexer::parse_line(string line) { vector tokens; while(line != "") { pair result_of_parsing = parse_token(line); line = result_of_parsing.first; Token token = result_of_parsing.second; if(token.get_value() != "") { tokens.push_back(token); } } return tokens; } pair Lexer::parse_token(string line) { string token_value = ""; unsigned int i; bool in_char_literal = false; for(i=0; i< line.size(); i++) { if(token_value == "" && isspace(line[i])) continue; if(isalnum(line[i]) || line[i] == '\"' || line[i]== '_') { token_value += line[i]; if(line[i] == '\"') { if(in_char_literal) { in_char_literal = false; } else in_char_literal = true; } } else if(ispunct(line[i])) { if(token_value=="") { token_value=line[i]; i++; if(i