Context-free Grammars - PowerPoint PPT Presentation

About This Presentation
Title:

Context-free Grammars

Description:

... can be viewed as a notation for describing a family of recognition algorithms. ... v in CFG, if there is a finite sequence of rule applications such that: ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 22
Provided by: csWr
Learn more at: http://cecs.wright.edu
Category:

less

Transcript and Presenter's Notes

Title: Context-free Grammars


1
Context-free Grammars
2
  • Recursive definition
  • Grammar
  • Derivation

3
  • What is the syntax of the description
    (meta-language)?
  • External form of the grammar
  • How do we associate a language with such a
    description?
  • Semantics or use of the grammar
  • Generators Grammars specify languages by
    generating strings in the language.
  • Recognizers Grammars can be viewed as a notation
    for describing a family of recognition algorithms.

4
CFG (V, ,P,S)
  • V Finite set of variables/non-terminals
  • Alphabet/Finite set of terminals
  • P Finite set of rules/productions
  • S Start symbol

5
  • a represents a context-free language because we
    can write a CFG for it.
  • A-rule, null-rule,
    -rule.
  • Context-freeness An A-rule can be applied
    whenever A occurs in a string, irrespective of
    the context (that is, non-terminals and terminals
    around A).
  • Cf. context-sensitive grammar (declare-use)

6
From CFG to Language
  • One-step Derivation (Defn 3.1.2)
  • w is derivable from v in CFG, if there is a
    finite sequence of rule applications such that

7
  • Let G(V, S, P, S) be a CFG.
  • is a sentential form,
    if
  • .
  • is a sentence, if
    .
  • The language of G,
  • L(G)

8
  • Derivation of aabb
  • Derivation tree

l
9
(No Transcript)
10
Derivation Tree (abstracts derivation)
S
A
B
A
B
b
a
l
l
11
Examples CFGs and CFLs
12
(No Transcript)
13
Note that parentheses are part of the
meta-language.
14
(No Transcript)
15
(No Transcript)
16
Left to right generation of string.
17
Regular Grammar
  • A regular grammar is a CFG in which each of the
    rules has the form
  • (Right Linear Grammar)

18
Equivalent Regular Grammar
  • A regular grammar is a CFG in which each of the
    rules has the form
  • (Left Linear Grammar)

19
(No Transcript)
20
(No Transcript)
21
Derivations
Note that the above result does not hold for
sentential forms.
Write a Comment
User Comments (0)
About PowerShow.com