Allow floating point literals with exponent and without decimal part.

This commit is contained in:
Stefano Sanfilippo 2014-11-30 13:19:19 +01:00
parent a6954b6ff7
commit 2bc017d0bb

View File

@ -29,6 +29,12 @@ using namespace monicelli;
typedef Parser::token token; typedef Parser::token token;
#define YY_USER_ACTION location->begin.columns(yyleng); #define YY_USER_ACTION location->begin.columns(yyleng);
inline
bool in(const char *sub, const std::string &str) {
return str.find(sub) != std::string::npos;
}
%} %}
%option ecs stack warn c++ %option ecs stack warn c++
@ -193,7 +199,7 @@ CHAR [a-zA-Z_]
[-+]?(({DIGIT}*".")?{DIGIT}+|{DIGIT}+".")([eE][-+]?{DIGIT}+)? { [-+]?(({DIGIT}*".")?{DIGIT}+|{DIGIT}+".")([eE][-+]?{DIGIT}+)? {
std::string value(yytext); std::string value(yytext);
if (value.find(".") != std::string::npos) { if (in(".", value) || in("e", value) || in("E", value)) {
lval->floatval = std::stod(value); lval->floatval = std::stod(value);
return token::FLOAT; return token::FLOAT;
} else { } else {