if (a < b) { while (c > d * 2) { b = a + 1; a = c * (b + c + d); a = a + 1; d = c * (b + c + d); } b = a + 1; } c = a + 1; |
Translate the program segment to an abstract syntax tree (by drawing the tree).
Remember that a concrete syntax tree, or parse tree, contains nodes for all productions that were used to reduce the input string to the start symbol. With a grammar similar to some that we have seen in the course, a parse tree for the input 2 + 2 might look like this:
An abstract syntax tree, or just syntax tree, is a simplified version of the parse tree, where nodes that are not needed have been remove or folded into each other:
b) Identify the basic blocks and draw the flow graph. (The flow graph, with the three-address code in it, is sufficent as answer to both a and b.)
b) Are there any non-block-local optimizations (optimizations that involve several basic blocks) that can be done?
There are some solutions to some of the questions, but try to solve them yourself first.