60 const QStringList& colHeaders,
61 const QVector<QPair<QString, QVector<QString>>>& sortedGrammar,
62 QWidget* parent =
nullptr)
64 setWindowTitle(tr(
"Ayuda interactiva: Tabla SLR(1)"));
72 int rows = rawTable.size();
73 int cols = colHeaders.size();
74 for (
int i = 0; i < rows; ++i) {
75 for (
int j = 0; j < cols; ++j) {
76 QString sym = colHeaders[j];
80 auto itAct = parser.
actions_.at(i).find(sym.toStdString());
82 (itAct != parser.
actions_.at(i).end()
85 SLR1Parser::Action::Empty});
90 expected = QString(
"s%1").arg(to);
91 explanation = tr(
"Estado %1: existe transición δ(%1, "
93 "estado harías shift?")
100 for (
int k = 0; k < sortedGrammar.size(); ++k) {
101 auto& rule = sortedGrammar[k];
102 if (rule.first.toStdString() ==
110 expected = QString(
"r%1").arg(idx);
112 std::unordered_set<std::string>
F;
114 QStringList followList;
116 followList << QString::fromStdString(t);
117 explanation = tr(
"Estado %1: contiene el ítem [%2 → "
119 "SIG(%2). ¿Qué regla usas para "
120 "reducir (0, 1, ...)?")
122 .arg(QString::fromStdString(
129 explanation = tr(
"Estado %1: contiene [S → A · $]. "
130 "¿Qué palabra clave "
131 "usas para aceptar?")
140 auto nonT = sym.toStdString();
146 expected = QString::number(itGo->second);
147 explanation = tr(
"Estado %1: δ(%1, '%2') existe. ¿A "
149 "la transición? (pon solo el número)")
164 last->setFinalPage(
true);
175 QVector<QString> result;
176 result.reserve(vec.size());
177 for (
const auto& str : vec) {
178 result.push_back(QString::fromStdString(str));
Implements an SLR(1) parser for context-free grammars.
Definition slr1_parser.hpp:38
action_table actions_
The action table used by the parser to determine shift/reduce actions.
Definition slr1_parser.hpp:308
Grammar gr_
The grammar being processed by the parser.
Definition slr1_parser.hpp:296
transition_table transitions_
The transition table used by the parser to determine state transitions.
Definition slr1_parser.hpp:312
@ Shift
Definition slr1_parser.hpp:51
@ Accept
Definition slr1_parser.hpp:51
@ Empty
Definition slr1_parser.hpp:51
@ Reduce
Definition slr1_parser.hpp:51
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:370
A single step in the SLR(1) guided assistant for table construction.
Definition slrwizardpage.h:41
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:59
QVector< QString > stdVectorToQVector(const std::vector< std::string > &vec)
Converts a std::vector<std::string> to QVector<QString> for UI compatibility.
Definition slrwizard.h:174
@ F
Definition slrtutorwindow.h:69
SymbolTable st_
Symbol table of the grammar.
Definition grammar.hpp:139
std::string antecedent_
The non-terminal on the left-hand side of the production.
Definition lr0_item.hpp:39
std::vector< std::string > consequent_
The sequence of symbols on the right-hand side of the production.
Definition lr0_item.hpp:44
Definition slr1_parser.hpp:64
const Lr0Item * item
Definition slr1_parser.hpp:65
Action action
Definition slr1_parser.hpp:66
std::string EPSILON_
Epsilon symbol, representing empty transitions, initialized as "EPSILON".
Definition symbol_table.hpp:51
std::unordered_set< std::string > terminals_
Set of all terminal symbols (including EOL).
Definition symbol_table.hpp:61