diff --git a/Monicelli.lpp b/Monicelli.lpp index 1e189c8..f60c81f 100644 --- a/Monicelli.lpp +++ b/Monicelli.lpp @@ -22,7 +22,6 @@ #include "Parser.hpp" #include -#include static void meta(const char *); @@ -191,9 +190,16 @@ CHAR [a-zA-Z_] return token::ID; } -{DIGIT}+ { - lval->intval = strtol(yytext, NULL, 10); - return token::NUMBER; +[-+]?(({DIGIT}*".")?{DIGIT}+|{DIGIT}+".")([eE][-+]?{DIGIT}+)? { + std::string value(yytext); + + if (value.find(".") != std::string::npos) { + lval->floatval = std::stod(value); + return token::FLOAT; + } else { + lval->intval = std::stol(value); + return token::NUMBER; + } } . { diff --git a/examples/float.mc b/examples/float.mc new file mode 100644 index 0000000..12389c9 --- /dev/null +++ b/examples/float.mc @@ -0,0 +1,12 @@ +# Test all possible numerical forms (integer and float) + +Lei ha clacsonato + +2.0 a posterdati +-2.0 a posterdati +2. a posterdati +.232 a posterdati +-2 a posterdati +-.2233 a posterdati ++2 a posterdati ++2.233e-23 a posterdati