CS25 Lecture Presentation 6

Embed Size (px)

Citation preview

  • 7/24/2019 CS25 Lecture Presentation 6

    1/20

    1

    CS 25Automata Theory & Formal Languages

    Lecture 6

  • 7/24/2019 CS25 Lecture Presentation 6

    2/20

    PUSHDOWN AUTOMATA

    The PDA is an automaton equivalent to the CFG inlanguage-deining !o"e#$

    Only the nondeterministic PDA defines all the CFLs.

    But the deterministic version models parsers. Most programming languages have deterministicPDAs.

  • 7/24/2019 CS25 Lecture Presentation 6

    3/20

    PUSHDOWN AUTOMATA

    A !ushdo"n automata %PDA& is essentiall' an NFA "ith asta()$

    On a t#ansition the PDA*

    +$ Consumes an in!ut s'm,ol$

    $ Goes to a ne" state %o# sta's in the old&$

    .$ /e!la(es the to! o the sta() ,' an' st#ing %does nothing0 !o!sthe sta()0 o# !ushes a st#ing onto the sta()&

  • 7/24/2019 CS25 Lecture Presentation 6

    4/20

    PUSHDOWN AUTOMATA

    Schematic of a pushdown automaton

  • 7/24/2019 CS25 Lecture Presentation 6

    5/20

    FO/MA1 D2F3N3T3ON OF APUSHDOWN AUTOMATON %PDA&

    A !ushdo"n automaton is a 4-tu!le (Q, , !,

    , "#, F)0 "he#eQ, , !and Fa#e all inite sets0 and

    $% Qis the set o states

    2% is the in!ut al!ha,et

    % !is the sta() al!ha,et

    : Q ' ( ' !() *+Q ' !(is the t#ansition un(tion

    5% "#Qis the sta#t state0 and

    -% FQis the set o a((e!t states

  • 7/24/2019 CS25 Lecture Presentation 6

    6/20

    FO/MA1 D2F3N3T3ON OF APUSHDOWN AUTOMATON %PDA&

    TRANSITION FUNCTION : Q ' ( ' !() *+Q ' !(

    a!es three arguments"

    #. A state$ in Q.

    %. An input$ &hich is either a sym'ol in or .

    (. A stac! sym'ol in .

    )", a, .* is a set of +ero or more actions of the form

    )p, *.

    pis a state, is a string of stac! sym'ols.

  • 7/24/2019 CS25 Lecture Presentation 6

    7/20

    FO/MA1 D2F3N3T3ON OF APUSHDOWN AUTOMATON %PDA&

    Actions of the PDA

    -f )", a, .* contains )p, * among its actions$ then one thingthe PDA can do in state q$ &ith a at the front of the input$

    andZon top of the stac!is"#. Change the state top.

    %. emove a from the front of the input )'ut a may 'e *.

    (. eplaceZon the top of the stac! 'y .

  • 7/24/2019 CS25 Lecture Presentation 6

    8/20

    25AMP12 OF PUSHDOWN AUTOMATA

    EXAMPLE 1* A o#mal des(#i!tion o the PDA o# the language {0n1n|n 0}

    1et *+,e %60 70 800 q+0 F&0 "he#e

    6 9 :q+0 q0 q.0 q;