2 Given what you know of computer languages, what language would be a good choice for:
a Processing a file of text, such as a system error log, looking for particular types of events?
b Developing an artificial intelligence application to diagnose disease, given a list of symptoms?
c Writing driver software for a new computer printer?
4.3 Here is a C function that computes the sum of a range of integers. You can assume that begin will
always be less than or equal to end (begin <= end):
64 SOFTWARE [CHAP. 4
int summation( int begin, int end ) {
int result = begin;
begin = begin + 1;
while( begin <= end ) {
result = result + begin;
begin = begin + 1;
}
return result;
}
Rewrite this function so that it uses recursion instead of iteration.
4.4 Assume that a language describes a statement-sequence as a sequence of one or more statements
separated by semicolons (assume statements are defined elsewhere), but with no punctuation at the
end of the statement-sequence. Write the EBNF production.
4.5 Given the following grammar:
expr ?† term + expr | term
term ?† factor * term | factor
factor ?† (expr) | number
number ?† number digit | digit
digit ?† 0|1|2|3|4|5|6|7|8|9
Draw the full parse tree for the expression:
2 * (3 + 5) + (6 + 8)
4.
Pages:
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185