Java Reference
In-Depth Information
A jump table is generated containing only labels (cf. JVM
tableswitch instruction). The switch expression value is used
to index the table, starting at 0, and execution proceeds with
the resulting label. A default label is provisioned and is chosen
as the outcome if the expression's value is larger than accom-
modated by the table.
(d) Compare and contrast the above code-generation strategies for the
switch statement. Underwhich conditions is a given strategy better
or worse than the others?
8. The semantics of a WhileTestingnode accommodate Java and C's while
constructs. Languages like Java have other syntax for itneration, such
as Java's do-while construct. The body of the loop is executed, and
the predicate is then tested. If the predicate is true, then the body is
executed again. Execution continues to loop in this manner until the
predicate becomes false.
The sense of the predicate is consistent, in that iteration ceases when the
predicate test is false. However, the do-while construct executes the
loop body before the test. The CondTestingnode represents constructs
where the predicate is tested before the loop body is executed.
How would you accommodate the do-while statement? What changes
are necessary across a compiler's phases, from syntax analysis to code
generation?
9. Some languages o
er iteration constructs like C's for statment, which ag-
gregates the loop's initialization, termination, and repetition constructs
into a single construct.
Investigate the syntax and semantics of C's for statement. Develop an
AST node and suitable interface to represent its components. Design and
implement its code-generation visitor.
ff
10. Later versions of Java o
er the so-called “enhanced for” statement. In-
vestigate the syntax and semantics of that statement. Develop an AST
node and suitable interface to represent the statement. Design and im-
plement its code-generation visitor.
ff
11. Section 11.3.10 generates code that emits the predicate test as instructions
that occur before the loop body. Write a visitor method that generates
the loop body's instructions first, but preserves the semantics of the
WhileTestingnode (the predicate must execute first).
12. Write a visitor method to generate code for a ReturningAST node. Recall
that the node may, or may not, require evaluation of the return value.
 
Search WWH ::




Custom Search