Abstract

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. The 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.

Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.