{"id":18349178,"url":"https://github.com/andy-messer/formal-languages-practice-1-task-13","last_synced_at":"2025-04-09T23:45:45.436Z","repository":{"id":81130125,"uuid":"418599442","full_name":"Andy-Messer/formal-languages-practice-1-task-13","owner":"Andy-Messer","description":"Homework Formal Languages Practice 1","archived":false,"fork":false,"pushed_at":"2021-12-26T23:08:51.000Z","size":2818,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T23:45:41.306Z","etag":null,"topics":["mipt-homeworks"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Andy-Messer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-18T17:20:07.000Z","updated_at":"2022-03-27T18:37:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"87a1bb73-31da-460f-891c-a8425907028c","html_url":"https://github.com/Andy-Messer/formal-languages-practice-1-task-13","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-1-task-13","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-1-task-13/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-1-task-13/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-1-task-13/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andy-Messer","download_url":"https://codeload.github.com/Andy-Messer/formal-languages-practice-1-task-13/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131465,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mipt-homeworks"],"created_at":"2024-11-05T21:20:57.915Z","updated_at":"2025-04-09T23:45:45.416Z","avatar_url":"https://github.com/Andy-Messer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Задача:\n\n\u003e 13. Даны α и слово u ∈ {a, b, c} ∗ . Найти длину самого длинного подслова u, принадлежащего L.\n\n# Корректность и идея:\n\u003e Сначала обозначим корректность и идею:\nПостроим НКА по данному регулярному выражению, если НКА построить не удалось ввод был не корректен.\nВоспользуемся тем, что если НКА может прочитать данное пользователем слово, то оно принадлежит языку,\nиначе не принадлежит.\n\n# Подробное описание алгоритма и асимптотика\n### асимптотика построения\n\n\u003e 1. Первое на что стоит обратить внимание, что алгоритм буква за буквой разбирает регулярное выражение, \n     каждый раз за O(1), обновляя автомат. Автомат будем представлять себе в виде стека,\n     на который кладутся вершины одна за другой, для обновления автомата нам потребуется задействовать\n     не более чем 3 вершины из этого стека, что сведется в константу. Но надо учитывать получившееся кол-во вершин и рёбер.\n\n\u003e  Создание простейшего автомата принесло нам 2 состояния и 1 ребро.\n\n\u003e  Операция '.' привнесла 1 ребро по пустому слову. reg_concatination - O(1)\n\n\u003e  Операция '+' привнесла 2 вершины и 4 ребра. reg_or - O(1)\n\n\u003e  Операция '*' привнесла 1 ребро. reg_itration - O(1)\n\n\u003e  Итого если в изначальном выражении было n символов, из них floor(n/2) операций.\n   Максимальное кол-во ребер = 2 * n, где n = | reg_expr |.\n   Максимальное кол-во вершин = n, где n = | reg_expr |.\n   Получили разреженный граф с 2n ребрами, и n вершинами.\n### асимптотика обработки\n\n\u003e 2. И так мы построили автомат за O(n), где n = | reg_expr |,\n     теперь придется за O(k^2), где k = | input_string | перебрать подстроки,\n     входной строки (возможно можно было придумать какое-нибудь ДП P.s. не придумал... ).\n\n\u003e  Для каждой такой строки запустимся по автомату с помощью BFS без пометок в used!!! Это необходимо, т.к.\n     в автомате допустимы несколько переходов в разные состояния по одной букве.\n     Чтобы прочитать какое-то слово требуется, пройти, как минимум, k состояний, а значит Асимптотика такого BFS\n     O(n * k), 2n кол-во ребер иначе говоря ответвлений, значит финальный результат достигается O(n * k^2).\n     Но часто, кол-во ответвлений критически мало, а значит сведётся в константу, откуда делаем вывод в оптимальных случаях\n     алгоритм работает за перебор подстрок во входном слове O(k^2).\n\n\u003e P.s. За сколько работает dump? Если оценить сверху O(n^2) т.к. для каждой вершины мы рисуем все ребра.\n\n\n# Решение:\n## Шаг 1:\n\u003e Т.к. пользователю разрешено передавать поток вывода и ввода, обрабатываем их.\n``` python\nif isinstance(istream, type(io.StringIO())):\n    sys.stdin = istream\nif isinstance(ostream, type(io.StringIO())):\n    sys.stdout = ostream\n```\n## Шаг 2:\n\u003e Далее считываем из потока строку и парсим по пробелам.\n\u003e Если слов меньше чем нужно или больше кидаем исключение.\n\n## Шаг 3:\n\u003e Перебираем все подслова переданной строки и проверяем на ответ.\n\n## Шаг 4:\n\u003e Начинаем строить автомат.\n\u003e Будем парсить по символьно если встречаем символ из алфавита добавляем простейший НКА.\n\n![](practice1/doc/2.png)\n\n\u003e Рассмотри операцию '.' для букв a, b\n\n![](practice1/doc/1.png)\n\n\u003e операция '+' для букв a, b\n\n![](practice1/doc/3.png)\n\n\u003e операция '*' для слова ab\n\n![](practice1/doc/4.png)\n\n## Шаг 5\n\u003e Запускаем BFS по автомату с некоторыми пометками для выхода.\n``` python\n# Putting the starting state in the queue\nindex = 0\nq = [[self.initial, index]]\nwhile len(q) \u003e 0:\n    # Take out the current state\n    state = q[0][0]\n    ind = q[0][1]\n    q.pop(0)\n    # Processing eps transitions\n    for next_state in _get_ways(state, 'eps'):\n        q.append([next_state, ind])\n    if ind \u003c len(string):\n        # Put in the queue all states reachable by a given letter\n        if _is_way_to(state, string[ind]):\n            for next_state in _get_ways(state, string[ind]):\n                q.append([next_state, ind + 1])\n    elif state.final:\n        return True\nreturn False\n```\n\n## Шаг 6\n\u003e Выводим ответ: максимальная длина подстроки\n\n# Тесты из условия \n## Тест 1 \"ab+c.aba.*.bac.+.+* babc\"\n\u003e Ответ: 2\n\n### logs\n``` python\n2021-10-22 16:02:47,827 - root - INFO - Redirecting input and output streams\n2021-10-22 16:02:47,828 - root - INFO - Done...\n2021-10-22 16:03:02,139 - root - INFO - Submitted to the entrance: \"ab+c.aba.*.bac.+.+*\", \"babc\"\n2021-10-22 16:03:02,140 - root - INFO - Start building NFA...\n2021-10-22 16:03:02,140 - root - INFO - Constructing NFA from regExpr\n2021-10-22 16:03:02,141 - root - INFO - Initialize some basic variables\n2021-10-22 16:03:02,141 - root - INFO - Trying to parse regExpr\n2021-10-22 16:03:02,141 - root - INFO - Parse regExpr letter by letter\n2021-10-22 16:03:02,142 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,142 - root - INFO - Created.\n2021-10-22 16:03:02,142 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,143 - root - INFO - Created.\n2021-10-22 16:03:02,144 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,144 - root - INFO - Created.\n2021-10-22 16:03:02,144 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,144 - root - INFO - Created.\n2021-10-22 16:03:02,145 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,145 - root - INFO - Created.\n2021-10-22 16:03:02,145 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,145 - root - INFO - Created.\n2021-10-22 16:03:02,146 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,146 - root - INFO - Created.\n2021-10-22 16:03:02,146 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,147 - root - INFO - Created.\n2021-10-22 16:03:02,147 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:03:02,147 - root - INFO - Created.\n2021-10-22 16:03:02,148 - root - INFO - NFA Constructed.\n2021-10-22 16:03:03,461 - root - INFO - Start solving the task.\n2021-10-22 16:03:03,461 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,462 - root - INFO - \"b\" has been passed to NFA for reading\n2021-10-22 16:03:03,462 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,462 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,462 - root - INFO - \"ba\" has been passed to NFA for reading\n2021-10-22 16:03:03,463 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,463 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,463 - root - INFO - \"bab\" has been passed to NFA for reading\n2021-10-22 16:03:03,463 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,464 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,464 - root - INFO - \"babc\" has been passed to NFA for reading\n2021-10-22 16:03:03,464 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,464 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,465 - root - INFO - \"a\" has been passed to NFA for reading\n2021-10-22 16:03:03,465 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,465 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,465 - root - INFO - \"ab\" has been passed to NFA for reading\n2021-10-22 16:03:03,466 - root - INFO - the Line was read!\n2021-10-22 16:03:03,467 - root - INFO - Checking the length of substring\n2021-10-22 16:03:03,467 - root - INFO - New answer!!! 2\n2021-10-22 16:03:03,467 - root - INFO - Checked.\n2021-10-22 16:03:03,467 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,468 - root - INFO - \"abc\" has been passed to NFA for reading\n2021-10-22 16:03:03,468 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,468 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,469 - root - INFO - \"b\" has been passed to NFA for reading\n2021-10-22 16:03:03,469 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,469 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,469 - root - INFO - \"bc\" has been passed to NFA for reading\n2021-10-22 16:03:03,470 - root - INFO - the Line was read!\n2021-10-22 16:03:03,470 - root - INFO - Checking the length of substring\n2021-10-22 16:03:03,470 - root - INFO - Checked.\n2021-10-22 16:03:03,470 - root - INFO - ------------------------------------------------\n2021-10-22 16:03:03,471 - root - INFO - \"c\" has been passed to NFA for reading\n2021-10-22 16:03:03,471 - root - INFO - the Line wasn't read\n2021-10-22 16:03:03,471 - root - INFO - Exiting from \"solve\"\n```\n\n![](practice1/doc/5.png)\n\n## Тест 2 \"acb..bab.c.*.ab.ba.+.+*a. abbaa\"\n\u003e Ответ: 4\n\n### logs\n```python\n2021-10-22 16:11:47,633 - root - INFO - Redirecting input and output streams\n2021-10-22 16:11:47,634 - root - INFO - Done...\n2021-10-22 16:11:49,299 - root - INFO - Submitted to the entrance: \"acb..bab.c.*.ab.ba.+.+*a.\", \"abbaa\"\n2021-10-22 16:11:49,299 - root - INFO - Start building NFA...\n2021-10-22 16:11:49,300 - root - INFO - Constructing NFA from regExpr\n2021-10-22 16:11:49,300 - root - INFO - Initialize some basic variables\n2021-10-22 16:11:49,300 - root - INFO - Trying to parse regExpr\n2021-10-22 16:11:49,300 - root - INFO - Parse regExpr letter by letter\n2021-10-22 16:11:49,300 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,300 - root - INFO - Created.\n2021-10-22 16:11:49,300 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,306 - root - INFO - Created.\n2021-10-22 16:11:49,306 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,306 - root - INFO - Created.\n2021-10-22 16:11:49,306 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,306 - root - INFO - Created.\n2021-10-22 16:11:49,306 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,307 - root - INFO - Created.\n2021-10-22 16:11:49,307 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,307 - root - INFO - Created.\n2021-10-22 16:11:49,307 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,307 - root - INFO - Created.\n2021-10-22 16:11:49,307 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,307 - root - INFO - Created.\n2021-10-22 16:11:49,307 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,308 - root - INFO - Created.\n2021-10-22 16:11:49,308 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,308 - root - INFO - Created.\n2021-10-22 16:11:49,308 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,308 - root - INFO - Created.\n2021-10-22 16:11:49,308 - root - INFO - Creating some basic NFA for one letter\n2021-10-22 16:11:49,308 - root - INFO - Created.\n2021-10-22 16:11:49,308 - root - INFO - NFA Constructed.\n2021-10-22 16:11:49,407 - root - INFO - Start solving the task.\n2021-10-22 16:11:49,407 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,407 - root - INFO - \"a\" has been passed to NFA for reading\n2021-10-22 16:11:49,407 - root - INFO - the Line was read!\n2021-10-22 16:11:49,407 - root - INFO - Checking the length of substring\n2021-10-22 16:11:49,407 - root - INFO - New answer!!! 1\n2021-10-22 16:11:49,407 - root - INFO - Checked.\n2021-10-22 16:11:49,407 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,407 - root - INFO - \"ab\" has been passed to NFA for reading\n2021-10-22 16:11:49,407 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,407 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"abb\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,408 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"abba\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,408 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"abbaa\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,408 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"b\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,408 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"bb\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,408 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,408 - root - INFO - \"bba\" has been passed to NFA for reading\n2021-10-22 16:11:49,408 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,409 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,409 - root - INFO - \"bbaa\" has been passed to NFA for reading\n2021-10-22 16:11:49,409 - root - INFO - the Line was read!\n2021-10-22 16:11:49,409 - root - INFO - Checking the length of substring\n2021-10-22 16:11:49,409 - root - INFO - New answer!!! 4\n2021-10-22 16:11:49,409 - root - INFO - Checked.\n2021-10-22 16:11:49,409 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,409 - root - INFO - \"b\" has been passed to NFA for reading\n2021-10-22 16:11:49,409 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,409 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,409 - root - INFO - \"ba\" has been passed to NFA for reading\n2021-10-22 16:11:49,409 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,409 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,409 - root - INFO - \"baa\" has been passed to NFA for reading\n2021-10-22 16:11:49,409 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,409 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,409 - root - INFO - \"a\" has been passed to NFA for reading\n2021-10-22 16:11:49,409 - root - INFO - the Line was read!\n2021-10-22 16:11:49,409 - root - INFO - Checking the length of substring\n2021-10-22 16:11:49,409 - root - INFO - Checked.\n2021-10-22 16:11:49,410 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,410 - root - INFO - \"aa\" has been passed to NFA for reading\n2021-10-22 16:11:49,410 - root - INFO - the Line wasn't read\n2021-10-22 16:11:49,410 - root - INFO - ------------------------------------------------\n2021-10-22 16:11:49,410 - root - INFO - \"a\" has been passed to NFA for reading\n2021-10-22 16:11:49,410 - root - INFO - the Line was read!\n2021-10-22 16:11:49,410 - root - INFO - Checking the length of substring\n2021-10-22 16:11:49,410 - root - INFO - Checked.\n2021-10-22 16:11:49,410 - root - INFO - Exiting from \"solve\"\n```\n![](practice1/doc/6.png)\n\n## Результаты тестирования\n\n![](practice1/doc/picture1.png)\n\n# Документация\n# Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`namespace `[`practice1`](#namespacepractice1) | Python Library - Solve for homework: 'Formal Languages, Practice 1, task 13'.\n`namespace `[`practice1::dump`](#namespacepractice1_1_1dump) | module - Dump utility of NFA.\n`namespace `[`practice1::nfa`](#namespacepractice1_1_1nfa) | module - Implementation of [NFA](#classpractice1_1_1nfa_1_1NFA).\n\n# namespace `practice1` \n\nPython Library - Solve for homework: 'Formal Languages, Practice 1, task 13'.\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`solve`](#namespacepractice1_1a4f1e2327621575169836b24fad1c4cc0)`(istream,ostream)`            | Solution for the task.\n\n## Members\n\n#### `public def `[`solve`](#namespacepractice1_1a4f1e2327621575169836b24fad1c4cc0)`(istream,ostream)` \n\nSolution for the task.\n\nКорректность: воспользуемся тем, что любая регулярка задаёт НКА. А значит если подслово может быть прочитано НКА, то оно принадлежит установленному языку. Более точно, переберем все подстроки данной нам строки и попытаемся их прочитать, длина наибольшей прочитанной строки будет ответом. Верность построения НКА доказывается самим алгоритмом построения.\n\n# namespace `practice1::dump` \n\nmodule - Dump utility of NFA.\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`__dump__`](#namespacepractice1_1_1dump_1ad9f715f29da831aa7643c91af5ebe458)`(nfa,filename)`            | Dump the information about NFA.\n`private def `[`__get_transitions_count`](#namespacepractice1_1_1dump_1a48a26379315f5034651c9f7bb9bb4fe5)`(node)`            | Counts the number of possible transitions.\n`public def `[`__print__`](#namespacepractice1_1_1dump_1ab26a8f699adf1b51bbb17f5d6b0f5286)`(nfa)`            | Dump NFA.\n`public def `[`__print_brief__`](#namespacepractice1_1_1dump_1ae6922a078c8fb18193cfe597b9590312)`(node)`            | Print a summary of the NFA node.\n`public def `[`__print_node__`](#namespacepractice1_1_1dump_1ade4c74aabe15dae245a2b47484ca9612)`(node)`            | Printing node of NFA.\n`private def `[`_tree_remove`](#namespacepractice1_1_1dump_1a99dcf84e0b8fa8cb8f8c888ffc8f198f)`(str top)`            | Removes all files in the current directory.\n`public str `[`make_new_state`](#namespacepractice1_1_1dump_1a8d3277da1b00286352f693cdb9c011a0)`(node)`            | Generate new name for id(node) in format: f'q + {id}'.\n\n## Members\n\n#### `public def `[`__dump__`](#namespacepractice1_1_1dump_1ad9f715f29da831aa7643c91af5ebe458)`(nfa,filename)` \n\nDump the information about NFA.\n\n#### Parameters\n* `nfa` NFA \n\n* `filename` output file\n\n#### `private def `[`__get_transitions_count`](#namespacepractice1_1_1dump_1a48a26379315f5034651c9f7bb9bb4fe5)`(node)` \n\nCounts the number of possible transitions.\n\n#### Parameters\n* `node` node that number of transitions is being searched for \n\n#### Returns\ncount: number of transitions\n\n#### `public def `[`__print__`](#namespacepractice1_1_1dump_1ab26a8f699adf1b51bbb17f5d6b0f5286)`(nfa)` \n\nDump NFA.\n\nMake notes about nodes and their connections \n#### Parameters\n* `nfa` nondeterministic finite automaton that need to be print\n\n#### `public def `[`__print_brief__`](#namespacepractice1_1_1dump_1ae6922a078c8fb18193cfe597b9590312)`(node)` \n\nPrint a summary of the NFA node.\n\nShort output format: 'node.name node.final' \n#### Parameters\n* `node` node the debug information about which should be output\n\n#### `public def `[`__print_node__`](#namespacepractice1_1_1dump_1ade4c74aabe15dae245a2b47484ca9612)`(node)` \n\nPrinting node of NFA.\n\nOutput the name of the node, its final and a list of neighbors with their number \n#### Parameters\n* `node` printing node\n\n#### `private def `[`_tree_remove`](#namespacepractice1_1_1dump_1a99dcf84e0b8fa8cb8f8c888ffc8f198f)`(str top)` \n\nRemoves all files in the current directory.\n\n#### Parameters\n* `top` Name of initial directory.\n\n#### `public str `[`make_new_state`](#namespacepractice1_1_1dump_1a8d3277da1b00286352f693cdb9c011a0)`(node)` \n\nGenerate new name for id(node) in format: f'q + {id}'.\n\n#### Parameters\n* `node` node \n\n#### Returns\nname: new name of node\n\n# namespace `practice1::nfa` \n\nmodule - Implementation of [NFA](#classpractice1_1_1nfa_1_1NFA).\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`private list `[`_get_ways`](#namespacepractice1_1_1nfa_1a4d9a2e5db8da6340541e17cde0bc5680)`(`[`_Node`](#classpractice1_1_1nfa_1_1__Node)` state,str letter)`            | Returns a list of states that can be entered by a given letter.\n`private bool `[`_is_letter`](#namespacepractice1_1_1nfa_1a12e43040f4837c23c481fc929939fed5)`(str symbol)`            | Checks for the presence of a character in the alphabet.\n`private bool `[`_is_way_to`](#namespacepractice1_1_1nfa_1a44b82383fce3d09db5a6b4ee9e553c6b)`(`[`_Node`](#classpractice1_1_1nfa_1_1__Node)` state,str letter)`            | Checks for the presence letter in possible transitions.\n`class `[`practice1::nfa::_CreateNFA`](#classpractice1_1_1nfa_1_1__CreateNFA) | Functor for creating [NFA](#classpractice1_1_1nfa_1_1NFA).\n`class `[`practice1::nfa::_Node`](#classpractice1_1_1nfa_1_1__Node) | Section: Working with states of [NFA](#classpractice1_1_1nfa_1_1NFA).\n`class `[`practice1::nfa::NFA`](#classpractice1_1_1nfa_1_1NFA) | Section: Working with [NFA](#classpractice1_1_1nfa_1_1NFA).\n\n## Members\n\n#### `private list `[`_get_ways`](#namespacepractice1_1_1nfa_1a4d9a2e5db8da6340541e17cde0bc5680)`(`[`_Node`](#classpractice1_1_1nfa_1_1__Node)` state,str letter)` \n\nReturns a list of states that can be entered by a given letter.\n\n#### Parameters\n* `state` state of [NFA](#classpractice1_1_1nfa_1_1NFA)\n\n* `letter` letter from preset alphabet \n\n#### Returns\nlist list of states that can be entered by a given letter\n\n#### `private bool `[`_is_letter`](#namespacepractice1_1_1nfa_1a12e43040f4837c23c481fc929939fed5)`(str symbol)` \n\nChecks for the presence of a character in the alphabet.\n\n#### Parameters\n* `symbol` user-supplied character \n\n#### Returns\nTrue if symbol in alphabet \n\n#### Returns\nFalse if symbol not in alphabet\n\n#### `private bool `[`_is_way_to`](#namespacepractice1_1_1nfa_1a44b82383fce3d09db5a6b4ee9e553c6b)`(`[`_Node`](#classpractice1_1_1nfa_1_1__Node)` state,str letter)` \n\nChecks for the presence letter in possible transitions.\n\n#### Parameters\n* `state` state of [NFA](#classpractice1_1_1nfa_1_1NFA)\n\n* `letter` letter from preset alphabet \n\n#### Returns\nTrue if ways exist \n\n#### Returns\nFalse if ways don't exist\n\n# class `practice1::nfa::_CreateNFA` \n\nFunctor for creating [NFA](#classpractice1_1_1nfa_1_1NFA).\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public  `[`nodes`](#classpractice1_1_1nfa_1_1__CreateNFA_1a6da5270e48c8b5c2f0dbaa008af4df76) | \n`public  `[`stack`](#classpractice1_1_1nfa_1_1__CreateNFA_1a37d7c639a3adefa88200027e9f78ba3f) | \n`public def `[`__init__`](#classpractice1_1_1nfa_1_1__CreateNFA_1a62d114c8017936187a4b318c581e0bb3)`(self,reg_exp)` | Constructing [NFA](#classpractice1_1_1nfa_1_1NFA) instance.\n`public def `[`reg_concatenation`](#classpractice1_1_1nfa_1_1__CreateNFA_1a5c3712c31bdf8318bd4b732d4e99014b)`(self)` | Regex concatenation This method takes the last two elements in stack and concatenates.\n`public def `[`reg_iteration`](#classpractice1_1_1nfa_1_1__CreateNFA_1a377c78827ef6e6c6bfa1e88c880b6882)`(self)` | Regex iteration This method takes the last element and applies the Kleene star.\n`public def `[`reg_or`](#classpractice1_1_1nfa_1_1__CreateNFA_1a57eb512c08bd3207c3a41667f054dc65)`(self)` | boolean 'or' for regular expressions This method takes the last two elements in stack and forks them into one block with the help of two additional states.\n\n## Members\n\n#### `public  `[`nodes`](#classpractice1_1_1nfa_1_1__CreateNFA_1a6da5270e48c8b5c2f0dbaa008af4df76) \n\n#### `public  `[`stack`](#classpractice1_1_1nfa_1_1__CreateNFA_1a37d7c639a3adefa88200027e9f78ba3f) \n\n#### `public def `[`__init__`](#classpractice1_1_1nfa_1_1__CreateNFA_1a62d114c8017936187a4b318c581e0bb3)`(self,reg_exp)` \n\nConstructing [NFA](#classpractice1_1_1nfa_1_1NFA) instance.\n\n#### `public def `[`reg_concatenation`](#classpractice1_1_1nfa_1_1__CreateNFA_1a5c3712c31bdf8318bd4b732d4e99014b)`(self)` \n\nRegex concatenation This method takes the last two elements in stack and concatenates.\n\n#### `public def `[`reg_iteration`](#classpractice1_1_1nfa_1_1__CreateNFA_1a377c78827ef6e6c6bfa1e88c880b6882)`(self)` \n\nRegex iteration This method takes the last element and applies the Kleene star.\n\n#### `public def `[`reg_or`](#classpractice1_1_1nfa_1_1__CreateNFA_1a57eb512c08bd3207c3a41667f054dc65)`(self)` \n\nboolean 'or' for regular expressions This method takes the last two elements in stack and forks them into one block with the help of two additional states.\n\n# class `practice1::nfa::_Node` \n\nSection: Working with states of [NFA](#classpractice1_1_1nfa_1_1NFA).\n\nNode - state of NKA\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public  `[`final`](#classpractice1_1_1nfa_1_1__Node_1a46a85338742bf5c446ee7a462d658889) | \n`public def `[`__init__`](#classpractice1_1_1nfa_1_1__Node_1ae8d7d57832bfb87f45bdc9b6e8bfc030)`(self,`[`transitions`](#classpractice1_1_1nfa_1_1__Node_1a2594171e7c2a90ab61e43e1bc68adaf7)`,`[`final`](#classpractice1_1_1nfa_1_1__Node_1af28a838c358ed1f4ae4ebd0b702ea078)`)` | \n\n## Members\n\n#### `public  `[`final`](#classpractice1_1_1nfa_1_1__Node_1a46a85338742bf5c446ee7a462d658889) \n\n#### `public def `[`__init__`](#classpractice1_1_1nfa_1_1__Node_1ae8d7d57832bfb87f45bdc9b6e8bfc030)`(self,`[`transitions`](#classpractice1_1_1nfa_1_1__Node_1a2594171e7c2a90ab61e43e1bc68adaf7)`,`[`final`](#classpractice1_1_1nfa_1_1__Node_1af28a838c358ed1f4ae4ebd0b702ea078)`)` \n\n# class `practice1::nfa::NFA` \n\nSection: Working with [NFA](#classpractice1_1_1nfa_1_1NFA).\n\nNondeterministic finite automaton It consists of a list of states, in which, inside each state, all possible transitions to other states are stored, allowed by a regular expression specified by the user in reverse Polish notation.\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public  `[`nodes`](#classpractice1_1_1nfa_1_1NFA_1a6da5270e48c8b5c2f0dbaa008af4df76) | \n`public  `[`state`](#classpractice1_1_1nfa_1_1NFA_1adc6e5733fc3c22f0a7b2914188c49c90) | \n`public def `[`__init__`](#classpractice1_1_1nfa_1_1NFA_1a1be0698cef9313432d31dd5028cd7654)`(self,str reg_exp)` | Initialize method from a regExp in reverse Polish notation.\n`public bool `[`read`](#classpractice1_1_1nfa_1_1NFA_1a42f933055dd9fadc2a95f6f3484dc096)`(self,str string)` | Answers the question whether the string can be read by the [NFA](#classpractice1_1_1nfa_1_1NFA) This method uses the breadth-first search algorithm.\n\n## Members\n\n#### `public  `[`nodes`](#classpractice1_1_1nfa_1_1NFA_1a6da5270e48c8b5c2f0dbaa008af4df76) \n\n#### `public  `[`state`](#classpractice1_1_1nfa_1_1NFA_1adc6e5733fc3c22f0a7b2914188c49c90) \n\n#### `public def `[`__init__`](#classpractice1_1_1nfa_1_1NFA_1a1be0698cef9313432d31dd5028cd7654)`(self,str reg_exp)` \n\nInitialize method from a regExp in reverse Polish notation.\n\n#### Parameters\n* `reg_exp` regular expression given in reverse Polish notation\n\n#### `public bool `[`read`](#classpractice1_1_1nfa_1_1NFA_1a42f933055dd9fadc2a95f6f3484dc096)`(self,str string)` \n\nAnswers the question whether the string can be read by the [NFA](#classpractice1_1_1nfa_1_1NFA) This method uses the breadth-first search algorithm.\n\n#### Parameters\n* `string` the string passed by the user \n\n#### Returns\nTrue if the string can be read by an automaton \n\n#### Returns\nFalse if the string can't be read by an automaton\n\nGenerated by [Moxygen](https://sourcey.com/moxygen)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy-messer%2Fformal-languages-practice-1-task-13","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandy-messer%2Fformal-languages-practice-1-task-13","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy-messer%2Fformal-languages-practice-1-task-13/lists"}