From 0627e0ac4bd237f0d7d256f1cfe863440b318f55 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 15 Aug 2019 00:25:25 +0200 Subject: Added documentation --- src/runMain/kotlin/Lexical.kt | 3 +++ src/runMain/kotlin/Loader.kt | 8 +++++++- src/runMain/kotlin/Syntax.kt | 6 ++++++ src/runMain/kotlin/TokenTypes.kt | 3 +++ src/runMain/kotlin/exceptions/UnknownType.kt | 3 +++ 5 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/runMain/kotlin') diff --git a/src/runMain/kotlin/Lexical.kt b/src/runMain/kotlin/Lexical.kt index 459927c..2910bca 100644 --- a/src/runMain/kotlin/Lexical.kt +++ b/src/runMain/kotlin/Lexical.kt @@ -1,6 +1,9 @@ import exceptions.* class Lexical { + /** + * Analyzes the given [source] and returns the tokens divided into an array of statements + */ fun analyze(source: String): MutableList>> { var buffer = "" var skipStatementEnd = false diff --git a/src/runMain/kotlin/Loader.kt b/src/runMain/kotlin/Loader.kt index 3aef50a..13e1157 100644 --- a/src/runMain/kotlin/Loader.kt +++ b/src/runMain/kotlin/Loader.kt @@ -4,11 +4,17 @@ import platform.posix.* class Loader(path: String) { private val inputString = read(path) - // TODO: Add preprocessor managing imports and comments + /** + * Preprocesses the plain source code + * TODO: Add preprocessor managing imports and comments + */ fun preprocess(): String { return inputString.replace("\n", "") } + /** + * Reads a file via the [path] into a string representation + */ private fun read(path: String): String { setlocale(LC_CTYPE, "en_US.UTF-8") diff --git a/src/runMain/kotlin/Syntax.kt b/src/runMain/kotlin/Syntax.kt index 46f2306..ace7280 100644 --- a/src/runMain/kotlin/Syntax.kt +++ b/src/runMain/kotlin/Syntax.kt @@ -1,4 +1,7 @@ class Syntax { + /** + * Checks and validates whether the code complies with the syntax/grammar rules + */ fun check(statements: MutableList>>): Boolean { for (statement in statements) { removePadding(statement) @@ -6,6 +9,9 @@ class Syntax { return true } + /** + * Removed empty characters from the start and end of statements + */ private fun removePadding(statement: MutableList>) { while (statement[0].second == TokenType.Empty) { statement.removeAt(0) diff --git a/src/runMain/kotlin/TokenTypes.kt b/src/runMain/kotlin/TokenTypes.kt index 9e15b5a..aa37439 100644 --- a/src/runMain/kotlin/TokenTypes.kt +++ b/src/runMain/kotlin/TokenTypes.kt @@ -1,3 +1,6 @@ +/** + * Defines the token types which are used by the lexical analyser to classify tokens + */ enum class TokenType { Keyword, Assignment, diff --git a/src/runMain/kotlin/exceptions/UnknownType.kt b/src/runMain/kotlin/exceptions/UnknownType.kt index 4c348a5..a696891 100644 --- a/src/runMain/kotlin/exceptions/UnknownType.kt +++ b/src/runMain/kotlin/exceptions/UnknownType.kt @@ -1,3 +1,6 @@ package exceptions +/** + * Gets thrown if the entered token/code does not exist in this language + */ class UnknownType(token: String = "") : Exception("Token type not known: $token") \ No newline at end of file -- cgit v1.2.3