LL1Checker 3.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 };
8
11 inline static std::string EOL_{"$"};
12
15 inline static std::string EPSILON_{"EPSILON"};
16
19 inline static std::unordered_map<std::string,
20 std::pair<symbol_type, std::string>>
21 st_{{EOL_, {TERMINAL, EOL_}}, {EPSILON_, {TERMINAL, EPSILON_}}};
22
24 inline static std::unordered_map<std::string, unsigned long> token_types_{
25 {EOL_, 1}};
26
28 inline static std::unordered_map<unsigned long, std::string> token_types_r_{
29 {1, EOL_}};
30
32 inline static std::vector<unsigned long> order_{1};
33
35 inline static unsigned long i_{2};
36
46 static void PutSymbol(const std::string& identifier,
47 const std::string& regex);
48
54 static void PutSymbol(const std::string& identifier);
55
62 static bool In(const std::string& s);
63
70 static bool IsTerminal(const std::string& s);
71
78 static std::string GetValue(const std::string& terminal);
79
85 static void Debug();
86
92 static void SetEol(const std::string& eol);
93};
Definition symbol_table.hpp:9
static std::string GetValue(const std::string &terminal)
Retrieves the regex pattern for a terminal symbol.
Definition symbol_table.cpp:18
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:6
static std::unordered_map< unsigned long, std::string > token_types_r_
Reverse mapping from integer token IDs back to symbols.
Definition symbol_table.hpp:28
static std::unordered_map< std::string, std::pair< symbol_type, std::string > > st_
Main symbol table, mapping identifiers to a pair of symbol type and its regex.
Definition symbol_table.hpp:21
static unsigned long i_
Current index for assigning new token IDs, starting from 2.
Definition symbol_table.hpp:35
static bool IsTerminal(const std::string &s)
Checks if a symbol is a terminal.
Definition symbol_table.cpp:34
static bool In(const std::string &s)
Checks if a symbol exists in the symbol table.
Definition symbol_table.cpp:30
static std::vector< unsigned long > order_
Tracks insertion order of token types.
Definition symbol_table.hpp:32
static std::unordered_map< std::string, unsigned long > token_types_
Token types, mapping each symbol to a unique integer ID.
Definition symbol_table.hpp:24
static std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:15
static std::string EOL_
End-of-line symbol used in parsing, initialized as "$".
Definition symbol_table.hpp:11
static void Debug()
Prints all symbols and their properties in the symbol table.
Definition symbol_table.cpp:22
static void SetEol(const std::string &eol)
Sets the end-of-line symbol.
Definition symbol_table.cpp:38