Context - Free Languages
Context - Free Languages
Review Machine Models of Computing Linguistic Model of Computing Challenge Problem Near-Solution Liuyi (Eric) Zhang Context-Free Grammars
David Evans
http://www.cs.virginia.edu/evans
Lecture 8: Language
Yes or No
Machine DFA DPDA TM
3
101
Yes or No
Machine NFA NDPDA NDTM
4
DFAs
McCulloch and Pitts, A logical calculus of the ideas immanent in nervous activity, 1943 S. C. Kleene, Representation of Events in Nerve Nets and Finite Automata, 1956 Claude Shannon and John McCarthy, Automata Studies, 1956
Lecture 8: Language
Lecture 8: Language
Out theoretical objective is not dependent on the assumptions fitting exactly. It is a familiar strategem of science, when faced with a body of data too complex to be mastered as a whole, to select some limited domain of experiences, some simple situations, and to undertake to construct a model to fit these at least approximately. Having set up such a model, the next step is to seek a thorough understanding of the model itself. S. C. Kleene, Representation of Events in Nerve Nets and Finite Automata, 1956
Lecture 8: Language
Lecture 8: Language
Noam Chomsky (born 1928), MIT Linguistics Professor and Leftist Political Activist
Lecture 8: Language
10
I dont know anybody whos ever read a Chomsky book, He does not write page turners, he writes page stoppers. There are a lot of bent pages in Noam Chomskys books, and they are usually at about Page 16.
Alan Dershowitz
Lecture 8: Language
I must admit to taking a copy of Noam Chomskys Syntactic Structures along with me on my honeymoon in 1961. During odd moments, while crossing the Atlantic in an ocean liner and while camping in Europe, I read that book rather thoroughly and tried to answer some basic theoretical questions. Here was a marvelous thing: a mathematical theory of language in which I could use a computer programmers intuition! The mathematical, linguistic, and algorithmic parts of my life had previously been totally separate. During the ensuing years those three aspects became steadily more intertwined; and by the end of the 1960s I found myself a Professor of Computer Science at Stanford University, primarily because of work that I had done with respect to languages for computer programming. Donald Knuth
11
Lecture 8: Language
12
Replacement Grammars
Unrestricted:
Left Right
Anything that matches the left side can be replaced by what is on the right side. Left and Right can be any sequence of variables (nonterminals) and symbols (terminals)
(left and right sides can be any sequence of symbols and variables)
Context-Sensitive:
(A is a variable)
Context-Free:
Regular:
Lecture 8: Language
A
A aB ; A a
14
Lecture 8: Language
13
Jane
jump
16
Charles Yang
Lecture 8: Language
17
Lecture 8: Language
18
Recursion = Human ?
We hypothesize that faculty of language in the narrow sense (FLN) only includes recursion and is the only uniquely human component of the faculty of language. We further argue that FLN may have evolved for reasons other than language, hence comparative studies might look for evidence of such computations outside of the domain of communication (for example, number, navigation, and social relations). Marc Hauser, Noam Chomsky, Tecumseh Fitch,
The Faculty of Language: What Is It, Who Has It, and How Did It Evolve?, Science, Nov 2002
Steven Pinker and Ray Jackendoff (2004): its not just recursion...
Lecture 8: Language
19
Lecture 8: Language
20
Review: Heaps
A heap is a complete binary tree, usually represented as an array:
16 4 14 2 8 1 7 9 3 2 4 1 7 9 10 3
A = 16 14 10 8
21
Lecture 8: Language
22
Sorting
Heap starts 32 bit before the 1st integer
Bit Sort
Sort bit by compare 8 bits with 011111112
Lecture 8: Language
23
Lecture 8: Language
24
Continue
Sort till the last bit
Memory
Bottom-up
Lecture 8: Language
25
Lecture 8: Language
26
Compare
Heap Sort
Requires ~ n log2 n comparisons 4 bytes to store integer
Challenge Recap
Bit Sort:
Requires ~ 32n comparisons Memory to store (up to 33) memory addresses that separate the 1s and 0s
Lecture 8: Language
27
Lecture 8: Language
28
Language Classes
Described by a finite set, DFA with no cycles, Regular grammar with no recursion Described by a DFA, NFA, Regular grammar Described by a NDPDA, Context-Free Grammar
29
Context-Free Grammar
A
One variable
Finite
Regular Context-Free
Lecture 8: Language
30
Example 1
S 0S0 S 1S1 S
Example 2
Define a CFG that generates the language: { w | w {0, 1}* and w has an equal number of 0s and 1s }
Lecture 8: Language
31
Lecture 8: Language
32
Review Questions
How do you prove context-free? How do you prove context-free? How do you prove context-free? How do you prove context-free?
Lecture 8: Language
Charge
Return PS2 and PS2 Comments now PS3 is posted on the course site (Due in 1 week, Feb 19) Thursday:
Equivalence of NDPDAs and CFGs (sketch) Non-Context-Free Languages
Lecture 8: Language
33
34