Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-x24gv Total loading time: 0 Render date: 2024-04-30T14:17:35.009Z Has data issue: false hasContentIssue false

9 - Context-Free Grammars and Context-Free Languages

Published online by Cambridge University Press:  26 October 2011

P. K. Srimani
Affiliation:
Professor, Department of Computer Science, Bangalore University
S. F. B. Nasir
Affiliation:
Professor, Department of Computer Science, Bangalore University
Get access

Summary

Grammar is the mathematics of a language and mathematics is the grammar of creation.’

Introduction

In any language such as English, Hindi or Sanskrit, words can be combined in several ways. Naturally, some combinations form valid sentences, while others do not. The validity of a sentence is determined by the grammar of a language, which comprises a set of rules. For instance, ‘The boy prepares tea quickly’, although meaningless, is a perfectly legal sentence. In other words, the sentences in a language may be nonsensical, but they must obey the rules of grammar. The discussion in this chapter deals with only the syntax of sentence (the way the words are combined) and not with the semantics of sentences (meaning).

In the previous chapters, two different (though equivalent) methods: finite automata and regular expressions were introduced for describing languages. These methods have their own limitations in the sense that some simple languages, such as {0n1n|n ≥ 0}, cannot be described by these methods. Formal languages and grammars are widely used in connection with programming languages. During programming, we proceed with an intuitive knowledge of the languages, which leads to errors. Therefore, a precise description of the language is needed, at almost every step, which helps to understand the syntax diagrams found in programming texts. Among the ways in which programming languages can be defined precisely, grammars or context-free grammars are most widely used. This method happens to be a very powerful method and such grammars can describe certain features which have a recursive structure. Context-free-grammars (CFG) were first used in the study of human languages.

Type
Chapter
Information
Publisher: Foundation Books
Print publication year: 2007

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×