introduction n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction PowerPoint Presentation
Download Presentation
Introduction

Loading in 2 Seconds...

play fullscreen
1 / 13

Introduction - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

Introduction. Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b} ):. - {a n b n : n = 0, 1, 2, …} - {w : w is palindrome word}.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction' - nyoko


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
introduction
Introduction
  • Finite Automata accept all regular languages and only regular languages
  • Even very simple languages are non regular ( = {a,b}):

- {anbn : n = 0, 1, 2, …}

- {w : w is palindrome word}

  • We are going to define a new class of languages, called context-free languages that contain all regular languages and many more (including the 2 above)
context free grammar preliminaries
Context-Free Grammar (preliminaries)
  • A context-free grammar is a kind of program
  • Languages that are generated by context-free grammars are called context-free languages
  • Context-free grammars are more expressive than finite automata: if a language L is accepted by a finite automata then L can be generated by a context-free grammar
my first context free grammar
My First Context-Free Grammar

S  bA

A  aA

A  b

  •  = {a,b}
  • Elements in  are called terminals
  • S and A are called variables
context free grammar cfg
Context-Free Grammar (CFG)
  • Definition. A context-free grammar (CFG) is a 4-tuple (V, , R, S), where:
  •  is an alphabet (characters  are called terminals)
  • V is a set (elements in NT are called variables)
  • R is a subset of NT  ( NT)*
  • S, the start variable, is one of the variables in NT
  • V   = 
  • If (,)  R, we write 
  •  is called a rule
derivations
Derivations
  • Definition. u yields v in one-step, written u  v, if: for some u,v in (V  )* the following 3 conditions hold:
    • u = xz
    • v = xz
    •  in R
  • Definition. u derives v, written u * v, if:
  • There is a chain of one-step yields of the form:
    • u  u1  u2  …  v
example 2
Example (2)
  • = {a,b}
  • V = {S}
  • R = { S aSb,
  • S e }
context free languages
Context-Free Languages

Definition. Given a context-free grammar

G = (V, , R, S), the language generated or

derived from G is the set:

L(G) = {w  *: }

S * w

Definition. A language L is context-free if there is a context-free grammar G = (, NT, R, S), such that L is generated from G

example 3
Example (3)
  • = {a,b}
  • NT = {S}
  • R = { S aS,
  • S  Sb,
  • S e}
example 4
Example (4)
  • = {a,b}

NT = {S}

R = { S aSa,

S  bSb,

S e}

parse tree

S

a

S

S

a

b

S

e

Parse Tree
  • A parse tree of a derivation u  u1  u2  …  v
  • is a tree in which:
    • Each internal node is labeled with a variable
    • If a rule A  A1A2…An occurs in the derivation then A is a parent node of nodes labeled A1, A2, …, An
leftmost rightmost derivations
Leftmost, Rightmost Derivations

Definition. A leftmost derivation of a sentential form is one in which rules transforming the left-most nonterminal are always applied

Definition. A rightmost derivation of a sentential form is one in which rules transforming the right-most nonterminal are always applied

ambiguous grammar
Ambiguous Grammar

Definition. A grammar G is ambiguous if there is a word w  L(G) having are least two different leftmost derivations

S  A

S  B

S  AB

A  aA

B  bB

A  e

B  e

  • Notice that the word a has at least two left-most derivations
  • Some ambiguous grammars G can be disambiguated:
    • find an unambiguous grammar G’ such that L(G) = L(G’)
  • Some languages cannot be disambiguated
chomsky normal form
Chomsky Normal Form
  • Definition: A grammar is in Chomsky Normal Form if every rule is of the form:
    • A  BC

(A, B, C variables; B and C are not the start variable)

    • A  a
    • S  e (S is the start variable)
  • Theorem: Any CFG G can be converted into a grammar G’ in Chomsky Normal Form such that L(G) = L(G’)
    • Add new rule S0 S (S0 is the new start variable)
    • Remove rules of the form A  e, and for every rule B  <…>A<…> add a new rule: B <…><…>
    • Remove rules of the form A  B and for every rule B  <…> add a new rule: A  <…>
    • Remove rules A  <C1|c1> …<Cn|cn> with n > 2 and add rules: A  <C1|c1> A1, A1  <C2|c2>, …, An-1  <Cn-1|cn-1> <Cn|cn>
    • Replace any rule: A  cAi with A  UAi, U  c

See example 2.10