aboutsummaryrefslogtreecommitdiff
path: root/src/runMain/kotlin/Lexical.kt
diff options
context:
space:
mode:
authorMarvin Borner2019-08-17 17:53:59 +0200
committerMarvin Borner2019-08-17 17:53:59 +0200
commit75f8c215364a38ac0fc78510d1b11daa9d4f2318 (patch)
tree18c2e018b4cb210d8651a7f36b33e814c8227729 /src/runMain/kotlin/Lexical.kt
parent21a6062aa909c3bb3347f837206fdd3d2fd01af2 (diff)
Improved lexical analysis
Diffstat (limited to 'src/runMain/kotlin/Lexical.kt')
-rw-r--r--src/runMain/kotlin/Lexical.kt18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/runMain/kotlin/Lexical.kt b/src/runMain/kotlin/Lexical.kt
index 4452235..4f6c419 100644
--- a/src/runMain/kotlin/Lexical.kt
+++ b/src/runMain/kotlin/Lexical.kt
@@ -19,14 +19,15 @@ class Lexical {
buffer += source[i]
val tokenType = getTokenType(buffer, if (source.length > i + 1) source[i + 1] else ' ')
- if (tokenType != Skip && !statementEnd) {
+ if (tokenType != Skip) {
val newToken = Token()
newToken.content = buffer
newToken.type = tokenType
newToken.lineNumber = lineNumber
currentStatement.add(newToken)
buffer = ""
- } else if (statementEnd) {
+ }
+ if (statementEnd) {
statements.add(currentStatement.toMutableList())
currentStatement.clear()
buffer = ""
@@ -67,7 +68,10 @@ class Lexical {
token in punctuation -> Punctuation
- token in brackets -> Bracket
+ token in endOfStatement -> StatementEnd
+
+ token in openedBrackets -> OpenedBracket
+ token in closedBrackets -> ClosedBracket
token in classifier -> Classifier
@@ -80,8 +84,10 @@ class Lexical {
private val arithmetic = listOf("+", "-", "*", "/", "%")
private val comparison = listOf("==", "!=", "<", "<=", ">", ">=")
private val logical = listOf("&&", "||", "!")
- private val punctuation = listOf(",", ":", ".", ";")
- private val brackets = listOf("(", ")", "[", "]", "{", "}") // TODO: Use brackets for functions
+ private val punctuation = listOf(",", ":", ".")
+ private val endOfStatement = listOf(";")
+ private val openedBrackets = listOf("(", "[", "{")
+ private val closedBrackets = listOf(")", "]", "}")
private val classifier = listOf("\"", "'")
- private val emptiness = listOf(" ", "\t", "\n")
+ private val emptiness = listOf(" ", "\r", "\t", "\n")
}