]> www.ginac.de Git - ginac.git/blobdiff - ginac/parser/lexer.cpp
Parser can parse (some) floating point numbers now.
[ginac.git] / ginac / parser / lexer.cpp
index 894a2ad8afeef8ae484eca01274290dc00074815..7c3e6c84aecf5ac6d62db29452de77f981791a95 100644 (file)
@@ -35,13 +35,23 @@ int lexer::gettok()
                        return token_type::identifier;
        }
 
                        return token_type::identifier;
        }
 
-       // Number: [0-9.]+
+       // Number: [0-9]+([.][0-9]*(eE[+-][0-9]+)*)*
        if (isdigit(c) || c == '.') {
                str = "";
                do {
                        str += c;
                        c = input->get();
                } while (isdigit(c) || c == '.');
        if (isdigit(c) || c == '.') {
                str = "";
                do {
                        str += c;
                        c = input->get();
                } while (isdigit(c) || c == '.');
+               if (c == 'E' || c == 'e') {
+                       str += 'E';
+                       c = input->get();
+                       if (isdigit(c))
+                               str += '+';
+                       do {
+                               str += c;
+                               c = input->get();
+                       } while (isdigit(c));
+               }
                return token_type::number;
        }
 
                return token_type::number;
        }
 
@@ -129,5 +139,19 @@ void lexer::switch_input(std::istream* in)
        c = ' ';
 }
 
        c = ' ';
 }
 
+/// Symbolic name of current token (for error reporting)
+std::string lexer::tok2str(const int tok) const
+{
+       switch (tok) {
+               case lexer::token_type::identifier:
+               case lexer::token_type::number:
+                       return std::string("\"") + str + "\"";
+               case lexer::token_type::eof:
+                       return std::string("EOF");
+               default:
+                       return std::string("\"") + char(tok) + "\"";
+       }
+}
+
 } // namespace GiNaC
 
 } // namespace GiNaC