| Context-free Grammar |
Website Links For Grammar |
Information AboutContext-free Grammar |
| CATEGORIES ABOUT CONTEXT-FREE GRAMMAR | |
| compiler theory | |
| formal languages | |
| programming language topics | |
| SHOPPER'S DELIGHT | |
|
:V → ''w'' where V is a Non-terminal Symbol and ''w'' is a string consisting of terminals and/or non-terminals. The term "context-free" comes from the fact that the non-terminal V can always be replaced by ''w'', regardless of the context in which it occurs. A Formal Language is Context-free if there is a context-free grammar that generates it. Context-free grammars are powerful enough to describe the Syntax of most Programming Language s; in fact, the syntax of most programming languages are specified using context-free grammars. On the other hand, context-free grammars are simple enough to allow the construction of efficient Parsing Algorithm s which, for a given string, determine whether and how it can be generated from the grammar. An Earley Parser is an example of such an algorithm, while LR and LL Parser s only deal with more restrictive subsets of context-free grammars. BNF ( Backus-Naur Form ) is the most common notation used to express context-free grammars. Not all formal languages are context-free — a well-known Counterexample is , the set of strings containing some number of a's, followed by the same number of b's and the same number of c's. This particular language can be generated by a Parsing Expression Grammar , which is a relatively new Formalism that is particularly well-suited to programming languages. FORMAL DEFINITION Just as any Formal Grammar , a context-free grammar G can be defined as a 4-tuple: where
EXAMPLES Example 1 A simple context-free grammar is |