Author: Andreas Slovacek Date: 23 September 2018
Please see ./html/index.html for Doxygen generation. It is complete documentation.
Functions are listed in the order they are called.
Master script. Reads directories and passes definition files to FA constructor and string processor
run(self)
calls sub-functions
build_fas(self)
calls sub-function to scan directory for .fa files, then
passes those to the FA constructorget_input_strings(self,input_file)
creates an iterable list of all strings
from input.txtprocess_string()
Implementation of NFA. DFA functionality handled the same as the NFA, except strings containing epsilon transitions aren't processed.
process_def(self,from_file)
set's up a Finite Automaton based on a .fa files
definition.
fa_type()
determines the type of the FA by checking duplicate transitions,
epsilon tranisitons, invalid accepts states, accept state range, state rangeset_alphabet()
extracts the alphabet from the transition tableset_states()
extracts the states from the transition tableget_dupe_set()
extracts duplicate transitions from the transition tableprocess_string(in_string)
used to test strings in the FA. The current states
is reset with every string processed. IF-ELIF-ELSE finds reasons to cease
processing. Otherwise process the string, check if it ended in an accept
state, and save the string if it did.
self.strings_processed
tracks how many strings this FA has processednext_state_recurse(in_str)
recursively processes the string and shifts
statesfinalize_fa()
Logs the FA values in results/basename.log and echos the
accepted strings into results/basename.txt. Called from fa_master.py
print_self()
Call after process_def
to print the FA to CLI
Handles file and directory operations.
log_FA(FA)
Takes an FA as parameter, sets up and writes log files
set_filenames(filename)
creates a directory for results if needed and
sets directory/filenames for the .log and .txt file associated with this FAremove_previous_files()
deletes any existing .log and .txt filescreate_log_file(FA)
writes (Valid,States,Alphabet,Accepted Strings) to
.log file with input parameter FA's member variablescreate_txt_file(FA)
writes accepted strings to .txt with input parameter
FA's member variablesCleans residual .log and .txt files in PJ01/results
Contains the Python files
Contains the output .log and .txt files generated in fa_logger.py
Finite Automaton creator and classifier based on PJ01.pdf
In this project you will write a program that will read a simplified description of a finite automaton, validate it, and then simulate it on each string read from an input text file. Each string that is accepted by the DFA will be echoed to a text file; in addition each machine will have a log file prepared containing specific pieces of information.
To avoid operating-specific case-sensitivity issues, all filenames will be all lowercase. So that all of the files can be in the same directory and the following naming conventions will be used: