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#ifndef SLRWIZARDPAGE_H
2#define SLRWIZARDPAGE_H
3
4#include <QAbstractButton>
5#include <QLabel>
6#include <QLineEdit>
7#include <QVBoxLayout>
8#include <QWizard>
9#include <QWizardPage>
10
21class SLRWizardPage : public QWizardPage
22{
23 Q_OBJECT
24public:
35 const QString &symbol,
36 const QString &explanation,
37 const QString &expected,
38 QWidget *parent = nullptr)
39 : QWizardPage(parent)
40 , m_state(state)
41 , m_symbol(symbol)
42 , m_expected(expected)
43 {
44 setTitle(tr("Estado %1, símbolo '%2'").arg(state).arg(symbol));
45
46 QLabel *lbl = new QLabel(explanation, this);
47 lbl->setWordWrap(true);
48
49 m_edit = new QLineEdit(this);
50 m_edit->setPlaceholderText(tr("Escribe tu respuesta (p.ej. s3, r2, acc, 5)"));
51
52 QVBoxLayout *layout = new QVBoxLayout(this);
53 layout->addWidget(lbl);
54 layout->addWidget(m_edit);
55 setLayout(layout);
56
57 connect(m_edit, &QLineEdit::textChanged, this, &SLRWizardPage::onTextChanged);
58 }
59private slots:
64 void onTextChanged(const QString &text)
65 {
66 bool correct = (text.trimmed() == m_expected);
67 setComplete(correct);
68 if (correct) {
69 setSubTitle(tr("✔ Respuesta correcta, pasa a la siguiente pregunta"));
70 } else {
71 setSubTitle(
72 tr("✘ Incorrecto, revisa el enunciado. Consulta los estados que has construido."));
73 }
74 wizard()->button(QWizard::NextButton)->setEnabled(correct);
75 }
76
77private:
82 void setComplete(bool complete)
83 {
84 m_isComplete = complete;
85 emit completeChanged();
86 }
87
92 bool isComplete() const override { return m_isComplete; }
93
94 int m_state;
95 QString m_symbol;
96 QString m_expected;
97 QLineEdit *m_edit;
98 bool m_isComplete = false;
99};
100
101#endif // SLRWIZARDPAGE_H
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:34
Represents a state in the LR(0) automaton.
Definition state.hpp:16