#include #include #include "Lexer.h" using namespace std; char Lexer::nextChar() const { if (pos < str.size()) return str[pos]; return 0; } char Lexer::getChar() { if (pos < str.size()) return str[pos++]; return 0; } void Lexer::skipChar() { pos++; } void Lexer::skipWhiteSpace() { if (pos < str.size() && isblank(str[pos])) pos++; } void Lexer::nextToken() { token.clear(); type = nothing; skipWhiteSpace(); char f = getChar(); if (f != 0) { token += f; if (isdigit(f)) { // token is number type = integer; // assume "integer" // number f = nextChar(); while (isdigit(f) || f == '.') { if (f == '.') { type = floatingpoint; // -> floating point } token += f; skipChar(); f = nextChar(); } } else if (f == '"') { // string literal starting with '"' char delimiter = f; token = "\""; type = stringliteral; f = nextChar(); while (f != delimiter) { if (f == 0) throw Exception("Parsing", "string literal not complete"); token += f; skipChar(); f = nextChar(); } token += '"'; skipChar(); } else if (isalpha(f)) { // cout << "id"<