Java Reference
In-Depth Information
Exercises
1. Extend the semantic analysis, reachability, and throws visitors for if state-
ments (Section 9.1.2) to handle the special case in which the condition
expression can be evaluated, at compile time, to true or false.
2. Assume that we add a new kind of conditional statement to C or Java,
the signtest . Its structure is:
signtest ( exp ) {
neg: stmts
zero: stmts
pos:
stmts
}
The integer expression exp is evaluated. If it is negative, the statements
following neg are executed. If it is zero, the statements following zero
are executed. If it is positive, the statements following pos are executed.
Show the AST you would use for this construct. Revise the semantic
analysis, reachability, and throws visitors for if statements (Section 9.1.2)
to handle the signtest.
3. Assume we add a new kind of looping statement, the exit-when loop to C
or Java. This loop is of the form:
loop
statements1
exit when expression
statements2
end
First, the statements in statements1 are executed. Then, expression
is evaluated. If it is true, then the loop is exited. Otherwise, the state-
ments in statements2 and statements1 are executed. Next expression
is reevaluated and the loop is conditionally exited. This process repeats
until expression eventually becomes true (or else the loop iterates for-
ever).
Show the AST you would use for this construct. Revise the semantic
analysis, reachability, and throws visitors for while loops (Section 9.1.3)
to handle this form of loop. Be sure the special case of expression being
constant-valued is handled properly.
 
 
Search WWH ::




Custom Search