Recent Question/Assignment

Requirements in the description
This is a “take home” exam. It is open book, open notes, open Internet, but you may not discuss any part of the exam with any person other than the instructor. It is, if you consider the number and difficulty of the questions, not difficult.
There are items that need to be drawn in this exam. These drawings may be the slowest part of the test for those who have no or limited experience with the drawing tools available on virtually all personal computers, but such applications provide adequate tools for doing this digitally. At most, once you have a drawing or graph completed you will only need to do some copy-and-paste work. Word itself has good drawing tools and thus does not require copying a pasting. PowerPoint excellent ones and even Excel’s drawing tools can prove adequate. On a Windows PC with Microsoft Office Paint can be used. Comparable tools are available in the Apple and Linux environments. A last resort is pencil-and-paper, photographing and pasting into the exam document. If you do not have access to Microsoft Word, consider using Open Office or Libre Office, both of which are available for free.
NOTE: You must submit as a single document. Canvas has its limitations, so you will need to submit a single document, and not more. If this proves to be a problem, discuss it with the instructor by phoning him.
Space is provided at the top of each page for your name. Please use it.
If you believe any question is “broken” (you believe there is no fully correct answer to the problem as stated) the CORRECT answer is to explain why the problem cannot be answered as stated and how it might be fixed. This does not mean there are or are not such questions on this exam, but is intended to force students to understand the material better.

1. Java uses a braces (‘{‘ and ‘}’) to start and end all compound statements. What are the arguments for and against this design feature? Contrast this with the ‘begin’/’end’ usage of some languages as delimiters for compound statements or statement blocks.
2. What are arguments for and against case-sensitive user defined names, such as in C and Java?

3. Using the provided grammar, show a parse tree and a leftmost derivation for the following:
A = A * ( B + (C * A))
assign ? id = expr
id ? A | B | C
expr ? id + expr
| id * expr
| ( expr )
| id

4. Using the virtual machine instruction set below, write an operational semantic definition of the C for loop shown below.
C for loop: for (n = 0; n = 1024; n++) { . . . }
Virtual Machine Instruction Set:
Ident = var
ident = ident + 1
ident = ident – 1
goto label
if var relop var goto label

5.a Write a grammar for the language anbn+1dmcm+2dp, where n 1 m 0, p = 1.
5.b Draw a parse tree for the sentence ‘aabbbddccccdd’ using the above grammar.
6. Consider the following skeletal C function:
void fun(void) {
int a, b, c; // definition 1

while (…) {
int b, c, d; // definition 2
… // - - - - - - - point 1
while (…) {
int c, d, e; // definition 3
… // - - - - - - point 2
… // - - - - - - - point 3
… // - - - - - - - - point 4
For each of the four marked points in this function, list each visible variable, along with the number of the definition statement that defines it.
Point 1 Point 2 Point 3 Point 4
variable defined variable defined variable defined variable defined

7. Using the provided grammar, show the parse tree, the phrases, simple phrases and handle for the right sentential form string aaAbBb.
S ? aAb | bBA
A ? ab | aAB
B ? bB | b
8. In the ML programming language, write a function, named length that returns the length of a list, without using an ML library function. (Example: length([1,17,23,8,2]) returns 5.)
9. Explain the reasoning behind the - operator/notation used in C and C++.

10. Show the stack, including all activation records, static and dynamic chains, when execution reaches position A in the following skeletal program, given the calling sequence following the program. You must show to which activation record each static and dynamic link refers by drawing an arrow from such a link to the activation record it refers to. The next page is provided for your answer, rather than using the back of a page.
procedure Basesub is
procedure First(Flag : Boolean) is
procedure Second is
begin -- Second
end; -- Second
begin -- First
if flag
then Second;
else Third;
end; -- First
procedure Third is
procedure Fourth is
begin -- Fourth
… -- position A: show stack at this point in execution.
end; -- Fourth
begin -- Third
end; -- Third
begin -- Basesub
end; -- Basesub
Calling sequence:
Basesub calls First
First calls Second
Second calls First
First calls Third
Third calls Fourth
(Yes, you can create additional pages for this and any other question as needed.)