70 likes | 328 Views
Context Free Grammars and Regular Grammars. Needs for CFG Grammars and Production Rules Context Free Grammars (CFG) Regular Grammars (RG). Needs for CFG. Regular expressions were inadequate to define all interesting languages and therefore we need more powerful language defining structure.
E N D
Context Free Grammars and Regular Grammars Needs for CFG Grammars and Production Rules Context Free Grammars (CFG) Regular Grammars (RG)
Needs for CFG • Regular expressions were inadequate to define all interesting languages and therefore we need more powerful language defining structure. • Why do we still need regular language if context free language is more powerful?
Grammars and Production Rules • G = ( V, T, S, P) is a set of rules that governs the manner in which the tokens of T may be organized into strings in a language. • T -- set of terminal symbols • V -- set of nonterminal symbols • S -- a element of V, starting symbol • P -- set of production rules of certain format restrictions which determine the class of grammar
Context Free Grammars(the representation defining CFL) • A grammar is said to be context-free if all productions in P have the form A --> x, where A is a single nonterminal and x can be any string of terminals or/and nonterminals. • Single nonterminal makes the grammar context-free.
Regular Grammars(one of 4 representations of RL) • A context-free grammar is said to be regular grammar if all productions in P have the form A --> x, where A is a single nonterminal and x can be a word or semiword. • Word -- a string of terminals • Semiword -- a string of terminals ended with a nonterminal.