Remove Unused Variables
This commit is contained in:
parent
f0be209464
commit
ab2f19e027
1 changed files with 11 additions and 16 deletions
|
@ -5,7 +5,6 @@ class AnalyzeTable {
|
||||||
var table = mutableMapOf<String, Int>() // k = E,i; v = 1
|
var table = mutableMapOf<String, Int>() // k = E,i; v = 1
|
||||||
var items = mutableListOf<String>() // 文法
|
var items = mutableListOf<String>() // 文法
|
||||||
|
|
||||||
var first = mutableMapOf<String, MutableList<String>>() // First(E)
|
|
||||||
var start = "" // 开始符号
|
var start = "" // 开始符号
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -19,14 +18,15 @@ class AnalyzeTable {
|
||||||
T -> FT'
|
T -> FT'
|
||||||
T' ::= *FT'|ε
|
T' ::= *FT'|ε
|
||||||
F -> (E)|i
|
F -> (E)|i
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
constructor(lang: String, _s: String? = null) {
|
constructor(lang: String, _s: String? = null) {
|
||||||
start = _s?:lang.trim()[0].toString()
|
start = _s ?: lang.trim()[0].toString()
|
||||||
|
|
||||||
val lang = if ("::=" in lang){ // 换成一个符号方便
|
val lang = if ("::=" in lang) { // 换成一个符号方便
|
||||||
lang.replace("::=","->")
|
lang.replace("::=", "->")
|
||||||
}else{
|
} else {
|
||||||
lang
|
lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class AnalyzeTable {
|
||||||
val vn = item.split("->")[0]
|
val vn = item.split("->")[0]
|
||||||
val right = item.split("->")[1]
|
val right = item.split("->")[1]
|
||||||
|
|
||||||
val firsts = getFirst(right, vn)
|
val firsts = getFirst(right)
|
||||||
firsts.forEach {
|
firsts.forEach {
|
||||||
if (it != NULL) {
|
if (it != NULL) {
|
||||||
table["$vn,$it"] = items.indexOf(item)
|
table["$vn,$it"] = items.indexOf(item)
|
||||||
|
@ -90,7 +90,7 @@ class AnalyzeTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFirst(string: String, vn: String): MutableList<String> {
|
private fun getFirst(string: String): MutableList<String> {
|
||||||
val firsts = mutableListOf<String>()
|
val firsts = mutableListOf<String>()
|
||||||
// 以NULL开头
|
// 以NULL开头
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
|
@ -101,11 +101,6 @@ class AnalyzeTable {
|
||||||
// 以终结符开头
|
// 以终结符开头
|
||||||
V_t.forEach {
|
V_t.forEach {
|
||||||
if (string.startsWith(it)) {
|
if (string.startsWith(it)) {
|
||||||
if (first[vn] != null) {
|
|
||||||
first[vn]!!.add(it)
|
|
||||||
} else {
|
|
||||||
first[vn] = mutableListOf(it)
|
|
||||||
}
|
|
||||||
if (!firsts.contains(it)) {
|
if (!firsts.contains(it)) {
|
||||||
firsts.add(it)
|
firsts.add(it)
|
||||||
}
|
}
|
||||||
|
@ -125,7 +120,7 @@ class AnalyzeTable {
|
||||||
for (line in items) {
|
for (line in items) {
|
||||||
if (line.split("->")[0] == item) {
|
if (line.split("->")[0] == item) {
|
||||||
val newLine = line.split("->")[1]
|
val newLine = line.split("->")[1]
|
||||||
val nextFirst = getFirst(newLine, item) // 求 item的follow
|
val nextFirst = getFirst(newLine) // 求 item的follow
|
||||||
nextFirst.forEach {
|
nextFirst.forEach {
|
||||||
if (it !in newFirst) {
|
if (it !in newFirst) {
|
||||||
newFirst.add(it)
|
newFirst.add(it)
|
||||||
|
@ -173,7 +168,7 @@ class AnalyzeTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val upFirst = getFirst(split, l)
|
val upFirst = getFirst(split)
|
||||||
upFirst.forEach {
|
upFirst.forEach {
|
||||||
if (it != NULL) {
|
if (it != NULL) {
|
||||||
follows.add(it)
|
follows.add(it)
|
||||||
|
@ -312,5 +307,5 @@ class AnalyzeTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnknownSymbolException(msg: String) : Exception("\n"+msg)
|
class UnknownSymbolException(msg: String) : Exception("\n" + msg)
|
||||||
}
|
}
|
Loading…
Reference in a new issue