Compiler/lexical analyzer: Difference between revisions

m
Line 9,967:
getNextChar()
} // while
if (text.equalsisEmpty(""))
error(line, pos, "Lexer: Unrecognized character: (%d) %c".
format(this.chr.code, this.chr))
Line 10,391:
// With no source specified, run the test of all symbols.
fun main(args: Array<String>) {
try {
if (args.size > 1) { // file specified on command line
tryval {s =
valif f(args.size => 0 && java.io.File(args[10].isNotEmpty()) // file on command line
val s = java.util.Scanner(fjava.io.File(args[0]))
varelse source =// ""use the console
while (s java.hasNextutil.Scanner()System.`in`)
var source += s.nextLine()+""
ifwhile (s.hasNext())
source += "\n"s.nextLine()+
if else(s.hasNext())
"\n"
else
""
if (args.size > 1)0 {&& args[0].isNotEmpty()) // file specified on command line
Lexer(source).printTokens()
} catch(e: Throwable)else {
println(e.message)
} // try
} else { // use the console
try {
val s = java.util.Scanner(System.`in`)
var source = ""
while (s.hasNext())
source += s.nextLine()+
if (s.hasNext())
"\n"
else
""
val digits = source.filter { it in '0'..'9' }
when {
Line 10,426 ⟶ 10,417:
Lexer(source).printTokens()
} // when
} catch(e:// Throwable) {if
} printlncatch(e.message: Throwable) {
} // tryprintln(e.message)
} // if System.exit(1)
} // maintry
} // main</lang>
{{out|case=test case 3}}
<b>