Download presentation
Presentation is loading. Please wait.
1
Context-Free Languages
Giorgi Japaridze Theory of Computability Context-Free Languages Chapter 2
2
A B A B 0A1 Terminals: 0,1 Variables: A,B Productions:
What is a CFG 2.1.a Giorgi Japaridze Theory of Computability A B A B 0A1 Terminals: ,1 Variables: A,B Productions: Start variable: A Derivation: A B 0A1 0B1 00A11 0011 A B Parse tree: A B A
3
Our grammar simplified
2.1.b Giorgi Japaridze Theory of Computability A 0A1 A A 0A1 00A11 000A111 0000A1111 What language does this grammar produce?
4
N men | women | children V like | hate | respect
A more complex CFG 2.1.c Giorgi Japaridze Theory of Computability S N’_V_N’ N’ N | N_who_V_N’ N men | women | children V like | hate | respect S N’ _ V _ N’ N respect N _ who _ V _ N’ children men hate N women
5
A context-free grammar is a 4-tuple (V,,R,S), where
Formal definitions 2.1.d Giorgi Japaridze Theory of Computability A context-free grammar is a 4-tuple (V,,R,S), where 1. V is a finite set called the variables; 2. is a finite set, disjoint from V, called the terminals; 3. R is a finite set of rules, with each rule being a pair of a variable and a string of variables and terminals; 4. S is an element of V called the start variable. If u,v, and w are strings of variables and terminals and Aw is a rule, we say that uAv yields uwv, written uAv uwv. x * y means that x=y, or x y, or there are z1,…,zn such that x z1 … zn y. The language produced (defined, described) by the grammar is {w | S * w and w is a string of (only) terminals}. A context-free language is a language produced by some CFG.
6
Designing context-free grammars
Giorgi Japaridze Theory of Computability Design a CFG that produces all regular expressions over the alphabet {0,1}: <RE> Design a CFG G that produces the union of the languages produced by two given CFGs G1 and G2. G1: A1 w1 … An wn G2: B1 u1 … Bm um
7
Context free versus regular languages
Giorgi Japaridze Theory of Computability Theorem. Every regular language is context-free, but not every context-free language is regular. Proof – omitted. Context-free languages Regular languages {0n1n | n0}
8
languages correspond pushdown automata.
2.2 Giorgi Japaridze Theory of Computability Just as to regular languages correspond finite automata, to context-free languages correspond pushdown automata. This is a new model of computation. What makes a PDA different from NFA is that it has potentially infinite, stack-type (LIFO) memory, where unlimited number of things can be remembered (pushed) and read (popped). A given transition depends on not only the current symbol in the input, but also the symbol currently at the top of the stack. PDAs are still not the most powerful machines. This is because of their limited (LIFO) access to memory. We omit the topic of pushdown automata.
9
Non-context-free languages
Giorgi Japaridze Theory of Computability Just as for regular languages, there is a pumping lemma for context-free languages, used as a tool for proving that a given language is not context-free. We omit this topic, but just remember the following examples of simple NON-CONTEXT-FREE LANGUAGES: {anbncn | n0} {ww | w*} (as long as the alphabet has at least two symbols)
10
Regular vs context-free vs computer-recognizable languages
Giorgi Japaridze Theory of Computability Computer-recognizable languages Context-free languages Regular languages {anbn | n0} {anbncn | n0}
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.