1

I have been asked to construct a NPDA that accepts the following language L = {anb2n : n ≥ 1}. I have completed the written assignment portion and after testing it thoroughly i am sure that my NPDA is correct. Here is an image using JFLAP:

    [enter image description here][1]

The struggle that i am running into is the confusion of understanding what the python syntax of this library. I haven't used it before, so it is new to me. For the documentation, i have visited this website: https://pypi.org/project/automata-lib/

The following is an example code listed on the website, that accepts a palindrome {wwR | w is an element of {a.b}* }. Although i understand how i might work this out on paper, I cannot seem to follow this syntax below. I apologize now for my foolishness in advance.

npda = NPDA(
    states={'q0', 'q1', 'q2'},
    input_symbols={'a', 'b'},
    stack_symbols={'A', 'B', '#'},
    transitions={
        'q0': {
            '': {
                '#': {('q2', '#')},
            },
            'a': {
                '#': {('q0', ('A', '#'))},
                'A': {
                    ('q0', ('A', 'A')),
                    ('q1', ''),
                },
                'B': {('q0', ('A', 'B'))},
            },
            'b': {
                '#': {('q0', ('B', '#'))},
                'A': {('q0', ('B', 'A'))},
                'B': {
                    ('q0', ('B', 'B')),
                    ('q1', ''),
                },
            },
        },
        'q1': {
            '': {'#': {('q2', '#')}},
            'a': {'A': {('q1', '')}},
            'b': {'B': {('q1', '')}},
        },
    },
    initial_state='q0',
    initial_stack_symbol='#',
    final_states={'q2'},
    acceptance_mode='final_state'
)

i have not tried anything that makes sense, because i am struggling with understanding whats being popped and pushed from the stack when an input is being seen during computation.

0 Answers0