Example #1
0
 def nfa_maker(self):
     self.get_alph()
     self.my_nfa = NFA([])
     self.get_parts()
     states = self.exp_parts(self.regex, 0)
     self.my_nfa.states = states
     self.my_nfa.alphabet = list(self.alphabet)
Example #2
0
def test1():
    s0 = state(0)
    s1 = state(1)
    s0.outpaths = {'b': [s0, s1]}
    s1.outpaths = {'a': [s1], 'b': [s0]}
    n = NFA([s0, s1])
    n.start_states = [s0]
    n.accept_states = [s1]
    n.alphabet = ['a', 'b']
    n.nfa_to_dfa()
    n.my_dfa.print_dfa()
    """
Example #3
0
import pytest

from automata.language import generate_language, language_over_range
from automata.nfa import NFA

automaton: NFA = NFA(**pytest.automata_config)


def test_generate_language():
    assert generate_language(automaton, 1) == ["a"]


def test_language_over_range():
    assert language_over_range(automaton, 3) == [
        ["a"],
        ["aa"],
        ["aaa"],
    ]
Example #4
0
    print(f"[--- language: {args.configFile}: ---]")

    for n, row in enumerate(data):

        print(
            f"length: {n+1:02}\t language: |{len(row):05}| : {row[:5]}{'...' if len(row) > 5 else ''}"
        )

    print(f"[--- duration: {duration:2.4f} sec ---]\n")


#
#
#  -------- __main__ -----------
#
if __name__ == "__main__":

    # collect terminal parameters
    args = parser.parse_args()

    # load JSON config
    with open(args.configFile) as json_file:
        config = json.load(json_file)

    # init automaton
    automaton: NFA = NFA(**config)

    # run tasks
    task__ambiguity_over_range(automaton, args.length)
    task__language_over_range(automaton, args.length)