• Nem Talált Eredményt

LászlóKabódi Languagesandautomata

N/A
N/A
Protected

Academic year: 2022

Ossza meg "LászlóKabódi Languagesandautomata"

Copied!
22
0
0

Teljes szövegt

(1)

Languages and automata

László Kabódi

(2)

Chomsky hierarchy

Chomsky hierarchy - Type-3

I also called Regular grammars

I Can have only two types of rules (A andB are non-terminals, a is a terminal):

I AaB I Aa

I Is the starting symbol S is not on the right hand side of any rule, there can be S →ε

(3)

Chomsky hierarchy

Chomsky hierarchy - Type-2

I also called Context-free grammars

I Can have only one type of rule (A is a non-terminal,

α∈(V ∪Σ)+ is a string of terminals and/or non-terminals):

I Aα

I If the starting symbolS is not on the right hand side of any rule, there can be S →ε

I It is called context-free, because you can use a rule to change a non-terminalA regardless of the context, the terminals and non-terminals next toA

(4)

Chomsky hierarchy

Chomsky hierarchy - Type-1

I also called Context sensitive grammars

I Can have only one type of rule (A is a non-terminal,

α∈(V ∪Σ)+, β, γ∈(V ∪Σ) are strings of terminals and/or non-terminals):

I βAγβαγ

I It is called context sensitive, because you can only change a non-terminalA toα in the right context, if there isβ before andγ after A.

(5)

Chomsky hierarchy

Chomsky hierarchy - Type-0

I Every other grammar

I a languageL is a Type-i language if there is a grammar that is Type-i, but there is no Type-i+1 grammar

(6)

Examples

Examples for regular grammars

1. Create a regular grammar forL={a,b}!

2. Is there a regular grammar for all languages that contain nite number of words?

3. Create a regular grammar for the language that contain the even length words!

(7)

Examples

Solutions

1. Create a regular grammar forL={a,b}! S →ε|aA|bA|a|b

A→aA|bA|a|b

2. Is there a regular grammar for all languages that contain nite number of words?

Yes, there is. You can break up the rules in the non-regular grammar for the same language.

3. Create a regular grammar for the language that contain the even length words!

S →aA|bA A→aS|bS|a|b

(8)

Regular grammars and regular languages

I Theorem: For every nite automaton M there is anM0 nite automaton where the initial state does not appear later.

I Proof: Create a new state S0, redirect all transitions that would go to the initial state S to go to S0. The transitions fromS0 are the same as from S. If S is also an accepting state, make S0 an accepting state.

(9)

Regular grammars and regular languages

Regular grammars and regular languages

I Theorem: The language Lis regular if and only if there is a regular grammar G for it (L(G) =L).

I The proof has two parts:

I If a languageLis regular, then there is a regular grammar for it.

I For a regular grammar, there is a nite automaton that accepts the same language.

I If we prove both of these, that means, that regular grammars and regular languages are the same set of languages.

(10)

Regular grammars and regular languages

Language L is regular ⇒ there is a regular grammar for L

I If Lis regular, then there is a nite automatonM for it, where L(M) =L. (Withoutεtransitions.)

I Let thisM be one, where the initial state does not appear later.

I We can create a regular grammar from this automaton:

I We create a non-terminal from each state otM. The starting non-terminal is from the initial state.

I From every transition we create one or two deduction rules.

(11)

Regular grammars and regular languages

Deduction rules from transitions

I A a B

: AA →aAB I A a B

: AA →aAB|a

I If the initial state is an accepting state: S →ε

I The grammar will be a regular grammar, because all the rules are inA→aB or A→a form.

I The accepted language will be the same, because the rules follow the transitions. We only nish a derivation with a deduction rule created form an accepting state.

(12)

Regular grammars and regular languages

There is a regular grammar for L ⇒ L is a regular language

I We do the inverse of the previous algorithm.

I Create a state for every non-terminal, and a plus stateF, that will be the only accepting state.

I For every ruleA→aB create a transition A a B

I For every ruleA→acreate a transition A a F I If there isS →ε, stateS will be an accepting state. (Because

this rule only allowed if S is not on the right hand side of any other rule, this won't accept unwanted words.)

(13)

Examples

Example I

Create a regular grammar from the following nite automaton:

S

A

B

C

D a

b

a a

a

b b a

(14)

Examples

Solution I

S

A

B

C

D a

b

a a

a

b b a

S →aA|bB A→aC|a

B →aA|aC|bD|a|b C →aD|a

D →bC|b

(15)

Examples

Example II

Create a regular grammar from the following nite automaton:

S

A

B

C

D E

a

b a

a

b b

b

a

b

(16)

Examples

Solution II

First, change the automaton, becauseS has incoming transitions:

S

S0 A

B C

E a

b a

b a

a b

b b

a

S →ε|aA|a|bE|b A→aC|a|aS0|bB B →bS0|bD|b C →aC|a D →bD|b

(17)

Examples

Example III

Create a regular grammar from the following nite automaton:

A B C

D 0

1 0

1 0 1

0, 1

(18)

Examples

Solution III

A B C

D 0

1 0

1 0 1

0, 1

A→0B|1D|0 B →0D|1C C →0B|1D|0 D →0D|1D

(19)

Examples

Example IV

Create a nite automaton from the following regular grammar:

S →ε|aB|bC A→aB|a B→bA|b C →bB|aA

(20)

Examples

Solution IV

S →ε|aB|bC A→aB|a B →bA|b C →bB|aA

S

B

C

A F

a

b

b b

a

a

a b

(21)

Examples

Example V

Create a nite automaton from the following regular grammar:

S →aA|bB|b A→aS|bC B→aC|bS C →aB|bA|a

(22)

Examples

Solution V

S →aA|bB|b A→aS|bC B →aC|bS C →aB|bA|a

S F

A

B

C a

b b a

b

a

b a

b a

Hivatkozások

KAPCSOLÓDÓ DOKUMENTUMOK

Here we consider SCGs in a more general form: each rule is associated with two sets of words P and Q, and such a rule can be applied to a sentential form u only if every word of P is

In addition, we created an application based on this measure created by junior high school students (Figure 4). Through these opportunities, we would like to examine

working with language classes, rule- based system classes, or predefined components, we ensure that (i) the verification of the rule-based system requires less complexity

If the Turing machine have a time complexity f (n) then it stops in nite steps fot all inputs4. So it

I check is the input consists of word pairs, if not stop and reject I otherwise it tries all the 1 element index lists then 2 element. index lists and

I If L 1 is regular, there is a nite automaton M 1 for it I Create ε transitions from the accepting states to the

Accepting the proposal of the EU and the International Union of Railways (UIC), the Austrian Federal Railways (ÖBB) and the Hungarian State Railways (MÁV) agreed that with

The Coriolis forces effect only the transverse vibration of the fluid- -conveying pipe therefore we show only the derivation of finite element for- mulation of