-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.kt
47 lines (40 loc) · 1.28 KB
/
Main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import lexicalAnalyzer.FileReader
import lexicalAnalyzer.Lexer
import lexicalAnalyzer.Lexer2
import lexicalAnalyzer.LexerHelper
import parser.Parser
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
//parser.main()
//lexer.main("./input/entrada02.txt")
/*
val res = FileReader.readFileAsTextUsingInputStream("./input/entrada02.txt")
val lexer2 = Lexer2(res)
do {
val c = lexerHelper.getNextLookaheadChar()
println("char: $c -> int: ${c?.toInt()}")
}while (c != null)
var token = lexer2.getNextToken()
while(token != null) {
println("class: ${token.type.type} value: ${token.value} line: ${token.line}")
token = lexer2.getNextToken()
}
*/
readAllInputFiles()
}
private fun readAllInputFiles() {
val path = Paths.get("input").toAbsolutePath()
if(Files.exists(path) && Files.isDirectory(path)) {
File(path.toString()).walk().forEach {
val fileName = it.name
if(fileName.startsWith("entrada") && fileName.endsWith(".txt")) {
println("Reading file: $fileName")
Parser(it.absolutePath).main(fileName)
}
}
} else {
throw Exception("You need a input directory to run the compiler")
}
}