MC 306 Theory of Computation Thursday, 101603 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

MC 306 Theory of Computation Thursday, 101603

Description:

A grammar generates strings by repeatedly applying rules: ... The language of the grammar G, denoted L(G), is the set of strings over that can ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 10
Provided by: skid
Category:

less

Transcript and Presenter's Notes

Title: MC 306 Theory of Computation Thursday, 101603


1
MC 306 Theory of ComputationThursday, 10/16/03
  • Last time
  • Pumping Lemma
  • Todays Class
  • More on Pumping Lemma, non-regular languages
  • New Chapter!
  • Context-free Languages
  • Reading 3.1
  • Exercises p. 110 1, 2, 5
  • New hand-in problems pp. 110-111 3, 8

2
Regular languages
  • So far Regular languages
  • Described by regular expressions
  • Accepted by finite automata
  • Applications
  • Pattern matching in searches
  • Lexical analysis of programming languages
  • Limitations Lots of reasonable languages are not
    regular
  • Example Cant test for balanced parentheses
    using regular expressions or FAs
  • Example Cant test for primality using FAs

3
Context-free languages
  • Context-free languages
  • Described by context-free grammars
  • Accepted by pushdown automata
  • Properties and Applications
  • Developed originally for study of human languages
  • Used for describing and checking syntax of
    programming languages in compiler design
  • Contain regular languages as a subclass
  • Still does not describe all possible languages

4
Context-free grammars a simple example
  • The expressions to the right form a context-free
    grammar well call G1
  • There are two types of symbols
  • Variables (nonterminals) A, B
  • Terminals (constants) 0, 1, 2
  • Each line is substitution rule (or production)
  • One variable is designated as the starting symbol
    (A in this example)
  • A grammar generates strings by repeatedly
    applying rules
  • This is called a derivation of the string 0002111

5
Parse-trees
  • Parse-trees can be used to represent derivations
    pictorially
  • Root of the tree is the start symbol
  • Internal nodes are variables
  • Leaves are terminals
  • What strings does G1 generate?

6
A more complex example
  • Some sentences generated by this grammar
  • A girl sees
  • The boy sees a flower
  • The girl with a flower likes the boy
  • Derive the first sentence

7
Definition of Context-free grammar
  • A context-free grammar is a quadruple (?, NT, R,
    S), where
  • ? is the alphabet (of terminals)
  • NT is the set of nonterminals (or variables)
  • R is the set of rules, a subset of
  • S ? NT is the starting symbol
  • Thus a rule is a pair (A, v) (usually written A
    ? v, where A is a single variable, and v is any
    string composed of variables and/or terminals
    (such a string is called a sentential form)

8
Derivations and the language of a grammar
  • We apply a rule A?v to a sentential form w that
    contains the symbol A, by substituting v for A,
    to get a new sentential form w
  • If we get w by applying a rule to w, we say that
    w yields w in one step, and we write w ? w.
  • If we get w by applying a sequence of rules,
    starting with w, we say that w yields w, and we
    write w? w. We also say that w is derivable
    from w.
  • The language of the grammar G, denoted L(G), is
    the set of strings over ? that can be derived
    from the start symbol S

9
More examples
  • Consider the grammar
  • G S ? AB, A ? aA ?, B ? bB ?
  • Give the elements of its quadruple
  • Derive the string aab
  • What is L(G)?
  • Design a grammar whose language is all
    palindromes over ? a, b
  • Design a grammar whose language is all balanced
    strings of parentheses
Write a Comment
User Comments (0)
About PowerShow.com