1. The below skeleton is in a C-like language. It includes one goto statement. The target of the goto might be any one of the labeled statements, s1...s5.
a) For each possible target, list BRIEFLY and CONCISELY
(i) any semantic problems with a goto to this target, and
(ii) any implementation problems that arrive with a goto to this target?
b) Choose a language of your choice and discuss which gotos would be legal.
int g() {
int x = 5;
...
t1: s1; // first target
...
return x;
}
int f() {
int i,j;
for (i=1;i<20;i++)
{ ...
t2: s2; // second target
...
goto < target ti >; // goto statement
...
}
t3: s3; // third target
...
for (j=1;j<30;j++)
{ int k=3;
...
t4: s4; // fourth target
...
}
...
return (i+j);
}
int main () {
int x=5, y=10;
x=g();
y=f();
t5: return 0; //fifth target
}
2. An e-commerce company has a reply template that asks for a user's email address. You, as an expert in compiler design, are asked to use compiler techniques for language specification to help in validating input by specifying the set of legal strings.
For simplification, suppose that the only characters are:
26 lower case letters: a,b,c,...,z
3 special characters: hyphen (-), atsign (@), dot (.)
And suppose that a legal email address must be a sequence of characters that:
Begins with a letter
Contains exactly one occurrence of the atsign
Ends in one of: .net .edu .com
Never contains two adjacent special characters (i.e, '.@', '...', etc. are illegal)
a) Write a regular expression for legal email addresses.
b) Write a BNF grammar that generates legal email addresses.
3. The XXX Language Reference manual says that "the order of the evaluation of parameters is not specified."
a) Write a simple C function that gives different results depending on the order of evaluation of the parameters. Show the definition of your function and the call to the function. Use no more than two parameters and three lines of code in the function. Show the different outputs possible. Explain why they occur.
b) What effect does the non-specification of parameter evaluation order have on the writer of the compiler for XXX? on programmers who write XXX programs?
4. A compiler writer must choose a data structure to use for building the symbol table. Among the possible choices are:
a. linked list.
b. binary tree.
c. hash table.
In a few sentences for each, list the ADVANTAGES and DISADVANTAGES of each of these. Be sure to list why each is good (or bad) for the special requirements of a symbol table. You may assume a standard block-structured language such as C, Java, or Ada in your answer.