Skip to content

Commit

Permalink
fix bug in reading blank lines from the input [issue #1]
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasCartman committed Feb 27, 2021
1 parent fc8ed79 commit bac688e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 22 additions & 3 deletions analisadorLexico/Lexer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.BufferedReader
import java.io.File

class Lexer() {
val automatonRelationalOperators = AutomatonRelationalOperators()
private val automatonRelationalOperators = AutomatonRelationalOperators()
lateinit var sourceCode: List<String>
var line = 0
var position = 0
Expand All @@ -25,11 +25,14 @@ class Lexer() {
char = nextChar()
}

//println(sourceCode)
/*
for(page in sourceCode) {
println(page)
}
*/

}

private fun readFileAsLinesUsingReadLines(fileName: String): List<String>
Expand All @@ -43,10 +46,26 @@ class Lexer() {
char
}
// The actual line is valid, but the position variable is a the end of line
else if(sourceCode.size > line + 1 && sourceCode[line].length <= position){
else if(sourceCode.size > line + 1 && sourceCode[line].length <= position) {
line += 1
position = 0
sourceCode[line][position]
// Checks if is an empty line (this include spaces if there are just them in the line)
if(sourceCode[line].isNotEmpty()) {
val char = sourceCode[line][position]
position += 1
return char
} else {
while (sourceCode.size > line + 1 && sourceCode[line].isEmpty()) {
line += 1
}
return if(sourceCode.size > line) {
val char = sourceCode[line][position]
position += 1
char
} else {
null
}
}
}
// There's no more line to read
else {
Expand Down
3 changes: 3 additions & 0 deletions input/entrada1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ if(c > a) {
}
c<=a
a == i



c!= i

0 comments on commit bac688e

Please sign in to comment.