{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter2Section1_F11

# Chapter2Section1_F11 - 91.304 Foundations of(Theoretical...

This preview shows pages 1–5. Sign up to view the full content.

91.304 Foundations of (Th ti l) C t S i (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin [email protected] uml edu [email protected] With some modifications by Prof. Karen Daniels, Fall 2011 This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by- 1 sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 2: CFGs, CFLs, PDAs We introduce our next programming model with a grammatical formulation: more like REX than DFA A context-free grammar (CFG) is a list of permitted substitution rules S ε S may be rewritten as ε S 0 S 1 ...or as 0 S 1 The variables are the substitutable things, written in UPPER CASE, sometimes called nonterminals The terminals are the nonsubstitutable characters Each rule has a single variable on the left of and a list of terminals and variables on the right The language generated by a CFG is the set of all (terminal) strings that can be found by starting from S and repeatedly substituting until no variables remain. 2
Language generated by example S i So in S ε S 0 S 1 We can generate the strings ε 01 , 01, 0011, 000111, etc. In other words, the language {0 n 1 n | n 0} -- which is non-regular 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Formal definition G is a Context Free Grammar (CFG) if G = (V, Σ , R, S) where 1. V is a finite set of variables 2. Σ is a finite set of terminals and V Σ = It's an alphabet that can't overlap with V 3. R is a set of rules of the form α β where α V — a single variable β ( Σ V) *
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 16

Chapter2Section1_F11 - 91.304 Foundations of(Theoretical...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online