3#include <unordered_map>
7enum symbol_type { NO_TERMINAL, TERMINAL, META };
10 using TokenID =
unsigned long;
12 inline static TokenID INVALID_TOKEN{0};
13 inline static TokenID EOF_ID{1};
14 inline static TokenID EPSILON_ID{2};
16 inline static TokenID next_id_{3};
19 inline static std::string
EOF_{
"<<EOF>>"};
23 inline static std::string
EPSILON_{
"<<EPSILON>>"};
26 inline static std::vector<std::pair<symbol_type, std::string>>
st_{
33 inline static std::unordered_map<std::string, TokenID>
lookup_{
40 inline static std::vector<TokenID>
order_{EOF_ID};
51 static void PutSymbol(
const std::string& identifier,
52 const std::string& regex);
59 static void PutSymbol(
const std::string& identifier);
67 static bool In(TokenID
id);
69 static bool In(
const std::string& identifier);
85 static std::string
GetValue(TokenID
id);
88 static const std::string&
ToString(TokenID
id);
91 static TokenID
ToID(
const std::string& identifier);
Definition symbol_table.hpp:9
static bool In(TokenID id)
Checks if a symbol exists in the symbol table.
Definition symbol_table.cpp:47
static std::vector< TokenID > order_
Tracks insertion order of terminal token types.
Definition symbol_table.hpp:40
static void PutSymbol(const std::string &identifier, const std::string ®ex)
Adds a terminal symbol with its associated regex to the symbol table.
Definition symbol_table.cpp:7
static std::unordered_map< std::string, TokenID > lookup_
Mapping from identifier to token ID.
Definition symbol_table.hpp:33
static std::string EOF_
End-of-line symbol used in parsing, initialized as "EOF".
Definition symbol_table.hpp:19
static TokenID ToID(const std::string &identifier)
Retrieve the token ID for a given identifier string.
Definition symbol_table.cpp:62
static std::string GetValue(TokenID id)
Retrieves the regex pattern for a terminal symbol.
Definition symbol_table.cpp:29
static std::vector< std::string > names_
Reverse mapping from token ID to identifier.
Definition symbol_table.hpp:37
static std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:23
static void Debug()
Prints all symbols and their properties in the symbol table.
Definition symbol_table.cpp:35
static std::vector< std::pair< symbol_type, std::string > > st_
Symbol table indexed by token ID storing type and regex.
Definition symbol_table.hpp:26
static bool IsTerminal(TokenID id)
Checks if a symbol is a terminal.
Definition symbol_table.cpp:69
static const std::string & ToString(TokenID id)
Convert a token ID to its identifier string.
Definition symbol_table.cpp:55