<html>
<MD!salutation!name> Dear <MU!name> </MD>
<MD!JohnN> John </MD>
<MU!salutation!JohnN>:
How are you?
</html>
You could rewrite it as:
<html>
<MD!JohnN> John </MD>
<p>
<MD!name> <MU!JohnN> </MD>
Dear <MU!name>
</p>
How are you?
</html>
Assume that your preprocessor can introduce paragraphs whenever it needs a new scope; i.e., for this assignment, adding extra paragraphs is acceptable. Given this caveat, the above rewriting produces a program which will have the desired output when you pass it through your solution to Stage 2. The interesting lines above are:
<p>
<MD!name> <MU!JohnN> </MD>
Dear <MU!name>
</p>
These lines are effectively a copy verbatim the body of the macro "salutation". The key difference is the <p>...</p> which is used to start a scope and that there is a new macro definition for macro "name". In other words, I've simply replicated the body of the macro salutation and added declarations for each parameter to the macro. Thus, now rather than accessing parameters the macro body will access the new macros (such as "name") and thus does not need parameters.
While this rewriting works for our example, does it always work? Give an example where the above rewriting does not work (hint: what happens when "salutation" uses macros other than its parameters in the body).
2. In the description of Project 1, I mentioned the different kinds of abstract syntax tree nodes that I use: MacroDefNode, MacroUseNode, BoldNode, PlainTextNode, ParaNode, ListItemNode, ListNode, and HtmlNode. These nodes have the obvious meaning, for example, HtmlNode represents <html>...</html> and BoldNode represents <B>...</B>. Draw the abstract syntax tree for the example you give in question 1 (i.e., the example for which text rewriting does not work). For each node of the tree give the kind of node it is (e.g., ParaNode) and the attributes of the nodes (e.g., a symbol table would be associated with a ParaNode). Give an algorithm based on your abstract syntax tree how you would transform the tree to eliminate the macro parameters and discuss why your algorithm based on the abstract syntax tree will not have the problem you found in Question 1.