formal grammars and abstract machines

85
Formal Grammars and Abstract Machines Sahar Al Seesi

Upload: others

Post on 05-Dec-2021

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Formal Grammars and Abstract Machines

Formal Grammars and Abstract Machines

Sahar Al Seesi

Page 2: Formal Grammars and Abstract Machines

What are Formal Languages

• Describing the sentence structure of a language in a formal way

• Used in – Natural Language Processing Applications (translators,

grammar checking tools, etc..) • Language: English, French, Spanish, Chinese, etc..

– RNA/Protein Structure Analysis • RNA in general, ribosomal RNA, protein, etc..

– Compilers for programming languages • C, Java, Python, Linux shell script, Assembly, etc..

• To build a program for any of the above applications, the language rules must be described in a formal inclusive way.

Page 3: Formal Grammars and Abstract Machines

Formal Languages and Grammars

• G={ Σ, R, S }

• Σ : Non-terminals (NT) Terminals (T) {S, VERB, SUBJECT, OBJECT} {children, sam, play, eat, ball} {S, A1, A2} {a, c, g, t} {a,c,g,u}

• R : Production rules {S SUBJECT VERB OBJECT}

• S : Starting symbol

• L(G) : The language defined by G; a finite or infinite set of strings (words/sentences)

• L(G) ⊆ T*

Page 4: Formal Grammars and Abstract Machines

Chomsky Hierarchy

Regular

Context-free

Context-sensitive

Unrestricted Grammars Recursively Enumerable Languages

Pow

er o

f ex

pre

ssio

n

Ru

le c

om

ple

xity

Pa

rsin

g ti

me

com

ple

xity

Page 5: Formal Grammars and Abstract Machines

Parsing/Accepting Abstract Machines

Grammar Parsing Automaton

Regular grammars Finite State Machine (FSM)

Context free grammars Push-Down Automaton (PDA)

Context sensitive grammars Linear-Bounded Automaton (LBA)

Unrestricted grammars Turing Machine (TM)

Page 6: Formal Grammars and Abstract Machines

Regular Languages & Regular Expressions

• A regular language can be represented by a regular expression

• Let Σ = {a,b} • Let Lr be the language defined by regular

expression r. r Lr

Σ* the set of all strings over Σ of length 0 or more (includes the empty string, ) Σ+ the set of all strings over Σ of length 1 or more (does not include ) a+ the set of all strings of 1 or more a’s {a, aa, aaa, …} b* the set of all strings of 0 or more b’s {, b, bb, bbb, …}

Page 7: Formal Grammars and Abstract Machines

Combining Regular Languages

• Concatenation

– Let r and s be 2 regular expressions, rs corresponds to the language LrLs

– Example:

• r = a*, s = b+

• LrLs : the set of strings consisting of 0 or more a’s followed by 1 or more b’s

• {b, bb, ab, aabbbb} ⊂ LrLs

Page 8: Formal Grammars and Abstract Machines

Combining Regular Languages

• Union

– Let r and s be 2 regular expressions, r+s corresponds to the language Lr∪Ls

– Example:

• r = a*, s = b+

• Lr∪Ls : the set of strings consisting of 0 or more a’s and strings of 1 or more b’s

• {b, bb, a, aa, bbbb} ⊂Lr ∪ Ls

Page 9: Formal Grammars and Abstract Machines

Combining Regular Languages

• Closure

– Let r be a regular expression, r* corresponds to the language Lr*

– Example:

• r = ab

• Lr* : the set of strings consisting of 0 or more “ab”s (ab)*

• {, ab, abab, abab, ababab} ⊂ Lr*

Page 10: Formal Grammars and Abstract Machines

Example

• R = (a+c+t)ykk(p+q)*vdt(l+z+)pq

• Strings that belong to the language defined by R

ayykppvdtlpq

cyykpqppqvdtpq

tyykqvdtzpq

Page 11: Formal Grammars and Abstract Machines

Regular Grammars

• Can be represented by a regular expression

• Grammar rules are of the form NT T NT

NT T

• Example: The set of all DNA strings

• Regular Expression: {a,c,g,t}+

• G= { Σ, {S}, R, S }

• Σ = {S, a, c, g, t}

• R = {S aS | cS | gS | tS | a | c | g | t}

Page 12: Formal Grammars and Abstract Machines

Finite State Machine

• M={Q, Σ, , q0, F}

• Q: Finite set of states

• Σ: Language alphabet

• : Transition function (Qx Σ Q)

• q0 : Starting state

• F : Set of final states

Page 13: Formal Grammars and Abstract Machines

Finite State Machine Example • M={Q, Σ, , q0, F}

• A FSM for

R = {S aS | cS | gS | tS | a | c | g | t}

2

a,c,g,t

Q = {1,2} Σ = {a, c, g, t}

q0 = 1 F = {2}

(1,a) = 2 (1,c) = 2

(1,g) = 2 (1,t) = 2

(2,a) = 2 (2,c) = 2

(2,g) = 2 (2,t) = 2

a,c,g,t 1

Page 14: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input1: 0100

Page 15: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input1: 0100

Page 16: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input: 0100

Page 17: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input1: 0100

Page 18: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input1: 0100

Page 19: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input1: 0100

Page 20: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 21: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 22: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 23: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 24: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 25: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input2: 1101

Page 26: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input3: 11011

Page 27: Formal Grammars and Abstract Machines

Another Example

L = The set of all strings in {0,1}*that either begin or end (or both) with 01

R = (01(0+1)*)+((0+1)*01)

S B A

E C D

1

0

1

1

1

1 0

0,1

0

0

0

Input3: 11011

