AST-based compilation of mathematical expressions in Kotlin

Iaroslav Postovalov

Interpreting mathematical expressions in runtime is a rather standard task in different fields of program engineering. There are different approaches to this problem from creating a specific language-in-a-language with its own parser and interpreter just for that task, to using a fully-fledged embedded compiler. This article is dedicated to a middle-ground solution, implemented in the KMath library. KMath uses Kotlin object builders (DSL) and its own abstractions for mathematical operations to provide a syntax to generate AST for mathematical operations. Then the AST is compiled using just-in-time JVM bytecode generation and other means. A similar approach is tested on other Kotlin platforms

Knowledge Graph

arrow_drop_up

Comments

Sign up or login to leave a comment