The parser tests the token stream against the syntax,
or grammar rules, of the language, and in the process finds many of the errors we programmers make.
The syntax of a language describes the allowable statements in the language. Following correct syntax does
not guarantee correct programming, but correct programming requires correct syntax. For instance, in English, the
sentence, ???The octopus combed his hair??? is syntactically correct, but foolish. On the other hand, the sentence, ???The
mab ran after the bus??? is not syntactically correct because the dictionary does not recognize the token ???mab??™. In
programming languages, as in English, many syntax errors occur because of misspellings and typographical errors.
Today, language syntax rules are usually expressed in Backus-Naur form (BNF), or extended Backus-Naur
form (EBNF), after John Backus (inventor of FORTRAN) and Peter Naur. BNF uses a set of rules or ???productions???
to describe the grammar, or syntax.
On the left-hand side of a production, BNF shows a linguistic concept known as a ???non-terminal.???
Examples of non-terminals from English include ???verb-phrase??? and ???sentence.??? In a programming language,
examples of non-terminals might be ???term??? or ???expression.
Pages:
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176