diff --git a/build.gradle b/build.gradle index 05d4341..fa563b6 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ repositories { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + runtime group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61' testCompile group: 'junit', name: 'junit', version: '4.12' } diff --git a/src/main/kotlin/SMNP.kt b/src/main/kotlin/SMNP.kt index c347f37..c5a5983 100644 --- a/src/main/kotlin/SMNP.kt +++ b/src/main/kotlin/SMNP.kt @@ -1,8 +1,5 @@ -import dsl.token.tokenizer.DefaultTokenizer import interpreter.Interpreter -import java.io.File fun main(args: Array) { val interpreter = Interpreter() - interpreter.run(File("/home/bartek/Developent/SMNP-Kotlin/examples/adeste.mus")) } \ No newline at end of file diff --git a/src/main/kotlin/dsl/ast/node/Node.kt b/src/main/kotlin/dsl/ast/node/Node.kt new file mode 100644 index 0000000..21f1b41 --- /dev/null +++ b/src/main/kotlin/dsl/ast/node/Node.kt @@ -0,0 +1,36 @@ +package dsl.ast.node + +import dsl.token.model.entity.TokenPosition + +class NoneNode : Node(0, TokenPosition.NONE) + +abstract class Node(numberOfChildren: Int, val position: TokenPosition) { + protected var children: Array = Array(numberOfChildren) { NONE } + + constructor(children: Array, position: TokenPosition) : this(children.size, position) { + this.children = children + } + + operator fun get(index: Int) = children[index] + + operator fun set(index: Int, value: Node) { + children[index] = value + } + + fun pretty(prefix: String = "", last: Boolean = true, first: Boolean = true) { + var newPrefix = prefix + var newLast = last + val newFirst = first + + println(newPrefix + (if (newFirst) "" else if (newLast) "└─" else "├─") + this::class.simpleName + " " + position) + newPrefix += if (newLast) " " else "│ " + for((index, child) in children.withIndex()) { + newLast = index == children.size - 1 + child.pretty(newPrefix, newLast, false) + } + } + + companion object { + val NONE = NoneNode() + } +} \ No newline at end of file