Assembler (#6)

Co-authored-by: Andre Wagner <WagnerAndre@JohnDeere.com>
Reviewed-on: https://192.168.5.48/andre/tyche/pulls/6
This commit was merged in pull request #6.
This commit is contained in:
2026-05-01 10:12:41 -05:00
parent b835dbb36e
commit a1aed4988a
13 changed files with 499 additions and 6 deletions

45
src/assembler/lexer.hh Normal file
View File

@@ -0,0 +1,45 @@
#ifndef TYCHE_LEXER_HH
#define TYCHE_LEXER_HH
#include <string>
#include <utility>
#include <variant>
namespace tyche::as {
enum class TokenType {
BOF, Directive, Instruction, Integer, Float, String, Enter, Colon, EOF_
};
using TokenValue = std::variant<std::monostate, int, float, std::string>;
struct Token {
TokenType type;
TokenValue token = std::monostate();
size_t line = 0;
size_t column = 0;
friend bool operator==(Token const& lhs, Token const& rhs) { return std::tie(lhs.type, lhs.token) == std::tie(rhs.type, rhs.token); }
};
std::string token_type_name(TokenType type);
class Lexer {
public:
explicit Lexer(std::string source) : source_(std::move(source)) { reset(); }
void reset();
[[nodiscard]] Token peek() const;
[[nodiscard]] Token ingest();
private:
const std::string source_;
size_t pos_ = 0;
Token current_token_ { TokenType::BOF };
void ingest_next_token();
};
} // tyche
#endif //TYCHE_LEXER_HH