LL1Checker 5.0
“Tool for verifying LL(1) grammars and validating input strings.”
Loading...
Searching...
No Matches
symbol_table.hpp
1#pragma once
2#include <string>
3#include <unordered_map>
4#include <utility>
5#include <vector>
6
7enum symbol_type { NO_TERMINAL, TERMINAL, META };
8
10 using TokenID = unsigned long;
11
12 inline static TokenID INVALID_TOKEN{0};
13 inline static TokenID EOF_ID{1};
14 inline static TokenID EPSILON_ID{2};
15
16 inline static TokenID next_id_{3};
17
19 inline static std::string EOF_{"<<EOF>>"};
20
23 inline static std::string EPSILON_{"<<EPSILON>>"};
24
26 inline static std::vector<std::pair<symbol_type, std::string>> st_{
27 {META, ""}, // 0 - INVALID
28 {TERMINAL, ""}, // 1 - <<EOF>>
29 {META, ""}, // 2 - <<EPSILON>>
30 };
31
33 inline static std::unordered_map<std::string, TokenID> lookup_{
34 {EOF_, EOF_ID}, {EPSILON_, EPSILON_ID}};
35
37 inline static std::vector<std::string> names_{"", EOF_, EPSILON_};
38
40 inline static std::vector<TokenID> order_{EOF_ID};
41
51 static void PutSymbol(const std::string& identifier,
52 const std::string& regex);
53
59 static void PutSymbol(const std::string& identifier);
60
67 static bool In(TokenID id);
68
69 static bool In(const std::string& identifier);
70
77 static bool IsTerminal(TokenID id);
78
85 static std::string GetValue(TokenID id);
86
88 static const std::string& ToString(TokenID id);
89
91 static TokenID ToID(const std::string& identifier);
92
98 static void Debug();
99};
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 &regex)
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