12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "Token.h"
- #include "Exception.h"
- #include <iostream>
- #include "TokenType.h"
- Token::Token(Tokens::Type type, int line)
- {
- this->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;
- }
- Tokens::Type 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;
- }
|