Таблица П1.2 Порядок приемки и контроля
|
Наименование контрольного этапа выполнения работы |
Результат выполнения |
Отметка и дата приёмки результата |
|
|
Создание обрабатываемого кода программы |
Код программы, над которым будет проводится лексический анализ, проверен преподавателем |
Выполнено 14.02.2020 |
|
|
Разработка программного кода для обработки комментариев, пробелов и пустых строк |
часть программы выполняющая удаление комментариев и лишних пробелов |
Выполнено 20.02.2020 |
|
|
Создание автоматной модели промежуточного представления |
Автоматная модель промежуточного представления проверена преподавателем |
Выполнено 05.03.2020 |
|
|
Программирование конечного автомата (КА) |
Часть лексического анализатора проверена преподавателем |
Выполнено 22.03.2020 |
|
|
Дополнение созданной ранее программы формированием таблиц с классами лексем. |
Часть программы, формирующая таблицы лексем, проверена преподавателем |
Выполнено 26.03.2020 |
|
|
Построение дескрипторного кода и псевдокода |
Часть программы, формирующая дескрипторный и псевдокод, проверена преподавателем |
Выполнено 15.04.2020 |
|
|
Написать части лексического анализатора по обработке лексических ошибок |
Часть программы, выявляющая ошибки в тексте, проверена преподавателем |
Выполнено 20.05.2020 |
|
|
Составление КС-грамматики для синтаксического анализа |
По построенной КСГ проделан успешный синтаксический анализ обрабатываемого кода |
Выполнено 28.05.2020 |
|
|
Подготовка документации |
Расчётно-пояснительная записка проверена преподавателем |
Выполнено |
|
|
Защита курсовой работы |
Курсовая работа защищена |
Выполнено |
Приложение 2
Руководство пользователя
Приложение Project является лексическим обработчиком входного кода программы. В ходе работы приложение производит такие действия с кодом как удаление комментариев, лишних пробелов и пустых строк, а также распределяет слова-лексемы по соответствующим таблицам классов и на основе таблиц создаёт дескрипторный код и псевдокод.
Для запуска приложения нужно открыть одноимённый файл Project.exe. Для этого нужно либо дважды нажать Левую кнопку мыши при наведённом на файл курсоре, либо нажать клавишу Enter при выделенном файле.
После открытия файла появляется следующее окно (рисунок 14).
Рис. 14. Интерфейс приложения.
Рис. 15. Поле для ввода кода.
В данном поле необходимо ввести код, подлежащий обработке (рисунок 15).
После нажатия кнопки «start processing» запускается обработка кода (рисунок 16). Происходит:
3.2 удаление комментариев, пробелов и пустых строк;
3.3 запись обработанного кода в нижний левый текстовый блок с нумерацией строк;
3.4 запись лексем в таблицы;
3.5 формирование псевдо и дискрипторного кодов.
Рис. 16. Обработка кода.
Если в процессе обработки кода программа найдет ошибку, то программа прервется и выдаст сообщение о ее названии и фрагмент этой ошибки (рисунок 17).
Рис. 17. Пример ошибки.
После нажатия копки «error processing» запускается анализ кода на наличие ошибок (рисунок 18).
Рис. 18. Анализ кода на наличие ошибок.
После нажатия кнопки “clear” производиться очистка вспомогательных полей. Главный текстовый блок, в котором располагается основной код, не очищается (рисунок 19).
Рис. 19. Очистка текстовых полей и таблиц.
Приложение 3: программный код
Заголовочный файл
#ifndef prv
#define prv
#include <string>
bool punctz(wchar_t c)
{
return (c == ',' || c== ';' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c== '}'||c =='"');
}
bool digit(wchar_t c)
{
return (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9');
}
bool word(wchar_t c)
{
return (c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' || c == 'g' || c == 'h'
|| c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || c == 'o' || c == 'p'
|| c == 'q' || c == 'r' || c == 's' || c == 't' || c == 'u' || c == 'v' || c == 'w' || c == 'x'
|| c == 'y' || c == 'z' || c == '_' || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E'
|| c == 'F' || c == 'G' || c == 'H'
|| c == 'I' || c == 'J' || c == 'K' || c == 'L' || c == 'M' || c == 'N' || c == 'O' || c == 'P'
|| c == 'Q' || c == 'R' || c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X'
|| c == 'Y' || c == 'Z');
}
double o_perat(wchar_t c){
switch (c) {
case '>':
return 1;
case '<':
return 2;
case '=':
return 3;
case '+':
return 4;
case '*':
return 5;
case '-':
return 6;
case '!':
return 7;
case '|':
return 8;
case '&':
return 9;
}
return 0;
}
int o_perat1(int c) {
switch (c) {
case 1:
return 2;
case 2:
return 2;
case 3:
return 1;
case 4:
return 1;
case 5:
return 1;
case 6:
return 1;
case 7:
return 2;
case 9:
return 1;
case 11:
return 1;
case 13:
return 2;
case 22:
return 1;
case 23:
return 2;
case 33:
return 2;
case 43:
return 1;
case 44:
return 1;
case 53:
return 1;
case 63:
return 1;
case 66:
return 1;
case 73:
return 2;
case 88:
return 2;
case 99:
return 1;
}
return 0;
}
#endif
Основной код
#pragma once
#include <iostream>
#include <string>
#include <windows.h>
#include "proverk.h"
namespace Project {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
public:
/*protected:
virtual void WndProc(Message% m) override
{
System::Windows::Forms::Form::WndProc(m);
if (m.Msg == WM_DEVICECHANGE)
{
}
}*/
private: System::Windows::Forms::MessageBox^ Mb;
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::RichTextBox^ richTextBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::RichTextBox^ richTextBox2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::DataGridView^ keyWord1;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column1;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column2;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column3;
private: System::Windows::Forms::DataGridView^ op1;
private: System::Windows::Forms::DataGridView^ ops1;
private: System::Windows::Forms::DataGridView^ constant1;
private: System::Windows::Forms::DataGridView^ ident1;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::DataGridView^ punctuation1;
private: System::Windows::Forms::RichTextBox^ richTextBox3;
private: System::Windows::Forms::RichTextBox^ richTextBox4;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn1;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn2;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn3;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn4;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn5;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn6;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn7;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn8;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn9;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn10;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn11;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn12;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn13;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn14;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ dataGridViewTextBoxColumn15;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container^ components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора -- не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
this->keyWord1 = (gcnew System::Windows::Forms::DataGridView());
this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->op1 = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->ops1 = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn4 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn5 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn6 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->constant1 = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn7 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn8 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn9 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->ident1 = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn10 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn11 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn12 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->punctuation1 = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn13 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn14 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->dataGridViewTextBoxColumn15 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
this->richTextBox4 = (gcnew System::Windows::Forms::RichTextBox());
this->label7 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->keyWord1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->op1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->ops1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->constant1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->ident1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->punctuation1))->BeginInit();
this->SuspendLayout();
//
// richTextBox1
//
this->richTextBox1->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->richTextBox1->Location = System::Drawing::Point(12, 12);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(312, 139);
this->richTextBox1->TabIndex = 0;
this->richTextBox1->Text = resources->GetString(L"richTextBox1.Text");
this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::richTextBox1_TextChanged);
//
// button1
//
this->button1->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->button1->Location = System::Drawing::Point(329, 12);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(79, 47);
this->button1->TabIndex = 1;
this->button1->Text = L"start processing";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// richTextBox2
//
this->richTextBox2->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->richTextBox2->Location = System::Drawing::Point(12, 157);
this->richTextBox2->Name = L"richTextBox2";
this->richTextBox2->Size = System::Drawing::Size(312, 139);
this->richTextBox2->TabIndex = 2;
this->richTextBox2->Text = L"";
this->richTextBox2->TextChanged += gcnew System::EventHandler(this, &MyForm::richTextBox2_TextChanged);
//
// keyWord1
//
this->keyWord1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom));
this->keyWord1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->keyWord1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^>(3) {
this->Column1, this->Column2,
this->Column3
});
this->keyWord1->EnableHeadersVisualStyles = false;
this->keyWord1->Location = System::Drawing::Point(12, 316);
this->keyWord1->Name = L"keyWord1";
this->keyWord1->RightToLeft = System::Windows::Forms::RightToLeft::No;
this->keyWord1->RowHeadersVisible = false;
this->keyWord1->Size = System::Drawing::Size(113, 103);
this->keyWord1->TabIndex = 9;
this->keyWord1->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::keyWord1_CellContentClick);
//
// Column1
//
this->Column1->HeaderText = L"10";
this->Column1->Name = L"Column1";
this->Column1->Width = 30;
//