CD5560
This presentation is the property of its rightful owner.
Sponsored Links
1 / 108

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University PowerPoint PPT Presentation


  • 40 Views
  • Uploaded on
  • Presentation posted in: General

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.

Download Presentation

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

CD5560

FABER

Formal Languages, Automata and Models of Computation

Lecture 8

Mälardalen University

2010


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

ContentContext-Free LanguagesPush-Down Automata, PDANPDA: Non-Deterministic PDAFormal Definitions for NPDAs NPDAs Accept Context-Free LanguagesConverting NPDA to Context-Free Grammar


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Non-regular languages

Context-Free Languages

Regular Languages


Context free languages

Context-Free Languages


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

stack

automaton

Context-Free Languages

Context-Free

Grammars

Pushdown

Automata

(CF grammars are

defined as generalized Regular Grammars)


Definition context free grammars

is string of variables and terminals

Definition: Context-Free Grammars

Grammar

Variables

Terminal

symbols

Start

variables

Productions of the form:


Definition regular grammars

is string of terminals

Definition: Regular Grammars

Grammar

Variables

Terminal

symbols

Start

variables

Right or Left Linear Grammars. Productions of the form:

or


Pushdown automata pdas

Pushdown AutomataPDAs


Pushdown automaton pda

Pushdown Automaton - PDA

Input String

Stack

States


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

The Stack

A PDA can write symbols on stack and read them later on.

POP reading symbol PUSH writing symbol

All access to the stack only on the top!

(Stack top is written leftmost in the string, e.g. yxz)

A stack is valuable as it can hold an unlimitedamount of (certain kind of) information.

The stack allows pushdown automata to recognize some non-regular languages.


The states

The States

Pop old- reading

stack symbol

Push new

- writing

stacksymbol

Input

symbol


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

input

stack

top

Replace

(An alternative is to start and finish with empty stack or a stack bottom symbol such as $)


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

stack

top

Push

input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

stack

top

Pop

input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

input

stack

top

No Change


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example 3.7 Salling:

A PDA for simple nested parenthesis strings

Time 0

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example 3.7

Time 1

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example 3.7

Time 2

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Stack

Example 3.7

Time 3

Input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Stack

Example 3.7

Time 4

Input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Stack

Example 3.7

Time 5

Input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example 3.7

Time 6

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example 3.7

Time 7

Input

Stack


Npdas non deterministic push down automata

NPDAsNon-deterministic Push-Down Automata


Non determinism

Non-Determinism


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A string is accepted if:

  • All the input is consumed

  • The last state is a final state

  • Stack is in the initial condition

  • (either: empty (when we started with empty stack),

  • or: bottom symbol reached, or similar)


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example NPDA

is the language accepted by the NPDA:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example NPDA

NPDAM

(Even-length palindromes)


Pushing strings

Pushing Strings

Pop

symbol

Input

symbol

Push

string


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example

input

pushed

string

stack

top

Push


Another npda example

Another NPDA example

NPDAM


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Execution Example

Time 0

Input

Stack

Current state


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 1

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 2

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 3

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 4

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 5

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 6

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 7

Input

Stack

accept


Formal definitions for npdas

Formal Definitions for NPDAs


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Transition function


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Transition function

new state

current state

current stack top

new stack top

current input symbol

An unspecified transition function is to the null set and represents a dead configuration for the NPDA.


Formal definition

Final

states

States

Input

alphabet

Stack

start

symbol

Transition

function

Stack

alphabet

Formal Definition

Non-Deterministic Pushdown Automaton NPDA


Instantaneous description

Instantaneous Description

Current

stack

contents

Current

state

Remaining

input


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example

Instantaneous Description

Input

Time 4:

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example

Instantaneous Description

Input

Time 5:

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

We write

Time 4

Time 5


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

A computation example


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

For convenience we write


Formal definition1

Formal Definition

Language of NPDAM

Initial state

Final state


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example

NPDAM


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

NPDAM


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Therefore:

NPDAM


Npdas accept context free languages

NPDAs Accept Context-Free Languages


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Theorem


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Proof - Step 1:

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Convert any context-free grammarGto a NPDA Mwith L(G) = L(M)


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Proof - Step 2:

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Convert any NPDA M to a context-free grammarGwith L(M) = L(G)


Converting context free grammars to npdas

Converting Context-Free Grammarsto NPDAs


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

An example grammar:

What is the equivalent NPDA?


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Grammar

NPDA


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

The NPDA simulates

leftmost derivations of the grammar

L(Grammar) = L(NPDA)


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Grammar:

A leftmost derivation:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

NPDA execution:

Time 0

Input

Stack

Start


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 1

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 2

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 3

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 4

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 5

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 6

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 7

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 8

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 9

Input

Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Time 10

Input

Stack

accept


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

In general

Given any grammarG

we can construct a NPDAMwith


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Constructing NPDAM from grammarG

Top-down parser

For any production

For any terminal


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Grammar G generates string w

if and only if

NPDA M accepts w


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

For any context-free language

there is an NPDA

that accepts the same language


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Which means


Converting npdas to context free grammars

Converting NPDAstoContext-Free Grammars


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

For any NPDA M

we will construct

a context-free grammar G with


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

The grammar simulates the machine

A derivation in Grammar

variables

terminals

Input processed

Stack contents

in NPDA M


Some simplifications

Some Simplifications

  • First we modify the NPDA so that

    • It has a single final state qf and

    • It empties the stack

    • when it accepts the input

Original NPDA

Empty Stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Second we modify the NPDA transitions.

All transitions will have form:

or

which means that each move

increases/decreases stack by a single symbol.


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

  • Those simplifications do not affect generality of our argument.

  • It can be shown that for any NPDA there exists an equivalent one having above two properties

  • i.e.

  • the equivalent NPDA with a single final state which empties its stack when it accepts the input, and which for each move increases/decreases stack by a single symbol.


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example of a NPDA in an appropriate form


The grammar construction

The Grammar Construction

In grammarG

Stack symbol

Variables:

states

Terminals:

Input symbols of NPDA


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

For each transition:

we add production:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

For each transition:

we add production:

for all statesqk , ql


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Stack bottom symbol

Start Variable

Start state

(Single) Final state


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example

Grammar production:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Grammar productions:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Grammar production:


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Resulting Grammar


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Resulting Grammar, cont.


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Resulting Grammar, cont.


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Derivation of string


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

In general, in grammar:

if and only if

is accepted by the NPDA


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Explanation

By construction of Grammar:

if and only if

in the NPDA going from qito qj

the stack doesn’t change below

and A is removed from stack


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

We have shown the procedure to convert

any NPDA Mto a context-free

grammar G with L(M) = L(G)

which means


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Therefore

END OF PROOF


Cd5560 faber formal languages automata and models of computation lecture 8 m lardalen university

Example (Sudkamp 8.1.2)

Language consisting solely of a’s or an equal number of a´s and b´s.


  • Login