39 const QVector<QVector<QString>> &rawTable,
40 const QStringList &colHeaders,
41 const QVector<QPair<QString, QVector<QString>>> &sortedGrammar,
42 QWidget *parent =
nullptr)
45 setWindowTitle(tr(
"Ayuda interactiva: Tabla SLR(1)"));
52 int rows = rawTable.size();
53 int cols = colHeaders.size();
54 for (
int i = 0; i < rows; ++i) {
55 for (
int j = 0; j < cols; ++j) {
56 QString sym = colHeaders[j];
60 auto itAct = parser.
actions_.at(i).find(sym.toStdString());
62 = (itAct != parser.
actions_.at(i).end()
67 unsigned to = parser.
transitions_.at(i).at(sym.toStdString());
68 expected = QString(
"s%1").arg(to);
69 explanation = tr(
"Estado %1: existe transición δ(%1, '%2'). ¿A qué "
70 "estado harías shift?")
77 for (
int k = 0; k < sortedGrammar.size(); ++k) {
78 auto &rule = sortedGrammar[k];
85 expected = QString(
"r%1").arg(idx);
87 std::unordered_set<std::string>
F;
89 QStringList followList;
91 followList << QString::fromStdString(t);
92 explanation = tr(
"Estado %1: contiene el ítem [%2 → ...·] y '%3' ∈ "
93 "SIG(%2). ¿Qué regla usas para reducir (0, 1, ...)?")
101 explanation = tr(
"Estado %1: contiene [S → A · $]. ¿Qué palabra clave "
102 "usas para aceptar?")
111 auto nonT = sym.toStdString();
117 expected = QString::number(itGo->second);
118 explanation = tr(
"Estado %1: δ(%1, '%2') existe. ¿A qué estado va "
119 "la transición? (pon solo el número)")
133 last->setFinalPage(
true);
144 QVector<QString> result;
145 result.reserve(vec.size());
146 for (
const auto &str : vec) {
147 result.push_back(QString::fromStdString(str));
Implements an SLR(1) parser for context-free grammars.
Definition slr1_parser.hpp:20
action_table actions_
The action table used by the parser to determine shift/reduce actions.
Definition slr1_parser.hpp:292
Grammar gr_
The grammar being processed by the parser.
Definition slr1_parser.hpp:280
transition_table transitions_
The transition table used by the parser to determine state transitions.
Definition slr1_parser.hpp:296
@ Shift
Definition slr1_parser.hpp:33
@ Accept
Definition slr1_parser.hpp:33
@ Empty
Definition slr1_parser.hpp:33
@ Reduce
Definition slr1_parser.hpp:33
std::unordered_set< std::string > Follow(const std::string &arg)
Computes the FOLLOW set for a given non-terminal symbol in the grammar.
Definition slr1_parser.cpp:352
A single step in the SLR(1) guided assistant for table construction.
Definition slrwizardpage.h:22
SLRWizard(SLR1Parser &parser, const QVector< QVector< QString > > &rawTable, const QStringList &colHeaders, const QVector< QPair< QString, QVector< QString > > > &sortedGrammar, QWidget *parent=nullptr)
Constructs the SLR(1) wizard with all necessary parsing context.
Definition slrwizard.h:38
QVector< QString > stdVectorToQVector(const std::vector< std::string > &vec)
Converts a std::vector<std::string> to QVector<QString> for UI compatibility.
Definition slrwizard.h:142
@ F
Definition slrtutorwindow.h:51
SymbolTable st_
Symbol table of the grammar.
Definition grammar.hpp:118
std::string antecedent_
The non-terminal on the left-hand side of the production.
Definition lr0_item.hpp:18
std::vector< std::string > consequent_
The sequence of symbols on the right-hand side of the production.
Definition lr0_item.hpp:23
Definition slr1_parser.hpp:46
const Lr0Item * item
Definition slr1_parser.hpp:47
Action action
Definition slr1_parser.hpp:48
std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:32
std::unordered_set< std::string > terminals_
Set of all terminal symbols (including EOL).
Definition symbol_table.hpp:42