X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fparser%2Flexer.cpp;h=7c3e6c84aecf5ac6d62db29452de77f981791a95;hp=ed1f894fea381bdc9c553d9a2811ff12b1697bcb;hb=3324b2f0f035490940b1a9d7cf5dc210776f6d87;hpb=1222eac51cee964961d2aad889dc4ceccb144a36;ds=sidebyside diff --git a/ginac/parser/lexer.cpp b/ginac/parser/lexer.cpp index ed1f894f..7c3e6c84 100644 --- a/ginac/parser/lexer.cpp +++ b/ginac/parser/lexer.cpp @@ -35,13 +35,23 @@ int lexer::gettok() 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 (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; } @@ -126,6 +136,21 @@ void lexer::switch_input(std::istream* in) input = in; line_num = 0; column = 0; + 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