#include "Token.h" #include "../Exception.h" #include #include "TokenType.h" Token::Token(TokenType type, int line) : type(type) { this->line = line; f = 0.0f; s = ""; } Token::~Token() { } void Token::setFloat(float f) { if(type != Tokens::FLOAT) { throw Exception("token contains no float"); } this->f = f; } void Token::setString(string s) { if(type != Tokens::TEXT && type != Tokens::LABEL && type != Tokens::VAR) { throw Exception("token contains no string"); } this->s.assign(s); } float Token::getFloat() const { return f; } bool Token::getBool() const { if(type == Tokens::TRUE) { return true; } return false; } string Token::getString() const { return s; } int Token::getLine() const { return line; } TokenType Token::getType() const { return type; } std::ostream& operator<<(std::ostream& stream, const Token& t) { stream << t.getLine() << " "; stream << t.getType(); string s = t.getString(); if(s.size() != 0) { stream << "(\"" << s << "\")"; } if(t.getType() == Tokens::FLOAT) { stream << '(' << t.getFloat() << ')'; } return stream; }