hi. I am new to Kotlin and currently I am trying to use it for my university bachelor thesis project.
Part of this project is implementation of a simple language/compiler. (for JVM, I am using ANTLR for lexer/parser and planning to use ASM library for bytecode output)
The question is, are there any good/idiomatic examples related to AST implementation?
So far I found one tutorial
https://github.com/ftomassetti/LangSandbox/blob/master/src/main/kotlin/me/tomassetti/sandy/ast/Model.kt#L79 with data classes and interfaces. It looks interesting, but I am not sure if it's the best way. For me it looks a bit weird that because of interfaces
we have to use extension functions for everything.
At first I thought that I should use abstract classes, but then I found out that I will not be able to use data classes and will have to implement `equals`/`hashCode` for all nodes manually.
Though I am not sure if I really need
equals
in AST nodes. One reason is for tests (
https://github.com/ftomassetti/LangSandbox/blob/master/src/test/kotlin/me/tomassetti/sandy/ast/MappingTest.kt), but maybe there are other good ways to test it...