2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2015-10-19 01:44:00 +08:00
|
|
|
#include <ostream>
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
struct Token
|
|
|
|
{
|
|
|
|
unsigned long id;
|
|
|
|
std::string value;
|
2015-10-19 01:44:00 +08:00
|
|
|
|
2016-02-03 07:18:20 +08:00
|
|
|
/*
|
|
|
|
* Token is "True" if it's id is bigger than zero. Because
|
|
|
|
* lexer ids are all bigger than zero.
|
|
|
|
*
|
|
|
|
* This object could be used in while loop as a condition.
|
|
|
|
* E.g.:
|
|
|
|
* while (auto token = ...)
|
|
|
|
* {
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return id > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ostream operator
|
|
|
|
*
|
|
|
|
* Prints token id and value in single line.
|
|
|
|
*/
|
2015-10-19 01:44:00 +08:00
|
|
|
friend std::ostream& operator<<(std::ostream& stream, const Token& token)
|
|
|
|
{
|
|
|
|
return stream << "TOKEN id = " << token.id
|
|
|
|
<< ", value = '" << token.value << "'";
|
|
|
|
}
|
2015-08-30 07:12:46 +08:00
|
|
|
};
|