#include "bnf.h" #include "lexer.h" #include "grammer.h" #include "minicc.h" #include #include #include #include #include #include #include #include #include #include using namespace std::string_literals; std::vector split(std::string s) { std::vector result; boost::algorithm::split(result, s, boost::algorithm::is_any_of(s), boost::algorithm::token_compress_on); while (result.size() > 0 && result.back() == ""s) result.pop_back(); return result; } bool operator==(const Location &a, const Location &b) { return (a.line == b.line && a.column == b.column); } bool operator==(const Token &a, const Token &b) { return (a.type == b.type && a.value == b.value && a.location == b.location); } std::ostream& operator<<(std::ostream& os, const Token& token) { return os << token.type << ": " << token.value << "(" << token.location.line << ":" << token.location.column << ")"; } void Location::advance(bool newline) { pos++; if (newline) { line++; column = 1; } else { column++; } } std::string Location::toString() const { return std::to_string(line) + ":"s + std::to_string(column); } std::string Token::toString() const { return location.toString() + ": "s + value + " ("s + type + ")"s; } std::string demangle(const std::type_info& type) { return boost::core::demangle(type.name()); } std::vector to_little_endian(uint32_t value) { std::vector result(size_t(4)); *(reinterpret_cast(result.data())) = boost::endian::native_to_little(value); return result; } uint32_t from_little_endian(const std::vector& value) { return boost::endian::little_to_native(*(reinterpret_cast(value.data()))); }