SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
 
Loading...
Searching...
No Matches
symbol_table.hpp
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <unordered_map>
4#include <unordered_set>
5#include <utility>
6#include <vector>
7
16
28 std::string EOL_{"$"};
29
32 std::string EPSILON_{"EPSILON"};
33
36 std::unordered_map<std::string, symbol_type> st_{{EOL_, symbol_type::TERMINAL},
38
42 std::unordered_set<std::string> terminals_{EOL_};
43
47 std::unordered_set<std::string> terminals_wtho_eol_{};
48
52 std::unordered_set<std::string> non_terminals_;
53
60 void PutSymbol(const std::string& identifier, bool isTerminal);
61
68 bool In(const std::string& s) const;
69
76 bool IsTerminal(const std::string& s) const;
77
84 bool IsTerminalWthoEol(const std::string& s) const;
85};
Stores and manages grammar symbols, including their classification and special markers.
Definition symbol_table.hpp:26
bool IsTerminal(const std::string &s) const
Checks if a symbol is a terminal.
Definition symbol_table.cpp:21
std::unordered_map< std::string, symbol_type > st_
Main symbol table, mapping identifiers to a pair of symbol type and its regex.
Definition symbol_table.hpp:36
bool IsTerminalWthoEol(const std::string &s) const
Checks if a symbol is a terminal excluding EOL.
Definition symbol_table.cpp:25
bool In(const std::string &s) const
Checks if a symbol exists in the symbol table.
Definition symbol_table.cpp:17
std::string EOL_
End-of-line symbol used in parsing, initialized as "$".
Definition symbol_table.hpp:28
std::unordered_set< std::string > terminals_wtho_eol_
Set of terminal symbols excluding the EOL symbol ($).
Definition symbol_table.hpp:47
void PutSymbol(const std::string &identifier, bool isTerminal)
Adds a non-terminal symbol to the symbol table.
Definition symbol_table.cpp:5
std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:32
std::unordered_set< std::string > non_terminals_
Set of all non-terminal symbols.
Definition symbol_table.hpp:52
std::unordered_set< std::string > terminals_
Set of all terminal symbols (including EOL).
Definition symbol_table.hpp:42
symbol_type
Represents the type of a grammar symbol.
Definition symbol_table.hpp:15
@ TERMINAL
Definition symbol_table.hpp:15
@ NO_TERMINAL
Definition symbol_table.hpp:15