I came up with the following function.
Is there any memory-leak effects or something else I've overlooked ?
//Here Keyword, Identifier, Operator, Literal and Punctuator are sub classes of token .
Code:
token* token_factory(std::string& input)
{
token* t;
if(is_keyword(input))
{
//type=keyword;
t = new Keyword(input);
}
else if(isalpha(input[0]))
{
t = new Identifier (input);
//type=identifier;
}
else if(is_operator(input))
{
t = new Operator(input);
//type=op;
}
else if(isdigit(input[0])||input[0]=='"'||input[0]=='\'')
{
t = new Literal(input);
//type=literal;
}
else if(is_punctuator(input))
{
t = new Punctuator(input);
//type = punctuator;
}
else throw(std::string("Unsupported Token: "+input));
return t;
}