Синтез распознающего автомата
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
editingFinished();
on_lineAllowedState_editingFinished();
on_pushButton_clicked();
on_about_triggered();
on_about_Qt_triggered();
:stateChanged();
};
#endif // MAINWINDOW_H
2.Заголовочный файл visualization.h
#ifndef VISUALISATION_H
#define VISUALISATION_H
#include
visualisation : public QWidget
{_OBJECT:visualisation(QWidget *parent = 0);setRibbon(QList *r);setSpaceSymbol(QChar c);setFakePos(int *pos);setRealPos(int *pos);setState(QChar *c);setResultText(const QString str);
: *ribbon;resultText;spaceSymbol, *state;*fakePos, *realPos;:
slots:
:paintEvent(QPaintEvent *);
};
#endif // VISUALISATION_H
3.Реализация mainwindow.cpp
#include
#include
#include
#include
#include "mainwindow.h"
#include "ui_mainwindow.h"
::MainWindow(QWidget *parent) :(parent),(new Ui::MainWindow)
{>setupUi(this);>comboMoveTo->addItem(trUtf8("Влево"));>comboMoveTo->addItem(trUtf8("Стоять"));>comboMoveTo->addItem(trUtf8("Вправо"));= 0;= 0;(this, SIGNAL(stateChanged()), ui->widget, SLOT(repaint()));(&timer, SIGNAL(timeout()), this, SLOT(step()));>widget->setRibbon(&ribbon);>widget->setFakePos(&fakePos);>widget->setRealPos(&ribbonPos);>widget->setState(¤tState);= 0;= 0;= false;= false;
}
::~MainWindow()
{ui;
}
MainWindow::isStopState(const QChar c)
{endStateSet.contains(c);
}
MainWindow::writeSymbol(const QChar c)
{.insert(ribbonPos, c);.removeAt(ribbonPos + 1);stateChanged();
}
MainWindow::moveRight()
comboSpaceSymbol->itemText(ui->comboSpaceSymbol->currentIndex()).at(0));++;stateChanged();">{++;(ribbonPos == ribbon.count() - 1).append(ui->comboSpaceSymbol->itemText(ui->comboSpaceSymbol->currentIndex()).at(0));++;stateChanged();
}
MainWindow::moveLeft()
{-;(ribbonPos > 0)-;.prepend(ui->comboSpaceSymbol->itemText(ui->comboSpaceSymbol->currentIndex()).at(0));stateChanged();
}
MainWindow::step()
{>widget->setResultText(QString(""));(!isStopState(currentState) && ready)
comboSpaceSymbol->itemText(ui->comboSpaceSymbol->currentIndex()).at(0);+=in+trUtf8(",");">{logString;+= trUtf8("Входной символ ");i = 0, j = 0;in;(ribbon.count() != 0)= ribbon.at(ribbonPos);= ui->comboSpaceSymbol->itemText(ui->comboSpaceSymbol->currentIndex()).at(0); += in + trUtf8(", устанавливается состояние ");
QString inSymbol = ui->ruleTable->horizontalHeaderItem(i)->text();(in != inSymbol && i columnCount())
{++;= ui->ruleTable->horizontalHeaderItem(i)->text();
}
state = ui->ruleTable->verticalHeaderItem(j)->text();(state != currentState && j rowCount())
{++;= ui->ruleTable->verticalHeaderItem(j)->text();
}asd = ui->ruleTable->item(j, i)->text().at(2); += asd + trUtf8(", записывается символ ");
currentState = asd;>writeSymbol(ui->ruleTable->item(j, i)->text().at(0));+= ui->ruleTable->item(j, i)->text().at(0);+= trUtf8(", каретка ");
(ui->ruleTable->item(j, i)->text().at(1) == QString("L").at(0))
{>moveLeft();+= trUtf8("движется влево");
}if (ui->ruleTable->item(j, i)->text().at(1) == QString("R").at(0))
{>moveRight();+= trUtf8("движется вправо");
}+= trUtf8("стоит на месте");>logWidget->addItem(logString);
}
{= false;>buttonStartStop->setText(trUtf8("Старт"));.stop();
}(isStopState(currentState))
{= false;>logWidget->addItem(QString(trUtf8("Достигли конечного состояния; остановка")));(isAllowedState(currentState))>widget->setResultText(this->getMeaningByState(currentState));>widget->setResultText(trUtf8("Состояние недопустимо"));
}
}
MainWindow::resetState()
{>logWidget->clear();(ready)
{= 0;= 0;= ui->comboBaseState->itemText(ui->comboBaseState->currentIndex()).at(0);stateChanged();
}
}
MainWindow::on_buttonSetStates_clicked()
{.clear();.clear();.clear();(int i = 0; i text().at(i);
.clear();(int i = 0; i text().at(i);
stateList=stateSet.toList(); symbolsList = symbolsSet.toList();(stateList);(symbolsList);
ruleTable->clear();>meaningsTable->clear();>ruleTable->setRowCount(stateSet.count());>ruleTable->setColumnCount(symbolsSet.count());>meaningsTable->setRowCount(stateSet.count());>meaningsTable->setColumnCount(1);">>ruleTable->clear();>meaningsTable->clear();>ruleTable->setRowCount(stateSet.count());>ruleTable->setColumnCount(symbolsSet.count());>meaningsTable->setRowCount(stateSet.count());>meaningsTable->setColumnCount(1);
ruleTable->setItem(0,0,newQTableWidgetItem);str="";>meaningsTable->clear();>comboSetState->clear();>comboBaseState->clear();(inti=0;iclear();(int i = 0; i < stateList.length(); i++)
ruleTable->setVerticalHeaderItem(i,newQTableWidgetItem(QString(stateList.at(i))));>meaningsTable->setVerticalHeaderItem(i,newQTableWidgetItem(QString(stateList.at(i))));+=stateList.at(i);>comboSetState->addItem(stateList.at(i));>comboBaseState->addItem(stateList.at(i));">{>ruleTable->setVerticalHeaderItem(i, new QTableWidgetItem(QString(stateList.at(i))));>meaningsTable->setVerticalHeaderItem(i, new QTableWidgetItem(QString(stateList.at(i))));+= stateList.at(i);>comboSetState->addItem(stateList.at(i));>comboBaseState->addItem(stateList.at(i));
}>lineStateSymbols->setText(str);
comboWriteSymbol->clear();>comboSpaceSymbol->clear();(inti=0;iclear();(int i = 0; i < symbolsList.length(); i++)
ruleTable->setHorizontalHeaderItem(i,newQTableWidgetItem(QString(symbolsList.at(i))));+=symbolsList.at(i);>comboWriteSymbol->addItem(symbolsList.at(i));>comboSpaceSymbol->addItem(symbolsList.at(i));">{>ruleTable->setHorizontalHeaderItem(i, new QTableWidgetItem(QString(symbolsList.at(i))));+= symbolsList.at(i);>comboWriteSymbol->addItem(symbolsList.at(i));>comboSpaceSymbol->addItem(symbolsList.at(i));
}>lineInputSymbols->setText(str);
(int i = 0; i setItem(i,j, new QTableWidgetItem);
(int i = 0; i columnCount(); j++)
{asd = " ";[0] = ui->ruleTable->horizontalHeaderItem(j)->text().at(0);[1] = QString("R").at(0);[2] = ui->ruleTable->verticalHeaderItem(i)->text().at(0);>ruleTable->item(i, j)->setText(asd);
}= true;>resetState();
}
MainWindow::on_load_triggered()
{fileName = QFileDialog::getOpenFileName(this, trUtf8("Загрузить таблицу"),
"",("Таблицы правил (*.tbl)"));file( fileName );( !file.open( QIODevice::ReadOnly ) );
stream( &file );.setVersion( QDataStream::Qt_4_2 );
>ruleTable->clear();.clear();.clear();rows, columns, posa, posc;>> rows;>> columns;>> stateSet;>> symbolsSet;>> posa;>> posc;>> endStateSet;>> allowedStateSet;
>ruleTable->setRowCount(rows);>ruleTable->setColumnCount(columns);
str;(int i = -1; i < rows; i++)(int j = -1; j < columns; j++)
{>> str;(i > -1 && j > -1)
{>ruleTable->setItem(i, j, new QTableWidgetItem);>ruleTable->item(i, j)->setText(str);
}
{(i == -1 && j > -1)
{>ruleTable->setHorizontalHeaderItem(j, new QTableWidgetItem(str));
}(j == -1 && i > -1)
{>ruleTable->setVerticalHeaderItem(i, new QTableWidgetItem(str));
}
}
}
comboSetState->clear();>comboBaseState->clear();>meaningsTable->clear();>meaningsTable->setRowCount(stateSet.count())