Tuesday, May 3, 2011

REVIEW QUESTIONS

4.1 Why was it important to the history of programming languages that, even at its introduction, FORTRAN
generated efficient programs?
4.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):

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.6 Describe the form in which a program is passed from:
a The scanner to the parser.
b The parser to the semantic analyzer.
4.7 Here is a context-free grammar in BNF form:
expr --> expr + term | expr - term | term
term --> term * factor | term / factor | factor
factor --> ex ** factor | ex
ex --> (expr) | id
Rewrite this grammar in EBNF form.
4.8 What does this Scheme function do?
(define whatsThis
(lambda (n)
(cond((null? n) 0)
((null? (cdr n)) (car n))
((> (car n) (whatsThis (cdr n))) (car n))
( else (whatsThis (cdr n)))
)))
4.9 Give an example of an irregularity in a language with which you are familiar.
4.10 Would it ever make sense to write a program in one language, planning from the beginning to rewrite
the program later in a different language? Give an example of a situation in which such a plan might
make sense, and not simply result in wasted time and effort.

No comments:

Post a Comment