background preloader

Context-Free Grammar

Facebook Twitter

Videos (Context Free Grammar)

Context-free grammar. V → w where V is a single nonterminal symbol, and w is a string of terminals and/or nonterminals (w can be empty). A formal grammar is considered "context free" when its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. Context-free grammars arise in linguistics where they are used to describe the structure of sentences and words in natural language, and they were in fact invented by the Linguist Noam Chomsky for this purpose, but have not really lived up to their original expectation.

By contrast, in computer science, as the use of recursively defined concepts increased, they were used more and more. In an early application, grammars are used to describe the structure of programming languages. In a newer application, they are used in an essential part of the Extensible Markup Language (XML) called the Document Type Definition.[1] where. Ch 17, Context-Free Grammars and Constituency Parsing (Speech and Language Processing (3rd ed. draft by Dan Jurafsky and James H. Martin) Formal language. Context-free language.

Prerequisite for a. Parse Tree (Linguistics) Chomsky Hierarchy. Type-2 Grammer. Context-free grammar.

Parse Tree (Linguistics)

Abstract machine. Nondeterministic Pushdown (Abstract Machine) Context Free Grammars. Parsing expression grammar. Type of grammar for describing formal languages Unlike CFGs, PEGs cannot be ambiguous; a string has exactly one valid parse tree or none. It is conjectured that there exist context-free languages that cannot be recognized by a PEG, but this is not yet proven.[1] PEGs are well-suited to parsing computer languages (and artificial human languages such as Lojban) where multiple interpretation alternatives can be disambiguated locally, but are less likely to be useful for parsing natural languages where disambiguation may have to be global.[2] Definition[edit] A parsing expression is a kind of pattern that each string may either match or not match.

In case of a match, there is a unique prefix of the string (which may be the whole string, the empty string, or something in between) which has been consumed by the parsing expression; this prefix is what one would usually think of as having matched the expression. An element of a string matched is called a terminal symbol, or terminal for short. . Probabilistic context-free grammar. Grammar theory to model symbol strings originated from work in computational linguistics aiming to understand the structure of natural languages.[1][2][3] Probabilistic context free grammars (PCFGs) have been applied in probabilistic modeling of RNA structures almost 40 years after they were introduced in computational linguistics.[4][5][6][7][8] PCFGs extend context-free grammars similar to how hidden Markov models extend regular grammars. Each production is assigned a probability. The probability of a derivation (parse) is the product of the probabilities of the productions used in that derivation.

These probabilities can be viewed as parameters of the model, and for large problems it is convenient to learn these parameters via machine learning. A probabilistic grammar's validity is constrained by context of its training dataset. PCFGs have application in areas as diverse as natural language processing to the study the structure of RNA molecules and design of programming languages.

". Straight-line grammar. From Wikipedia, the free encyclopedia Type of formal grammar A straight-line grammar (sometimes abbreviated as SLG) is a formal grammar that generates exactly one string.[1] Consequently, it does not branch (every non-terminal has only one associated production rule) nor loop (if non-terminal A appears in a derivation of B, then B does not appear in a derivation of A).[1] Areas of usefulness[edit] Straight-line grammars are widely used in the development of algorithms that execute directly on compressed structures (without prior decompression).[2]: 212 SLGs are of interest in fields like Kolmogorov complexity, Lossless data compression, Structure discovery and Compressed data structures.

The problem of finding a context-free grammar (equivalently: an SLG) of minimal size that generates a given string is called the smallest grammar problem. Formal Definition[edit] A context-free grammar G is an SLG if: An SLG in Chomsky normal form is equivalent to a straight-line program. See also[edit] Pumping lemma for context-free languages. Type of pumping lemma The pumping lemma can be used to construct a proof by contradiction that a specific language is not context-free. Conversely, the pumping lemma does not suffice to guarantee that a language is context-free; there are other necessary conditions, such as Ogden's lemma, or the Interchange lemma.

Formal statement[edit] If a language is context-free, then there exists some integer (called a "pumping length")[2] such that every string in that has a length of or more symbols (i.e. with ) can be written as with substrings and , such that , and for all Below is a formal expression of the Pumping Lemma. Informal statement and explanation[edit] The pumping lemma for context-free languages (called just "the pumping lemma" for the rest of this article) describes a property that all context-free languages are guaranteed to have.

The property is a property of all strings in the language that are of length at least , where Say is a string of length at least that is in the language. is at most ) in in L. Category:1956 in computing. Category:Compiler construction. Category:Formal languages. Category:Programming language topics. Formal Grammer's in Chomsky's Hierarchy.