We present algorithms for the translation of statecharts to the Abstract Machine Notation of the B method. These algorithms
have been implemented in iState, a tool for translating statecharts to various programming languages. The translation proceeds in several phases. We give
a model of statecharts, a model of the code in AMN, as well as the intermediate representations in terms of class diagrams
and their textual counterpart. The translation algorithms are expressed in terms of these models. We also discuss optimizations
of the generated code. The translation scheme is motivated by making the generated code comprehensible.