SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
Loading...
Searching...
No Matches
slrwizardpage.h
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
#ifndef SLRWIZARDPAGE_H
20
#define SLRWIZARDPAGE_H
21
22
#include <QAbstractButton>
23
#include <QLabel>
24
#include <QLineEdit>
25
#include <QVBoxLayout>
26
#include <QWizard>
27
#include <QWizardPage>
28
41
class
SLRWizardPage
:
public
QWizardPage {
42
Q_OBJECT
43
public
:
54
SLRWizardPage
(
int
state
,
const
QString& symbol,
const
QString& explanation,
55
const
QString& expected, QWidget* parent =
nullptr
)
56
: QWizardPage(parent), m_state(
state
), m_symbol(symbol),
57
m_expected(expected) {
58
setTitle(tr(
"Estado %1, símbolo '%2'"
).arg(
state
).arg(symbol));
59
60
QLabel* lbl =
new
QLabel(explanation,
this
);
61
lbl->setWordWrap(
true
);
62
63
m_edit =
new
QLineEdit(
this
);
64
m_edit->setPlaceholderText(
65
tr(
"Escribe tu respuesta (p.ej. s3, r2, acc, 5)"
));
66
67
QVBoxLayout* layout =
new
QVBoxLayout(
this
);
68
layout->addWidget(lbl);
69
layout->addWidget(m_edit);
70
setLayout(layout);
71
72
connect(m_edit, &QLineEdit::textChanged,
this
,
73
&SLRWizardPage::onTextChanged);
74
}
75
private
slots:
81
void
onTextChanged(
const
QString& text) {
82
bool
correct = (text.trimmed() == m_expected);
83
setComplete(correct);
84
if
(correct) {
85
setSubTitle(
86
tr(
"✔ Respuesta correcta, pasa a la siguiente pregunta"
));
87
}
else
{
88
setSubTitle(tr(
"✘ Incorrecto, revisa el enunciado. Consulta los "
89
"estados que has construido."
));
90
}
91
wizard()->button(QWizard::NextButton)->setEnabled(correct);
92
}
93
94
private
:
99
void
setComplete(
bool
complete) {
100
m_isComplete = complete;
101
emit completeChanged();
102
}
103
109
bool
isComplete()
const override
{
return
m_isComplete; }
110
111
int
m_state;
112
QString m_symbol;
113
QString m_expected;
114
QLineEdit* m_edit;
115
bool
m_isComplete =
116
false
;
117
};
118
119
#endif
// SLRWIZARDPAGE_H
SLRWizardPage::SLRWizardPage
SLRWizardPage(int state, const QString &symbol, const QString &explanation, const QString &expected, QWidget *parent=nullptr)
Constructs a page for a specific cell in the SLR(1) table.
Definition
slrwizardpage.h:54
state
Represents a state in the LR(0) automaton.
Definition
state.hpp:33
slrwizardpage.h
Generated by
1.14.0