Download presentation
Presentation is loading. Please wait.
Published byColeen Turner Modified over 8 years ago
1
Midterm 1 Breakdown >79 3 >29 7 >69 5 >19 5 >59 7 >49 9 >39 7
2
Project 1
3
CS 3240: Languages and Computation Context-Free Languages
4
What are Grammars? A grammar G is defined by (V, T, P, S), where V is a finite set of variables T is a finite set of terminal symbols P is a finite set of productions or ules S V is the special start variable Each grammar G defines a language L(G), which is the set of strings in T* (=Σ*) that G can generate from S. Automata are actuated by the transition table, grammars by the production rules.
5
Context-Free Grammars A context-free grammar (V, T, P, S) is a grammar where all production rules are of the form: A → x, with A V and x (V T)* A string in (V T)* is called sentential form E.g., let G = ({S}, {a,b}, P, S) with for P: S→aSa S→bSb S→ . Some derivations from this grammar: S aSa aaSaa aabSbaa aabbaa S bSb baSab baab, and so on. In general S …. ww R for w {a,b}*.
6
Beyond regular Languages
7
Formal definition of CF Grammar & Language
8
Another CFG Example Consider the CFG G=({S,Z},{0,1}, P, S) with P: S 0S1 | 0Z1 Z 0Z | What is the language generated by this G? Answer: L(G) = {0 i 1 j | i j } Specifically, S yields the 0 j+k 1 j according to: S 0S1 … 0 j S1 j 0 j Z1 j 0 j 0Z1 j … 0 j+k Z1 j 0 j+k ε1 j = 0 j+k 1 j
9
Exercise Design CFGs for the following languages: a) { 0 n 1 n : n ≥ 0} b) { 0 n 1 m : n,m ≥ 0} c) { (0|1)* : # of 0s > # of 1s} Answers: a) S → 0S1 | b) S → 0S | R and R → 1R | c) S → T0T and T → TT | 0T1 | 1T0 | 0 |
10
derivations
11
Leftmost righmost
12
Sentential forms
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.