First page Back Continue Last page Summary Graphic
The Final Solution
void nextToken() {
outer: while (true) {
while (ch <= ' ')
nextCh();
buf.setLength(0);
switch (ch) {
case EOF_CH:
token = EOF;
return;
case '-': case '+':
buf.append(ch); nextCh();
if ((ch < '0') || (ch > '9')) error("missing number");
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
buf.append(ch); nextCh();
while ((ch >= '0') && (ch <= '9')) {
buf.append(ch); nextCh();
}
token = NUM; chars = buf.toString(); return;
...
case '/':
nextCh();
if (ch == '=') {
token = NEQ; nextCh();
} else if (ch == '*') {
do {
nextCh();
while (ch == '*') {
nextCh(); if (ch == '/') {nextCh(); continue outer;}
}
} while (ch != EOF_CH);
error("unclosed comment");
} else
error("missing =");
return;
default:
error("illegal character: " + ch);
}
}
}