implemented lexer for a more complex subset of the
monkey language
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "type.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace token {
|
||||
|
||||
// Array mapping enum values to their string representations
|
||||
@@ -18,4 +21,17 @@ namespace token {
|
||||
return os << "Unknown";
|
||||
}
|
||||
|
||||
static std::unordered_map<std::string, type> keywords{
|
||||
{"fn", type::FUNCTION},
|
||||
{"let", type::LET},
|
||||
};
|
||||
|
||||
type lookup_identifier(std::string ident) {
|
||||
try {
|
||||
return keywords.at(ident);
|
||||
} catch (const std::out_of_range&) {
|
||||
return type::IDENTIFIER;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace token
|
||||
|
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <ostream>
|
||||
#include <string_view>
|
||||
|
||||
namespace token {
|
||||
|
||||
@@ -30,5 +28,6 @@ namespace token {
|
||||
#undef X
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, type type);
|
||||
std::ostream& operator<<(std::ostream&, type);
|
||||
type lookup_identifier(std::string);
|
||||
} // namespace token
|
||||
|
Reference in New Issue
Block a user