CS 126 Lecture T3: Formal Languages Outline Introduction Defining - - PowerPoint PPT Presentation

cs 126 lecture t3 formal languages outline
SMART_READER_LITE
LIVE PREVIEW

CS 126 Lecture T3: Formal Languages Outline Introduction Defining - - PowerPoint PPT Presentation

CS 126 Lecture T3: Formal Languages Outline Introduction Defining grammar Type 3 grammars Type 2 grammars Chomsky hierarchy Conclusions CS126 16-1 Randy Wang Where We Are T1 - Simplest language generators: regular


slide-1
SLIDE 1

CS 126 Lecture T3: Formal Languages

slide-2
SLIDE 2

CS126 16-1 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-3
SLIDE 3

CS126 16-2 Randy Wang

Where We Are

  • T1
  • Simplest language generators: regular expressions
  • Simplest language recognizer: FSAs
  • T2: more powerful machines
  • FSA, NFSA
  • PDA, NPDA
  • TM
  • T3: more powerful languages associated with the more

powerful machines

  • T4:
  • Nature of most powerful machines
  • Languages that no machine can ever deal with
slide-4
SLIDE 4

CS126 16-3 Randy Wang

Review: Formal Languages

  • Formal definitions
  • An alphabet: a finite set of symbols
  • A string: a finite sequence of symbols from the alphabet
  • A language: a (potentially infinite) set of strings over an

alphabet

  • Intriguing topic: finite representation of a language
  • How?

+ language generators (a set of rules for producing strings) + language recognizers

slide-5
SLIDE 5

CS126 16-4 Randy Wang

Languages and Automata

slide-6
SLIDE 6

CS126 16-5 Randy Wang

Why Learn Languages?

slide-7
SLIDE 7

CS126 16-6 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-8
SLIDE 8
slide-9
SLIDE 9

CS126 16-8 Randy Wang

Example 1

slide-10
SLIDE 10

CS126 16-9 Randy Wang

Example 1 (cont.)

slide-11
SLIDE 11

CS126 16-10 Randy Wang

Example 2

slide-12
SLIDE 12

CS126 16-11 Randy Wang

Example 2 (cont.)

if (x == 0) { while (y == 1) { if (z > 0) { s = z * 2; } } }

| <iteration-stmt> | ...

Each box is one production.

slide-13
SLIDE 13

CS126 16-12 Randy Wang

Example 3

slide-14
SLIDE 14

CS126 16-13 Randy Wang

Example 3 (cont.)

slide-15
SLIDE 15

CS126 16-14 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-16
SLIDE 16

CS126 16-15 Randy Wang

Type 3 Grammars

slide-17
SLIDE 17

CS126 16-16 Randy Wang

Type 3 Grammars and Regular Expressions

slide-18
SLIDE 18

CS126 16-17 Randy Wang

Example

<A> -> <z>0 <z> -> <A>1 <z> -> ε

F A z S

ε ε

1

slide-19
SLIDE 19

CS126 16-18 Randy Wang

Demo: Construction of Equivalent FSA

slide-20
SLIDE 20

CS126 16-19 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-21
SLIDE 21

CS126 16-20 Randy Wang

Context-Free Grammars

slide-22
SLIDE 22

CS126 16-21 Randy Wang

Example Context-Free Grammar

if (x == 0) { while (y == 1) { if (z > 0) { s = z * 2; } } }

| <iteration-stmt> | ...

Each box is one production.

slide-23
SLIDE 23

CS126 16-22 Randy Wang

How to Recognize Context-Free Grammars

slide-24
SLIDE 24

CS126 16-23 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-25
SLIDE 25

CS126 16-24 Randy Wang

Type 1 Grammars (Context-Sensitive) and Type 0 Grammars

slide-26
SLIDE 26

CS126 16-25 Randy Wang

Chomsky Hierarchy, Languages and Automata

slide-27
SLIDE 27

CS126 16-26 Randy Wang

Language Expressiveness and Machine Power

slide-28
SLIDE 28

CS126 16-27 Randy Wang

Example Language Outside Chomsky Hierarchy: Lindenmayer Systems

Reproduction Growth

slide-29
SLIDE 29

CS126 16-28 Randy Wang

Graftal Plants: Lindenmayer in 2D

“Production” rules: add one to each segment of my trunk; replace each branch with myself of prev generation

slide-30
SLIDE 30

CS126 16-29 Randy Wang

Outline

  • Introduction
  • Defining grammar
  • Type 3 grammars
  • Type 2 grammars
  • Chomsky hierarchy
  • Conclusions
slide-31
SLIDE 31

CS126 16-30 Randy Wang

More on Languages, Machines, and Life

  • The fine art of describing infinite beauty and variety with

finite representation

  • Shakespearean sonnets and machines that can identify

authorship? (Is intelligence/art nothing but a set of rules, with some non- determinism thrown in?)

  • DNA: the language of life

(Is life nothing but a set of rules, with some non-determinism thrown in?)

  • ......
slide-32
SLIDE 32

CS126 16-31 Randy Wang

What We Have Learned Today

  • What is a grammar?
  • What is a type 3 grammar? type 2? type 1? type 0?
  • How to construct an FSA from a type 3 grammar?
  • What is the Chomsky Hierarchy?
  • What type of automata recognize which grammars?