Material about Grammars: This is the third of 3 pages about grammars.
Review: In page 1 above, familiarize yourself with the terms:
Regular Grammars: Regular grammars are a special case of the context-free grammars we have emphasized. Definition of Regular Grammar: A regular grammar is a CF grammar, where each grammar rule has at most one non-terminal on the right hand side, and if present, this non-terminal must be at the right end. There can be any number of non-terminals in the right-hand side, including none at all.It turns out that regular grammars generate exactly the same languages as are recognized by finite state automata (that is, NFAs, DFAs, or NFAs with ε-moves). This is also exactly the same languages at are described by regular expressions. For example, consider the regular expression /b(ab)*/. One corresponding regular grammar is: S ---> bT T ---> abT | εThe regular expression /(a|b)*abb/ can be described by the regular grammar: S ---> aS | bS | abb Context Free Grammars and Their Languages: The CF grammars describe a much larger collection of languages than the regular languages. A CF grammar is a more powerful tool than a regular grammar, and the definition makes it clear that the regular grammars are a special case of CF grammars. It turns out that there is a class of finite automata that have an additional stack to save items on called PDAs or Push-Down Automata. The languages recognized by PDAs are exactly the same as those described by context-free grammars. In fact, soon we will study a shift-reduce parser, which is just a finite machine with a stack. A shift-reduce parser can't handle all CF languages. More complicated LR parsers push states as well as symbols onto a stack, and they can handle a larger class of languages, but still not all CF languages. Unrestricted Grammars: These grammars allow anything at all on the left side of a rule. For example (here only the lower-case a is terminal):
Revision date: 2013-09-10. (Please use ISO 8601, the International Standard.) |