diff options
author | Marvin Borner | 2019-08-14 23:58:10 +0200 |
---|---|---|
committer | Marvin Borner | 2019-08-14 23:58:10 +0200 |
commit | 8039d51f78f7a1cb0acc74a3e8f09d4a522cf6f2 (patch) | |
tree | f046eba3415f8385b0d20f54131c7ddf549959d5 /src/runMain/kotlin/Lexical.kt | |
parent | 46f00834b7c11c35bda6857aeaefefe5c81bb5cc (diff) |
Added ending of statements via ;
Diffstat (limited to 'src/runMain/kotlin/Lexical.kt')
-rw-r--r-- | src/runMain/kotlin/Lexical.kt | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/runMain/kotlin/Lexical.kt b/src/runMain/kotlin/Lexical.kt index 8529036..7cd66af 100644 --- a/src/runMain/kotlin/Lexical.kt +++ b/src/runMain/kotlin/Lexical.kt @@ -1,20 +1,25 @@ -import exceptions.UnknownType +import exceptions.* class Lexical { - fun analyze(source: String): MutableList<Pair<String, TokenType>> { + fun analyze(source: String): MutableList<MutableList<Pair<String, TokenType>>> { var buffer = "" - var statementEnd = false - val tokens = mutableListOf<Pair<String, TokenType>>() + var statementEnd: Boolean + val statements = mutableListOf<MutableList<Pair<String, TokenType>>>() + val currentStatement = mutableListOf<Pair<String, TokenType>>() for (i in source.indices) { buffer += source[i] statementEnd = source[i] == ';' val tokenType = getTokenType(buffer, if (source.length > i + 1) source[i + 1] else ' ') - if (tokenType != TokenType.Skip) { - tokens += buffer to tokenType + if (tokenType != TokenType.Skip && !statementEnd) { + currentStatement.add(buffer to tokenType) + buffer = "" + } else if (statementEnd) { + statements.add(currentStatement.toMutableList()) + currentStatement.clear() buffer = "" } } - return tokens + return statements } /** |