if(isdigit(literal->token[0]))
{
// TODO have the tokenizer return the type of the token
- if(isnumrc(literal->token))
- literal->value = lexical_cast<int>(literal->token);
- else
+ if(literal->token.back()=='f')
+ literal->value = lexical_cast<float>(literal->token.substr(0, literal->token.size()-1));
+ else if(literal->token.find('.')!=string::npos)
literal->value = lexical_cast<float>(literal->token);
+ else
+ literal->value = lexical_cast<int>(literal->token);
}
else if(literal->token=="true" || literal->token=="false")
literal->value = (literal->token=="true");
}
bool require_digit = false;
- if(iter!=source_end && (*iter=='e' || *iter=='E'))
+ if(iter==source_end)
+ ;
+ else if(*iter=='e' || *iter=='E')
{
number += *iter++;
if(iter!=source_end && (*iter=='-' || *iter=='+'))
else
break;
}
+ if(!require_digit && iter!=source_end && *iter=='f')
+ number += *iter++;
}
+ else if(*iter=='f')
+ number += *iter++;
if(require_digit)
throw syntax_error(location, number, "Incomplete numeric literal");
- else if(isalnum(*iter) || *iter=='_')
+ else if(iter!=source_end && (isalnum(*iter) || *iter=='_'))
throw syntax_error(location, number, "Garbage at end of numeric literal");
return number;