{"id":13352,"date":"2022-08-21T10:49:27","date_gmt":"2022-08-21T07:49:27","guid":{"rendered":"http:\/\/journals.khnu.km.ua\/vestnik\/?p=13352"},"modified":"2022-10-04T09:08:41","modified_gmt":"2022-10-04T06:08:41","slug":"metod-deklaratyvnogo-metaprogramuvannya-na-osnovi-predmetno-oriyentovanyh-mov-programuvannya","status":"publish","type":"post","link":"https:\/\/journals.khnu.km.ua\/vestnik\/?p=13352","title":{"rendered":"\u041c\u0435\u0442\u043e\u0434 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0456 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0456\u0454\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0445 \u043c\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f"},"content":{"rendered":"<p><!--more--><\/p>\n<p style=\"text-align: center;\">\u041c\u0415\u0422\u041e\u0414 \u0414\u0415\u041a\u041b\u0410\u0420\u0410\u0422\u0418\u0412\u041d\u041e\u0413\u041e \u041c\u0415\u0422\u0410\u041f\u0420\u041e\u0413\u0420\u0410\u041c\u0423\u0412\u0410\u041d\u041d\u042f \u041d\u0410 \u041e\u0421\u041d\u041e\u0412\u0406 \u041f\u0420\u0415\u0414\u041c\u0415\u0422\u041d\u041e-\u041e\u0420\u0406\u0404\u041d\u0422\u041e\u0412\u0410\u041d\u0418\u0425 \u041c\u041e\u0412 \u041f\u0420\u041e\u0413\u0420\u0410\u041c\u0423\u0412\u0410\u041d\u041d\u042f<\/p>\n<p style=\"text-align: center;\">METHOD OF THE DECLARATIVE METAPROGRAMMING BASED ON DOMAIN-SPECIFIC PROGRAMMING LANGUAGES<\/p>\n<p><strong>\u0421\u0442\u043e\u0440\u0456\u043d\u043a\u0438:\u00a0<\/strong><strong>249<\/strong><strong>&#8211;<\/strong><strong>255<\/strong><strong>. \u041d\u043e\u043c\u0435\u0440: \u21164, 2022 (311)\u00a0\u00a0<a href=\"http:\/\/journals.khnu.km.ua\/vestnik\/wp-content\/uploads\/2022\/08\/vknu-ts-2022-n4311-249-255.pdf\"> <img loading=\"lazy\" class=\"size-full wp-image-69 alignnone\" src=\"http:\/\/journals.khnu.km.ua\/vestnik\/wp-content\/uploads\/2021\/01\/pdf.png\" alt=\"\" width=\"76\" height=\"32\" \/><\/a> <\/strong><br \/>\n<strong>\u0410\u0432\u0442\u043e\u0440\u0438:<\/strong><br \/>\n\u0421\u0422\u0410\u0412\u0418\u0426\u042c\u041a\u0418\u0419 \u041f. \u0412.<br \/>\n\u0412\u0456\u043d\u043d\u0438\u0446\u044c\u043a\u0438\u0439 \u043d\u0430\u0446\u0456\u043e\u043d\u0430\u043b\u044c\u043d\u0438\u0439 \u0442\u0435\u0445\u043d\u0456\u0447\u043d\u0438\u0439 \u0443\u043d\u0456\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442<br \/>\n<a href=\"https:\/\/orcid.org\/0000-0002-9139-6076\">https:\/\/orcid.org\/0000-0002-9139-6076<\/a><br \/>\ne-mail: <a href=\"mailto:pavlo.stavytskyi@gmail.com\">pavlo.stavytskyi@gmail.com<\/a><br \/>\n\u0412\u041e\u0419\u0422\u041a\u041e \u0412. \u0412.<br \/>\n\u0412\u0456\u043d\u043d\u0438\u0446\u044c\u043a\u0438\u0439 \u043d\u0430\u0446\u0456\u043e\u043d\u0430\u043b\u044c\u043d\u0438\u0439 \u0442\u0435\u0445\u043d\u0456\u0447\u043d\u0438\u0439 \u0443\u043d\u0456\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442<br \/>\n<a href=\"https:\/\/orcid.org\/0000-0002-3329-7256\">https:\/\/orcid.org\/0000-0002-3329-7256<\/a><br \/>\ne-mail: <a href=\"mailto:defakfki@i.ua\">defakfki@i.ua<\/a><br \/>\nPavlo STAVYTSKYI, Viktoriia VOITKO<br \/>\nVinnytsia National Technical University<br \/>\n<strong>DOI:<\/strong>\u00a0<a href=\"https:\/\/www.doi.org\/10.31891\/2307-5732-2022-311-4-249-255\">https:\/\/www.doi.org\/10.31891\/2307-5732-2022-311-4-249-255<\/a><\/p>\n<p style=\"text-align: center;\"><strong>\u0410\u043d\u043e\u0442\u0430\u0446\u0456\u044f \u043c\u043e\u0432\u043e\u044e \u043e\u0440\u0438\u0433\u0456\u043d\u0430\u043b\u0443<\/strong><\/p>\n<p>\u0420\u043e\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0456\u044e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f, \u0430 \u0441\u0430\u043c\u0435 \u0433\u0435\u043d\u0435\u0440\u0443\u0432\u0430\u043d\u043d\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0443, \u0449\u043e \u0431\u0430\u0437\u0443\u0454\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u0430\u043d\u043d\u0456 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0456\u0454\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0445 \u043c\u043e\u0432. \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u0456\u0441\u0442\u044c \u043f\u043e\u043b\u044f\u0433\u0430\u0454 \u0443 \u0442\u043e\u043c\u0443, \u0449\u043e \u0432\u0445\u0456\u0434\u043d\u0438\u0439 \u043a\u043e\u0434, \u044f\u043a\u0438\u0439 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0430\u0454 \u0437\u0430 \u0433\u0435\u043d\u0435\u0440\u0443\u0432\u0430\u043d\u043d\u044f \u043a\u043e\u0434\u0443 \u0437\u0430 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u043d\u0438\u043c\u0438 \u043e\u0437\u043d\u0430\u043a\u0430\u043c\u0438, \u0454 \u044f\u043a\u043e\u043c\u043e\u0433\u0430 \u0431\u043b\u0438\u0436\u0447\u0438\u043c \u0434\u043e \u0432\u0438\u0445\u0456\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0443\u044e\u0447\u043e\u0433\u043e \u043a\u043e\u0434\u0443. \u0412 \u044f\u043a\u043e\u0441\u0442\u0456 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0456\u0457 \u043c\u0435\u0442\u043e\u0434\u0443 \u0440\u043e\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043d\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0443\u0432\u0430\u043d\u043d\u044f \u043a\u043e\u0434\u0443 \u043c\u043e\u0432\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f Starlark, \u0449\u043e \u0454 \u0434\u0456\u0430\u043b\u0435\u043a\u0442\u043e\u043c Python. \u0423 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u043e\u0441\u043b\u0456\u0434\u0436\u0435\u043d\u043d\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0456\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f \u0440\u0435\u0430\u043b\u0456\u0437\u0443\u0454\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0430\u0437\u0456 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0456\u0454\u043d\u0442\u043e\u0432\u0430\u043d\u043e\u0457 \u043c\u043e\u0432\u0438, \u0449\u043e \u0456\u043c\u0456\u0442\u0443\u0454 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u043d\u0456 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0456\u0457 \u043c\u043e\u0432\u0438 Starlark. \u0420\u043e\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0438 \u043c\u043e\u0432\u0438 Starlark, \u0440\u0435\u0430\u043b\u0456\u0437\u043e\u0432\u0430\u043d\u0456 \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0456\u0454\u043d\u0442\u043e\u0432\u0430\u043d\u043e\u0457 \u043c\u043e\u0432\u0438 \u043d\u0430 \u0431\u0430\u0437\u0456 Kotlin, \u0437\u043e\u043a\u0440\u0435\u043c\u0430, \u0456\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0456\u0457 \u043f\u0440\u0438\u0441\u0432\u043e\u0454\u043d\u043d\u044f, \u0441\u043f\u0438\u0441\u043a\u043e\u0432\u0456 \u0432\u0438\u0440\u0430\u0437\u0438, \u0432\u0438\u0440\u0430\u0437\u0438 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0456\u0457, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430\u0440\u0456\u0437\u0430\u043d\u043d\u044f \u043c\u0430\u0441\u0438\u0432\u0456\u0432, \u0432\u0438\u043a\u043b\u0438\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0456\u0439 \u0442\u043e\u0449\u043e.<br \/>\n<strong>\u041a\u043b\u044e\u0447\u043e\u0432\u0456 \u0441\u043b\u043e\u0432\u0430:<\/strong> \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f, \u043c\u0435\u0442\u0430\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443\u0432\u0430\u043d\u043d\u044f, \u0433\u0435\u043d\u0435\u0440\u0443\u0432\u0430\u043d\u043d\u044f \u043a\u043e\u0434\u0443, \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0456\u0454\u043d\u0442\u043e\u0432\u0430\u043d\u0430 \u043c\u043e\u0432\u0430, Kotlin, Starlark, Python.<\/p>\n<p style=\"text-align: center;\"><strong>\u0420\u043e\u0437\u0448\u0438\u0440\u0435\u043d\u0430 \u0430\u043d\u043e\u0442\u0430\u0446\u0456\u044f \u0430\u043d\u0433\u043b\u0456\u0439\u0441\u044c\u043a\u043e\u044e \u00a0\u043c\u043e\u0432\u043e\u044e<\/strong><\/p>\n<p>A concept of declarative metaprogramming which focuses on program code generation is considered. The method is based on using domain-specific languages that are implemented by means of existing general-purpose programming languages. Since metaprogramming is based on using programs that produce other programs, the declarative approach means that the input and the output program code must be as close as possible in terms of syntax or ideally identical. In order to generate a program code, it is required to write templates that hold the exact structure of a resulting generated code but contain placeholders for specifics of concrete generated instances. Such an approach is highly useful when there is a need of generating a large number of similar program files by structure but different in details. The simplest way to define such templates would be just by constructing them from string literals by injecting the specific details using a string interpolation mechanism for example. However, such an approach does not provide type safety and compile time validation, so there is no guarantee the generated code is a correct and compilable program.<br \/>\nThe domain-specific language, on the other hand, replicates all the syntactic constructions of the target programming language so that, the resulting generated code would be the same as code written by the programmer. Moreover, having preserved all the syntax validations by the compiler on which the domain-specific language is based. The paper considers a concrete example of a code generator for a Starlark programming language, a dialect of Python while the domain specific-language is based on Kotlin language. Using the toolset of Kotlin, such a domain-specific language replicates such Starlark constructs as variable assignments, list comprehensions, library functions, slices, etc with a required level of customizability.<br \/>\n<strong>Keywords:<\/strong> declarative programming, metaprogramming, code generation, domain-specific language, Kotlin, Starlark, Python.<\/p>\n<p style=\"text-align: center;\"><strong>\u041b\u0456\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430<\/strong><\/p>\n<ol>\n<li>Ramanathan M., K., Clapp, L., Barik, R., Sridharan M. (2020). Piranha: Reducing Feature Flag Debt at Uber. https:\/\/manu.sridharan.net\/files\/ICSE20-SEIP-Piranha.pdf<\/li>\n<li>SMITH, F., GROSSMAN, D., MORRISETT, G., HORNOF, L., &amp; JIM, T. (2003). Compiling for template-based run-time code generation. Journal of Functional Programming, 13(3), 677-708. doi:10.1017\/S095679680200463X<\/li>\n<li>Starlark Language. <a href=\"https:\/\/bazel.build\/rules\/language\">https:\/\/bazel.build\/rules\/language<\/a><\/li>\n<li><a href=\"https:\/\/bazel.build\/\">https:\/\/bazel.build\/<\/a><\/li>\n<li>Gamma, E., Helm, R. and Johnson, R., 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley.<\/li>\n<li>Aho, A. V. (2007). Compilers: Principles, techniques, and tools. Pearson Addison-Wesley.<\/li>\n<li>The Python Language Reference. <a href=\"https:\/\/docs.python.org\/3\/reference\/\">https:\/\/docs.python.org\/3\/reference\/<\/a><\/li>\n<li>Stavytskyi P. (2021). Automated migration from Gradle to Bazel with Airin. BazelCon 2021, Google. <a href=\"https:\/\/youtu.be\/dz-CFEwJuko\">https:\/\/youtu.be\/dz-CFEwJuko<\/a><\/li>\n<\/ol>\n<p style=\"text-align: center;\"><strong>References<\/strong><\/p>\n<ol>\n<li>Ramanathan M., K., Clapp, L., Barik, R., Sridharan M. (2020). Piranha: Reducing Feature Flag Debt at Uber. https:\/\/manu.sridharan.net\/files\/ICSE20-SEIP-Piranha.pdf<\/li>\n<li>SMITH, F., GROSSMAN, D., MORRISETT, G., HORNOF, L., &amp; JIM, T. (2003). Compiling for template-based run-time code generation. Journal of Functional Programming, 13(3), 677-708. doi:10.1017\/S095679680200463X<\/li>\n<li>Starlark Language. <a href=\"https:\/\/bazel.build\/rules\/language\">https:\/\/bazel.build\/rules\/language<\/a><\/li>\n<li><a href=\"https:\/\/bazel.build\/\">https:\/\/bazel.build\/<\/a><\/li>\n<li>Gamma, E., Helm, R. and Johnson, R., 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley.<\/li>\n<li>Aho, A. V. (2007). Compilers: Principles, techniques, and tools. Pearson Addison-Wesley.<\/li>\n<li>The Python Language Reference. <a href=\"https:\/\/docs.python.org\/3\/reference\/\">https:\/\/docs.python.org\/3\/reference\/<\/a><\/li>\n<li>Stavytskyi P. (2021). Automated migration from Gradle to Bazel with Airin. BazelCon 2021, Google. <a href=\"https:\/\/youtu.be\/dz-CFEwJuko\">https:\/\/youtu.be\/dz-CFEwJuko<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[67],"tags":[],"_links":{"self":[{"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/posts\/13352"}],"collection":[{"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13352"}],"version-history":[{"count":5,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/posts\/13352\/revisions"}],"predecessor-version":[{"id":14225,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=\/wp\/v2\/posts\/13352\/revisions\/14225"}],"wp:attachment":[{"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journals.khnu.km.ua\/vestnik\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}