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/*
2 * SyntaxTutor - Interactive Tutorial About Syntax Analyzers
3 * Copyright (C) 2025 Jose R. (jose-rzm)
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20#include <string>
21#include <unordered_map>
22#include <unordered_set>
23#include <utility>
24#include <vector>
25
34
47 std::string EOL_{"$"};
48
51 std::string EPSILON_{"EPSILON"};
52
55 std::unordered_map<std::string, symbol_type> st_{
57
61 std::unordered_set<std::string> terminals_{EOL_};
62
66 std::unordered_set<std::string> terminals_wtho_eol_{};
67
71 std::unordered_set<std::string> non_terminals_;
72
79 void PutSymbol(const std::string& identifier, bool isTerminal);
80
87 bool In(const std::string& s) const;
88
95 bool IsTerminal(const std::string& s) const;
96
103 bool IsTerminalWthoEol(const std::string& s) const;
104};
Stores and manages grammar symbols, including their classification and special markers.
Definition symbol_table.hpp:45
bool IsTerminal(const std::string &s) const
Checks if a symbol is a terminal.
Definition symbol_table.cpp:39
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:55
bool IsTerminalWthoEol(const std::string &s) const
Checks if a symbol is a terminal excluding EOL.
Definition symbol_table.cpp:43
bool In(const std::string &s) const
Checks if a symbol exists in the symbol table.
Definition symbol_table.cpp:35
std::string EOL_
End-of-line symbol used in parsing, initialized as "$".
Definition symbol_table.hpp:47
std::unordered_set< std::string > terminals_wtho_eol_
Set of terminal symbols excluding the EOL symbol ($).
Definition symbol_table.hpp:66
void PutSymbol(const std::string &identifier, bool isTerminal)
Adds a non-terminal symbol to the symbol table.
Definition symbol_table.cpp:23
std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:51
std::unordered_set< std::string > non_terminals_
Set of all non-terminal symbols.
Definition symbol_table.hpp:71
std::unordered_set< std::string > terminals_
Set of all terminal symbols (including EOL).
Definition symbol_table.hpp:61
symbol_type
Represents the type of a grammar symbol.
Definition symbol_table.hpp:33
@ TERMINAL
Definition symbol_table.hpp:33
@ NO_TERMINAL
Definition symbol_table.hpp:33