LectureNotes10 - ECS 120 Lesson 10 Context-Free Grammars...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECS 120 Lesson 10 Context-Free Grammars Oliver Kreylos Friday, April 20th, 2001 In the beginning of the course, we encountered the Chomsky Hierarchy , a framework to classify languages into four different categories, CH-0 to CH-3. Until now, we have only had a closer look at the most restrictive level of the Chomsky Hierarchy: CH-3, the class of regular languages. In the last lesson, we found out that there are languages which are not in CH-3, for example the language n 1 n n or the language R () of regular expressions over the alphabet . Today we will look at CH-2, the class of context-free languages (CFL), which includes all regular languages, and also the two nonregular languages mentioned above. Context-free languages are very important in practical applications; al- most every programming language has an underlying context-free structure, and a parser , a program to analyze the context-free structure of an input string, is a major component of any compiler for these programming lan- guages. The parsers job is to break up a source program into its syntactical parts, e. g., modules, functions, loops, blocks and expressions, and to invoke the code generator , the program that converts syntactical structures into machine code, on these parts independently. Context-free languages are specified either by context-free grammars (CFG) or by pushdown automata , a generalization of finite state machines. We will start by having a closer look at context-free grammars. 1 Definition of Context-Free Grammars We already defined a grammar G as a four-tuple G = ( V, ,R,S ), where V is a finite set of variables, is an alphabet with V = , R is a finite set of rules and S V is the start symbol. For context-free grammars, all rules 1 in R are of the form A w , where A V is a variable and w ( A ) * is a string of variables and terminals. If there are several rules with the same left-hand side, e. g., A w 1 ,A w 2 ,...,A w n , those are often combined into a single rule A w 1 | w 2 | | w n . The vertical bar is treated like an or. If u,v,w ( A ) * are strings of variables and terminals, and A w R is a rule of G , then uAv uwv ( uAv yields uwv ). If u = v , or there exists an n 0 and a sequence ( u 1 ,u 2 ,...,u n ) ( ( A ) * ) n of strings of variables and terminals such that u u 1 u 2 u n v , then u * v . The language of grammar G is L ( G ) := w * S * w . 2 Example: The Language L = n 1 n n Consider the grammar G = ( { S } , { , 1 } ,R,S ) , where R = { S S 1 | } . We will now prove that this grammar exactly generates the nonregular language L ....
View Full Document

This note was uploaded on 05/20/2010 for the course ECS 120 taught by Professor Filkov during the Spring '07 term at UC Davis.

Page1 / 9

LectureNotes10 - ECS 120 Lesson 10 Context-Free Grammars...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online