diff options
author | Marvin Borner | 2019-08-14 18:28:10 +0200 |
---|---|---|
committer | Marvin Borner | 2019-08-14 18:28:10 +0200 |
commit | 38aad3dcda01fc5ed82556dbfdf4cfc30ff479d9 (patch) | |
tree | c38ac3df2f68e820f408c03468c43433e98f4be6 | |
parent | d9d9fbdd9d13a5eadc5c57ac19405983cfe11b2e (diff) |
Began syntactical analysis
-rw-r--r-- | src/Lexical.kt | 16 | ||||
-rw-r--r-- | src/Syntax.kt | 7 | ||||
-rw-r--r-- | src/Testing.kt | 7 | ||||
-rw-r--r-- | src/TokenTypes.kt | 14 |
4 files changed, 23 insertions, 21 deletions
diff --git a/src/Lexical.kt b/src/Lexical.kt index 1655805..df60a8e 100644 --- a/src/Lexical.kt +++ b/src/Lexical.kt @@ -13,6 +13,7 @@ class Lexical { if (buffer == "\"") stringMode = true buffer = "" } + if (tokenType == TokenType.Empty) buffer = "" } return tokens } @@ -65,18 +66,3 @@ class Lexical { private val brackets = listOf("(", ")", "[", "]", "{", "}") // TODO: Use brackets for functions private val classifier = listOf("\"") // TODO: Add char mode e.g 'a' } - -enum class TokenType { - Keyword, - Assignment, - Arithmetic, - Comparison, - Logical, - Identifier, - Constant, - Punctuation, - Bracket, - Classifier, - Empty, - Skip -}
\ No newline at end of file diff --git a/src/Syntax.kt b/src/Syntax.kt new file mode 100644 index 0000000..7d7ab9d --- /dev/null +++ b/src/Syntax.kt @@ -0,0 +1,7 @@ +class Syntax { + fun check(tokens: MutableList<Pair<String, TokenType>>) { + for (token in tokens) { + print(token) + } + } +}
\ No newline at end of file diff --git a/src/Testing.kt b/src/Testing.kt index 4e4ec0d..d1e6b17 100644 --- a/src/Testing.kt +++ b/src/Testing.kt @@ -2,12 +2,7 @@ class Testing { init { val source = Loader("/home/melvin/coding/run/example.run").load() val tokens = Lexical().analyze(source) - for (token in tokens) { - print(token.first) - print(" => ") - print(token.second) - print("\n") - } + Syntax().check(tokens) print(source) } }
\ No newline at end of file diff --git a/src/TokenTypes.kt b/src/TokenTypes.kt new file mode 100644 index 0000000..9e15b5a --- /dev/null +++ b/src/TokenTypes.kt @@ -0,0 +1,14 @@ +enum class TokenType { + Keyword, + Assignment, + Arithmetic, + Comparison, + Logical, + Identifier, + Constant, + Punctuation, + Bracket, + Classifier, + Empty, + Skip +}
\ No newline at end of file |