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