From 2bc017d0bb0569dda4d68e627190db5db5bc405e Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Sun, 30 Nov 2014 13:19:19 +0100 Subject: [PATCH] Allow floating point literals with exponent and without decimal part. --- Monicelli.lpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Monicelli.lpp b/Monicelli.lpp index f60c81f..e79dd0b 100644 --- a/Monicelli.lpp +++ b/Monicelli.lpp @@ -29,6 +29,12 @@ using namespace monicelli; typedef Parser::token token; #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++ @@ -193,7 +199,7 @@ CHAR [a-zA-Z_] [-+]?(({DIGIT}*".")?{DIGIT}+|{DIGIT}+".")([eE][-+]?{DIGIT}+)? { std::string value(yytext); - if (value.find(".") != std::string::npos) { + if (in(".", value) || in("e", value) || in("E", value)) { lval->floatval = std::stod(value); return token::FLOAT; } else {