Production (computer science)
This article needs additional citations for verification. (November 2012) (Learn how and when to remove this template message) |
A production or production rule in computer science is a rewrite rule specifying a symbol substitution that can be recursively performed to generate new symbol sequences. A finite set of productions [math]\displaystyle{ P }[/math] is the main component in the specification of a formal grammar (specifically a generative grammar). The other components are a finite set [math]\displaystyle{ N }[/math] of nonterminal symbols, a finite set (known as an alphabet) [math]\displaystyle{ \Sigma }[/math] of terminal symbols that is disjoint from [math]\displaystyle{ N }[/math] and a distinguished symbol [math]\displaystyle{ S \in N }[/math] that is the start symbol.
In an unrestricted grammar, a production is of the form [math]\displaystyle{ u \to v }[/math], where [math]\displaystyle{ u }[/math] and [math]\displaystyle{ v }[/math] are arbitrary strings of terminals and nonterminals, and [math]\displaystyle{ u }[/math] may not be the empty string. If [math]\displaystyle{ v }[/math] is the empty string, this is denoted by the symbol [math]\displaystyle{ \epsilon }[/math], or [math]\displaystyle{ \lambda }[/math] (rather than leave the right-hand side blank). So productions are members of the cartesian product
- [math]\displaystyle{ V^*NV^* \times V^* = (V^*\setminus\Sigma^*) \times V^* }[/math],
where [math]\displaystyle{ V := N \cup \Sigma }[/math] is the vocabulary, [math]\displaystyle{ {}^{*} }[/math] is the Kleene star operator, [math]\displaystyle{ V^*NV^* }[/math] indicates concatenation, [math]\displaystyle{ \cup }[/math] denotes set union, and [math]\displaystyle{ \setminus }[/math] denotes set minus or set difference. If we do not allow the start symbol to occur in [math]\displaystyle{ v }[/math] (the word on the right side), we have to replace [math]\displaystyle{ V^* }[/math] by [math]\displaystyle{ (V \setminus \{S\})^* }[/math] on the right side of the cartesian product symbol.[1]
The other types of formal grammar in the Chomsky hierarchy impose additional restrictions on what constitutes a production. Notably in a context-free grammar, the left-hand side of a production must be a single nonterminal symbol. So productions are of the form:
- [math]\displaystyle{ N \to (N \cup \Sigma)^* }[/math]
Grammar generation
To generate a string in the language, one begins with a string consisting of only a single start symbol, and then successively applies the rules (any number of times, in any order) to rewrite this string. This stops when we obtain a string containing only terminals. The language consists of all the strings that can be generated in this manner. Any particular sequence of legal choices taken during this rewriting process yields one particular string in the language. If there are multiple different ways of generating this single string, then the grammar is said to be ambiguous.
For example, assume the alphabet consists of [math]\displaystyle{ a }[/math] and [math]\displaystyle{ b }[/math], with the start symbol [math]\displaystyle{ S }[/math], and we have the following rules:
- 1. [math]\displaystyle{ S \rightarrow aSb }[/math]
- 2. [math]\displaystyle{ S \rightarrow ba }[/math]
then we start with [math]\displaystyle{ S }[/math], and can choose a rule to apply to it. If we choose rule 1, we replace [math]\displaystyle{ S }[/math] with [math]\displaystyle{ aSb }[/math] and obtain the string [math]\displaystyle{ aSb }[/math]. If we choose rule 1 again, we replace [math]\displaystyle{ S }[/math] with [math]\displaystyle{ aSb }[/math] and obtain the string [math]\displaystyle{ aaSbb }[/math]. This process is repeated until we only have symbols from the alphabet (i.e., [math]\displaystyle{ a }[/math] and [math]\displaystyle{ b }[/math]). If we now choose rule 2, we replace [math]\displaystyle{ S }[/math] with [math]\displaystyle{ ba }[/math] and obtain the string [math]\displaystyle{ aababb }[/math], and are done. We can write this series of choices more briefly, using symbols: [math]\displaystyle{ S \Rightarrow aSb \Rightarrow aaSbb \Rightarrow aababb }[/math]. The language of the grammar is the set of all the strings that can be generated using this process: [math]\displaystyle{ \{ba, abab, aababb, aaababbb, \dotsc\} }[/math].
See also
- Formal grammar
- Finite automata
- Generative grammar
- L-system
- Rewrite rule
- Backus–Naur form (A compact form for writing the productions of a context-free grammar.)
- Phrase structure rule
- Post canonical system (Emil Post's production systems- a model of computation.)
References
- ↑ See Klaus Reinhardt: Prioritatszahlerautomaten und die Synchronisation von Halbspursprachen ; Fakultät Informatik der Universität Stuttgart; 1994 (German)
Original source: https://en.wikipedia.org/wiki/Production (computer science).
Read more |