First page Back Continue Last page Summary Graphic

Dealing with Whitespaces

  • void nextToken() {
  • while (ch <= ' ')
  • nextCh();
  • switch (ch) {
  • case EOF_CH:
  • token = EOF; break;
  • case '-': case '+': case '0': case '1': case '2': case '3':
  • case '4': case '5': case '6': case '7': case '8': case '9':
  • buf.setLength(0); buf.append(ch);
  • if ((ch == '-') || (ch == '+')) {
  • nextCh(); if ((ch < '0') || (ch > '9')) error("missing number");
  • } else
  • nextCh();
  • while ((ch >= '0') && (ch <= '9')) {
  • buf.append(ch); nextCh();
  • }
  • token = NUM; chars = buf.toString(); break;
  • case '<':
  • nextCh();
  • if (ch == '=') {token = LTEQ; nextCh();} else token = LT;
  • break;
  • ...
  • default:
  • error("illegal character: " + ch);
  • }
  • }
  • What about comments?