Computer Science
Context Free Grammar
Context-free grammar is a formal grammar that describes a language by defining its syntax through a set of production rules. It is used in computer science to generate programming languages, compilers, and parsers. It is called "context-free" because the production rules apply regardless of the context in which a symbol appears.
Written by Perlego with AI-assistance
Related key terms
1 of 5
7 Key excerpts on "Context Free Grammar"
- eBook - PDF
Annual Review in Automatic Programming
International Tracts in Computer Science and Technology and Their Application, Volume 7
- Mark I. Halpern, William C. Mcgee, Louis Bolliet(Authors)
- 2014(Publication Date)
- Pergamon(Publisher)
The report explores the notion that the declarative statements of a program construct a context-free grammar for the imperative statements of that particular program, and that the required relationships can be represented by the rules for constructing this grammar. The concept has been termed dynamic syntax since it implies a dynamic context-free grammar. Using the language of the lambda-calculus, the report gives a functional realization of dynamic syntax, allowing the construction of an expression which denotes the set of language strings of a given programming language. In the Appendix the method is applied to the description of a large subset of Algol 60f. 2. Context-free Languages A context-free language is defined in the following way : A vocabulary Κ is a finite set of symbols. A string over the vocabulary is a finite sequence of these symbols. The set of all strings over Κ (where the set includes the empty string) will be t All subsequent, unqualified references to Algol should be taken as references to Algol 60. 115 116 Κ. V. Hanford and C. Β. Jones denoted by V*. Arbitrary symbols will be denoted by upper-case Latin letters A, B,. . . and strings by lower-case Latin letters a, b , . . . . A context-free grammar G consists of : 1. A vocabulary V. 2. A non-empty subset of the cross-product set V - eBook - ePub
Theory of Computation Simplified
Simulate Real-world Computing Machines and Problems with Strong Principles of Computation (English Edition)
- Dr. Varsha H. Patil, Dr. Vaishali S. Pawar, Dr. Swati A. Bhavsar, Dr. Aboli H. Patil(Authors)
- 2022(Publication Date)
- BPB Publications(Publisher)
(a + b)^d/e + (S – T)S → (a + b)^d/e + (T – V)S → (a + b)^d/e + (V – F)S → (a + b)^d/e + (F – I)S → (a + b)^d/e + (I – F)S → (a + b)^d/e + (– F),Hence, proved.Conclusion
In this chapter, we learnt the basic elements of grammar and it definition. The Context Free Grammar is a way of describing languages by using production rules. Derivations and languages are generated by using the start symbol and a string of terminals is derived by repeatedly replacing it by the body of production rules. While replacing, if we replace the leftmost non-terminal, then the resulting derivation is leftmost, else if we replace the rightmost non-terminal, then the resulting derivation is rightmost. We also learnt the concept of ambiguous grammar and how to remove ambiguity form it. Then we learnt the representation of grammar in two types of normal forms such as Chomsky normal form and Greibach normal form. Further, the types of grammar were studied using Chomsky hierarchy. At the end of the chapter, we learnt the applications of Context Free Grammar. - eBook - ePub
Automata and Computability
A Programmer's Perspective
- Ganesh Gopalakrishnan(Author)
- 2019(Publication Date)
- Chapman and Hall/CRC(Publisher)
7The basic goal of designing a CFG is to come up with an elegant set of rules that are intuitively correct, and (upon being challenged) rigorously shown to be consistent and complete. Many such proofs can be elegantly structured around a rather nice picture which we call the “hill/valley” plot.8Example: For our illustration, consider a different language, namely Leqab , which is exactly the set of all strings that contain an equal number of a ’s and b ’s. We can derive a CFG for it by growing the language inside-out.9 More specifically,• ε is in the language, and therefore we must include a production of the form S -> ″• Now, we set up the pattern aSbS , and think inductively in our minds; we also indicate the questions that naturally arise:– If S is consistent, then placing an equal amount of a ’s and b ’s keeps it consistent.– But do we settle for aSb or aSbS ? We choose the latter, as it does not force a b -ending.– Do we include bSaS ? We feel it is necessary, to avoid an a -only ending.– Do we throw in an SS case? While doing so won’t cause inconsistency, it may be unnecessary for completeness (see below).Let us assume we don’t need the SS case, and present the CFG designed thus far:S -> ’’ | aSbS | bSaSWe now prove that this CFG is consistent, and the SS production is not necessary (the CFG is complete with respect to Leqab - eBook - PDF
- Lev D. Beklemishev(Author)
- 2000(Publication Date)
- Elsevier Science(Publisher)
1). Each of the generated sentences will again have a structural description of the appropriate kind. Grammars of the type (3), (4) we will call context-free (CF) grammars. They are characterized by the property that exactly one non-terminal appears on the left-hand side of each rewriting rule. If this restriction is relaxed, we have systems with entirely different formal properties. It l) In this case, infinitely many non-English sentences will also be generated, e.g., “that those tom books is obvious are completely worthless”, etc. Hence the grammar ((3), (4)) is unacceptable. The difficulty of avoiding empirical inadequacies of this sort can easily be underestimated. We stress again that this is the key issue for both linguis- tics and psychology, though it will not concern us directly here. For discussion, see Chomsky [13]. 122 N. CHOMSKY AND M. P. SCH~TZENBERGER seems that grammars for natural languages must contain at least some rewriting ryles of this more general form, and some rules that are not rewriting rules at all. Cf. Chomsky [8], [lo], and [12], Chomsky and Miller [15], for further abstract discussion of systems of these sorts, which we will not consider further here. A set of terminal strings that can be generated by some CF grammar we will call a CF language. A CF language may generate a terminal (debracketised) string pl with several different structural descriptions. In this case, if the grammar is empirically adequate, pl should be structurally ambiguous. - eBook - PDF
Algorithms and Theory of Computation Handbook, Volume 1
General Concepts and Techniques
- Mikhail J. Atallah, Marina Blanton(Authors)
- 2009(Publication Date)
- Chapman and Hall/CRC(Publisher)
His work influenced Emil Post, Stephen Kleene, and others to study the mathematical properties of strings and collections of strings. Soon after the advent of modern electronic computers, people realized that all forms of information—whether numbers, names, pictures, or sound waves—can be represented as strings. Then collections of strings known as languages became central to computer science. This chapter is concerned with fundamental mathematical properties of languages and language-generating systems, such as grammars. Every programming language from Fortran to Java can be precisely described by a grammar. Moreover, the grammar allows us to write a computer program (called the syntax analyzer in a compiler) to determine whether a string of statements is syntactically correct in the programming language. Many people would wish that natural languages such as English could be analyzed as precisely, that we could write computer programs to tell which English sentences are grammatically correct. Despite recent advances in natural language processing, many of which have been spurred by formal grammars and other theoretical tools, today’s commercial products for grammar and style fall well short of that ideal. The main problem is that there is no common agreement on what are grammatically correct (English) sentences; nor has anyone yet been able to offer a grammar precise enough to propose as definitive. And style is a matter of taste(!) such as not beginning sentences 20 -1 20 -2 General Concepts and Techniques with “and” or using interior exclamations. Formal languages and grammars have many applications in other fields, including molecular biology (see [17]) and symbolic dynamics (see [14]). In this chapter, we will present some formal systems that define families of formal languages arising in many computer science applications. Our primary focus will be on context-free languages (CFL), since they are most widely used to describe the syntax of programming languages. - eBook - PDF
- Alexej V. Gladkij, Igor A. Melcuk, John Lehrberger(Authors)
- 2020(Publication Date)
- De Gruyter Mouton(Publisher)
4. Finally, there are a large number of algorithms for automatic analysis (= parsing) and generation of texts in natural language which use as a means of describing the corresponding languages just CF grammars or some systems Generative Grammars and Natural Languages 67 equivalent to CF grammars. Many of these algorithms have been programmed for electronic computers and have been tested in quite extensive experiments; based on CF grammars, for example, are the algorithms of syntactic analysis, or parsers, for English, German, French and other languages, which were elaborated at the University of Texas (Tosh 1965), a number of parsers which use the so-called Cock method (Hays 1962: 412—414), and several other parsers mentioned in Bobrow 1963, Kuno 1968, Montgomery 1969, Kay — Sparck-Jones 1971; cf. also systems for random generation of natural sentences described in Yngve 1961 and Arsent'eva 1965. All this suggests CF grammars as being sufficient for natural languages. In particular, it is worth noting that constructions of the type abed... d'c'b'a (p. 51), which cannot be described by FS grammars, are easily generated with the aid of CF grammars. Thus it is easy to show that a language consisting exactly of strings of the indicated type (composed of the symbols a u a 2 , a 3 , a, a' 2 , a' 3 ) is generated by a CF grammar containing the following six rules: / = 1,2,3 Now it seems necessary to make two important remarks. First, what has been said so far in no way means that CF/grammars generate only natural languages or languages close to them: among CF languages there are many which are not at all similar in their structure to natural languages. Second, from the fact that CF grammars are practically sufficient for describing natural languages, it does not follow that they are always CONVENIENT for this purpose, i.e., that they allow one to describe any constructions of any natural languages in a natural manner. - eBook - PDF
Formal Languages and Computation
Models and Their Applications
- Alexander Meduna(Author)
- 2014(Publication Date)
- Auerbach Publications(Publisher)
104 ◾ Formal Languages and Computation constructs S → aAb � Similarly, from S ⇒ A ⇒ ab , it makes S → ab � As the resulting CFG O , it produces S → AB, S → aAb , S → ab , S → cBd , S → cd , A → aAb , B → cBd , A → ab , B → cd We close this section by summarizing all the useful grammatical transformations given earlier in this chapter to demonstrate how to obtain a properly defined CFG from any CFG� Of course, first, we state what we mean by this proper definition� Definition 6.32 A CFG, G = ( G Σ , G R ), is proper if I� G Σ contains no useless symbols� II� G R contains neither ε -rules nor single rules� Theorem 6.33 For every CFG, I = ( I Σ , I R ), there exists a proper CFG, O = ( O Σ , O R ), such that L ( O ) = L ( I ) – { ε }� Proof � Let I = ( I Σ , I R ) be any CFG� Remove all useless symbols from I Σ (see Algorithm 6�20)� Apply Algorithm 6�28 to the CFG without useless symbols to an equivalent CFG containing no ε-rules; then, by Algorithm 6�30, convert the CFG without ε -rules to a CFG without any single rules� Take the resulting CFG as O � Observe that O is proper and L ( O ) = L ( I ) – { ε }� 6.2.5 Chomsky Normal Form In this section, we explain how to transform any CFG to an equivalent proper grammar in Chomsky normal form, in which each of its rule has on its right-hand side either a terminal or two nonter-minals� We often make use of the Chomsky normal form to simplify proofs as demonstrated later in this chapter (see, for instance, Algorithm 6�38 and the proof of Theorem 6�39 in Section 6�2�6)� Definition 6.34 A CFG, G = ( Σ , R ), is in Chomsky normal form if it is proper, and in addition, every rule A → x ∈ R satisfies x ∈ Δ ∪ NN � Basic Idea.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.






