From ab2f19e0279c2123688f33b54f8e9f95be9c1734 Mon Sep 17 00:00:00 2001 From: Kagura Date: Mon, 17 Jun 2024 13:06:46 +0800 Subject: [PATCH] Remove Unused Variables --- LL1/src/AnalyzeTable.kt | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/LL1/src/AnalyzeTable.kt b/LL1/src/AnalyzeTable.kt index 796271d..f22ef5b 100644 --- a/LL1/src/AnalyzeTable.kt +++ b/LL1/src/AnalyzeTable.kt @@ -5,7 +5,6 @@ class AnalyzeTable { var table = mutableMapOf() // k = E,i; v = 1 var items = mutableListOf() // 文法 - var first = mutableMapOf>() // First(E) var start = "" // 开始符号 companion object { @@ -19,14 +18,15 @@ class AnalyzeTable { T -> FT' T' ::= *FT'|ε F -> (E)|i - """.trimIndent()) + """.trimIndent() + ) constructor(lang: String, _s: String? = null) { - start = _s?:lang.trim()[0].toString() + start = _s ?: lang.trim()[0].toString() - val lang = if ("::=" in lang){ // 换成一个符号方便 - lang.replace("::=","->") - }else{ + val lang = if ("::=" in lang) { // 换成一个符号方便 + lang.replace("::=", "->") + } else { lang } @@ -70,7 +70,7 @@ class AnalyzeTable { val vn = item.split("->")[0] val right = item.split("->")[1] - val firsts = getFirst(right, vn) + val firsts = getFirst(right) firsts.forEach { if (it != NULL) { table["$vn,$it"] = items.indexOf(item) @@ -90,7 +90,7 @@ class AnalyzeTable { } } - private fun getFirst(string: String, vn: String): MutableList { + private fun getFirst(string: String): MutableList { val firsts = mutableListOf() // 以NULL开头 if (string == NULL) { @@ -101,11 +101,6 @@ class AnalyzeTable { // 以终结符开头 V_t.forEach { if (string.startsWith(it)) { - if (first[vn] != null) { - first[vn]!!.add(it) - } else { - first[vn] = mutableListOf(it) - } if (!firsts.contains(it)) { firsts.add(it) } @@ -125,7 +120,7 @@ class AnalyzeTable { for (line in items) { if (line.split("->")[0] == item) { val newLine = line.split("->")[1] - val nextFirst = getFirst(newLine, item) // 求 item的follow + val nextFirst = getFirst(newLine) // 求 item的follow nextFirst.forEach { if (it !in newFirst) { newFirst.add(it) @@ -173,7 +168,7 @@ class AnalyzeTable { } else -> { - val upFirst = getFirst(split, l) + val upFirst = getFirst(split) upFirst.forEach { if (it != NULL) { follows.add(it) @@ -312,5 +307,5 @@ class AnalyzeTable { } } - class UnknownSymbolException(msg: String) : Exception("\n"+msg) + class UnknownSymbolException(msg: String) : Exception("\n" + msg) } \ No newline at end of file