Top  Previous  Next

Examples > Java > Function-Table


By the function table wizard you now can insert a frame for evaluating the parse tree.


Who don't like to reproduce the following steps in detail can load the ready result made by the function table wizard also directly:





If you study the parse tree in the variable inspector, you will recognize, that it consists of branches with the names of productions and there is a node for every token with the label: IgLit. A function table shall be produced, with functions for the treatment of the nodes of all labels.

The IgLit nodes are primarily important for the copy program since the complete source text is available in the two sub-nodes. All the production nodes can be treated uniform: they serve as inter-stations for the iteration to the IgLit nodes.

So only two functions are needed, altogether:


Default function for the treatment of the production nodes

IgLit function for the treatment of the IgLit nodes




On the Start page of the function table wizard select: Create new table. So you come to the second page. The fields of this page should be filled as depicted:





On the next page select : Function for a single label

On the next page write the label: IgLit




"package"  {{IgLit(n, "Literal");}}


On the next page write the function name: CopyIgLit and for the name of the default function: CopyDefault.




As default function choose iteration on the next page.




This function is for the iteration to the IgLit-nodes.

On the next page choose value and change the text to:



node pos = xnNode.firstChild();

out << pos.value();

pos = pos.nextSibling();

out << pos.value();



This function writes both parts of text of an IgLit-node.





Now you will come to the last page and click on the Finish button.




By Cancel you can close the function table wizard now.

On the element page you can see, that a function table and two functions are inserted.


The copy project nearly is ready now. Unfortunately, there is a flaw. On the token page the tree wizard had inserted code for the addition of the token strings only and nor for the ignored characters. So you have to change the actions on the token page manually to:


{{IgLit(xn, "LITERAL");}}


The last thing you have to do is to call the evaluation of the tree. Change


"/* Breakpoint */"


in the action at the end of CompilationUnit to:




If you execute this project the java source code will be copied into the output window.


This page belongs to the TextTransformer Documentation

Home  Content  German