DATA STRUCTURES, ANALYSIS OF ALGORITHMS AND COMPUTATIONAL COMPLEXITY
int inQueue(int x);
Assume the existence of these global variables:
Write the code for the North-or-South bound automobile process.
Be sure to include this comment at the appropriate place in the code:
PROGRAMMING LANGUAGES AND COMPILER DESIGN
int a[2];
void z(int i, int j) {
i = a[i];
j = a[j];
a[j] = a[i];
a[i] = j*2;
}
main() {
a[0] = 1;
a[1] = 0;
z(a[0], a[1]);
print(a[0],a[1]);
}
For each of the following parameter mechanisms, describe the mechanism and show the output from the program.
a) call by value
b) call by reference
c) call by value-result
1. A variable's
a) scope must be determined by the lexical structure of the program;
b) type must be known at translation time;
c) lifetime must be determined by the variable's type;
d) value may be determined at translation time.
2. Associating storage to a variable name
a) is called ``binding'';
b) may be at translation time;
c) may be at run-time;
d) can never change.
3. An alias
a) occurs when two variables share the same type;
b) occurs when two variables share the same memory address;
c) can only occur in languages with pointers;
d) cannot occur with call-by-value parameters.
4. Parameter passing by
a) name copies the value of the actual parameter;
b) value is usually the default for arrays;
c) reference insures that aliases will not arise;
d) value-result can be considered macro-expansion.
5. Garbage
a) exists when deallocation occurs before the last reference;
b) exists when the last reference occurs before deallocation;
c) is collected in all languages which use heaps;
d) is found in static languages.
int z(int i, const float x) or int id(int id, const float id)
a) Compute the value of FIRST for each of the non-terminals in this grammar.
b) Compute FOLLOW of these non-terminals.
c) Using your results from a) and b), construct an LL(1) parsing table.
d) Using your result from c), begin the parse of the example above assuming that z, i, x are all replaced with the terminal id. Show the contents of the stack and how the input is consumed (show at least the first five steps).