Top  Previous  Next

Scripts > Productions > Actions


Before and after the recognition of a token or the call of a production semantic actions can be executed.(In very special cases this is possible during the recognition too.) Mostly these actions are used to process the last recognized section of text. The instructions, which shall be executed, are inserted into the text of a production. To distinguish them, they are included in special brackets. The instructions are formulated in c++.

The TextTransformer can interpret a sub set of c++ directly. But when generating source code c++ can be used without limitations. The code is just copied in this case. To distinguish between code, that shall be checked and executed internally and code, that shall be exported, there are different kinds of brackets.



{-...-}        Semantic action inside the interpreter

{_..._}        Semantic action to export into the generated code

{=...=}        Exportable semantic action, which also is executed by the interpreter

{{...}}        Semantic action for export or of the interpreter according to the option set



The sub set of c++, which the TextTransformer can interpret is presented in the next chapter


A typical example of an action is to copy the last recognized section of text into the output


{{out << xState.str();}}



The syntax of the semantic actions is checked by the TextTransformer only in so far, as they are intended for the interpreter. Only the c++ compiler will check code that simply will be copied into the generated parser.


The different kinds of brackets cannot be applied in the conditions of IF-structures and WHILE-structures. This code always is both: interpretable and exportable.



The project EditProds demonstrates the parallel use of semantic code for the interpreter and different code for the export.



This page belongs to the TextTransformer Documentation

Home  Content  German