4 - Grammars
Published online by Cambridge University Press: 02 December 2009
Summary
Formal grammars
A grammar is intuitively a set of rules which are used to construct a language contained in Σ* for some alphabet Σ. These rules allow us to replace symbols or strings of symbols with other symbols or strings of symbols until we finally have strings of symbols contained in Σ allowing us to form an element of the language. By placing restrictions on the rules, we shall see that we can develop different types of languages. In particular we can restrict our rules to produce desirable qualities in our language. For example in our examples below we would not want 3 + ÷4 − ×6. We also would not want a sentence Slowly cowboy the leaped sunset. Suppose that we begin with a word add, and that we have a rule that allows us to replace add with A + B and that both A and B can be replaced with any nonnegative integer less that ten. Using this rule, we can replace A with 5 and B with 3 to get 5 + 3. There might also be an additional rule that allows us to replace add with a different string of symbols.
If we add further rules that A can be replaced by A + B and B can be replaced by A × B, we can start by replacing add with A + B. If we then replace A with A + B and B with A × B, we get A + B + A × B.
- Type
- Chapter
- Information
- Automata Theory with Modern Applications , pp. 114 - 168Publisher: Cambridge University PressPrint publication year: 2006