Exceptions modelling in imperative programs in terms of Petri nets
Предложен подход к моделированию обработки исключительных ситуаций в императивных программах. Рассмотрены проблематика использования исключительных ситуаций в программах, общий подход к автоматическому построению моделей программ, описан минимальный набор шаблонов семантических конструкций, необходимый для построения моделей императивных программ. В качестве примера описан процесс моделирования небольшой программы и приведена ее результирующая модель в композициональном виде. The purpose of the article is to propose an approach to the automatic generation of models of imperative programs with exceptions from the source code. Methodology. The approach defines consecutive transformations of the program beginning from the source code to the parsing tree of the program, then to an abstract semantic graph and finally to a compositional model in terms of Petri nets. Transformations are based on a set of formal principles and relations and can be performed without human intervention purely algorithmically. To build a model from the program abstract semantic graph, templates and composition rules are used. Templates describe in terms of Petri net the basic constructions of imperative programming languages: expressions, branching, loops, choice and function call. Findings. A set of templates for modelling the exception handling mechanism is described. This set includes templates for the try and catch blocks describing the processing of the exception in local places of the program, the throw operator to signal the exception, and the operator of the function call with exceptions. Оriginality/value. The article demonstrates that the proposed set of templates allows building a complete model of the program with exceptions, consisting of several functions. The resulting program model makes it possible to analyze the program behavior by standard for Petri nets formal methods. In particular, a possibility of an abnormal termination due to an exceptional situation can be validated and where each particular exception is handled as well as what exceptions are handled in a particular catch block.