Page 28: Formal Grammars and Abstract Machines

Context Free Grammars (CFG) and Languages

• CFGs Can represent nested pair-wise correlation between terminal symbols in the string

• Famous example: palindrome language (wwr) a b a a a a b a

• Can you write a regular grammar for wwr?

• Grammar rules are of the form – NT (T+NT)+

Page 29: Formal Grammars and Abstract Machines

• M={Q, Σ, , , q0, F}

• Q: Finite set of states

• Σ: Language alphabet

• : Stack alphabet

• : Transition function (Q x Σ x Q x *)

• q0 : Starting state

• F : Set of final states

CFG and Push Down Automata

http://epsilonvectorplusplus.wordpress.com

Page 30: Formal Grammars and Abstract Machines

Grammar wwr

• G={ Σ, V, R, S }

• Σ = {a, b} , V = {S}

• R = {S aSa| bSb | aa | bb}

Parse tree for string: abbbba

S

a S a

b S b

b b

Page 31: Formal Grammars and Abstract Machines

Context Free Grammar for an RNA stem loop

• Language : wvwcr

• G={ Σ, R, S }

• Σ = {S, L, a, c, g, u}

• R = {S aSu| uSa | gSc | cSg | L,

L aL | cL | gL | uL | a |c |g | u}

Durbin et. al., Biological Sequence Analysis, adapted

Page 32: Formal Grammars and Abstract Machines

Context Sensitive Grammars and Languages

• Can represent crossing pair-wise correlation between terminal symbols in the string

• Famous example: copy language (ww) a a b b a a b b

• Grammar rules are of the form:

– (T+NT)*NT (T+NT)* (T+NT)+

– |LHS| <= |RHS| (generated RHS cannot shrink from one production step to the next)

Page 33: Formal Grammars and Abstract Machines

CSG and Linear Bounded Automata

SKIP FOR NOW

Page 34: Formal Grammars and Abstract Machines

Non-deterministic and stochastic models

• A stochastic grammar has a probability associated with each rule in the grammar

• Similarly, in automata, a probability would be associated with each transition

Page 35: Formal Grammars and Abstract Machines

Unrestricted Grammars and Recursively Enumerable Languages

• Grammar rules are of the form:

- (T+NT)*NT (T+NT)* (T+NT)*

- The only rule is that the left hand side must

contain at least one variable

• A recursively enumerable language is one that can be represented by an unrestricted grammar

Page 36: Formal Grammars and Abstract Machines

• M={Q, Σ, , , q0, B, F}

• Q: Finite set of states

• Σ: Language alphabet

• : tape alphabet (Σ ⊆ )

• : Transition function (Q x Σ Q x x {L,R})

• q0 : Starting state

• B: The blank symbol

• F : Set of final states

Turing Machines

Page 37: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

Page 38: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # a a b b # # # # # # #

Page 39: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X a b b # # # # # # #

Page 40: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X a b b # # # # # # #

Page 41: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X a Y b # # # # # # #

Page 42: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X a Y b # # # # # # #

Page 43: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X a Y b # # # # # # #

Page 44: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y b # # # # # # #

Page 45: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y b # # # # # # #

Page 46: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 47: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 48: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 49: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 50: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 51: Formal Grammars and Abstract Machines

Example

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X X Y Y # # # # # # #

Page 52: Formal Grammars and Abstract Machines

What is the language this TM accepts?

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

Page 53: Formal Grammars and Abstract Machines

Example -cont. (input 2)

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # a b a b # # # # # # #

Page 54: Formal Grammars and Abstract Machines

Example -cont. (input 2)

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X b a b # # # # # # #

Page 55: Formal Grammars and Abstract Machines

Example -cont. (input 2)

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X Y a b # # # # # # #

Page 56: Formal Grammars and Abstract Machines

Example -cont. (input 2)

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X Y a b # # # # # # #

Page 57: Formal Grammars and Abstract Machines

Example -cont. (input 2)

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

# # # # X Y a b # # # # # # #

Page 58: Formal Grammars and Abstract Machines

Language: anbn

q0 q1 q2 q3 q4

a/X,R

Y/Y,R

b/Y,L

a/a,R Y/Y,R

a/a,L Y/Y,L

X/X,R

Y/Y,R

#/#,R

Page 59: Formal Grammars and Abstract Machines

Computing with Turing Machines

Examples: A TM that accepts a number x divisible by 3 in unary format and outputs the results of the computation x/3

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 60: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # 111111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 61: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # X11111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 62: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XX1111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 63: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 64: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 65: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 66: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 67: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # # # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 68: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 69: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 70: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 71: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 72: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 73: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXX111 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 74: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXX11 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 75: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXX1 # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 76: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 77: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 78: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 1 # # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 79: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 11 # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 80: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 11 # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 81: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 11 # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 82: Formal Grammars and Abstract Machines

Divide by 3 TM

# # # # XXXXXX # 11 # # # #

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 83: Formal Grammars and Abstract Machines

Divide by 3 TM Try to parse 1111

q0 q1 q2 q3 q5 1/X,R 1/X,R

1/1,R

#/#,R q4

1/X,R

1/1,R

#/1,L

1/1,L

q6

#/#,L

q8

X/X,R

q7

1/1,L

1/1,L X/X,R

Page 84: Formal Grammars and Abstract Machines

More complex TM models

• Several tapes

• Several read/write heads

A Turing machine can simulate a computer.

Page 85: Formal Grammars and Abstract Machines

Back to Linear Bounded Automata

state

$ $

boundary boundary

• LBA is a TM whose read/write head never moves off the portion of the tape occupied by the input string