???
Non-terminals are so-called because they can be broken down into combinations of smaller concepts. For
instance, a verb-phrase can consist of a verb and a direct-object-phrase. Ultimately, the grammar defines the
units of the language that cannot be further reduced, the words of the language, and these are called ???terminals.???
On the right-hand side of a production, BNF shows the possible combinations of non-terminals and/or terminals
that can be substituted for the higher-level non-terminal on the left-hand side. Here is a grammar for mathematical
expressions:
1 expression -> term | expression add_op term
2 term -> factor | term mult_op factor
3 factor -> identifier | number | - factor | (expression)
4 add_op -> + | -
5 mult_op -> * | /
The vertical lines mean ???or.??? To simplify the discussion so that we need not also supply rules for creating
???identifiers??? and ???numbers,??? assume that identifiers are valid variable names and numbers are valid numbers.
We will treat them as terminals.
Production 1 says that an expression can consist either of a term, or of an expression plus an add_op
(addition operator) plus a term. Production 2 says that a term can be a factor, or it can be another term plus
a mult_op (multiplication operator) plus a factor.
Pages:
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177