Logo Search packages:      
Sourcecode: jasmin-sable version File versions  Download package

static Symbol java_cup::lexer::real_next_token (  )  throws java.io.IOException [inline, static, protected]

The actual routine to return one Symbol. This is normally called from next_token(), but for debugging purposes can be called indirectly from debug_next_token().

Definition at line 448 of file lexer.java.

References advance(), do_code_string(), do_id(), emit_error(), emit_warn(), EOF_CHAR, find_single_char(), id_start_char(), next_char, next_char2, next_char3, next_char4, and swallow_comment().

Referenced by debug_next_token(), and next_token().

    {
      int sym_num;

      for (;;)
      {
        /* look for white space */
        if (next_char == ' ' || next_char == '\t' || next_char == '\n' ||
            next_char == '\f' ||  next_char == '\r')
          {
            /* advance past it and try the next character */
            advance();
            continue;
          }

        /* look for a single character symbol */
        sym_num = find_single_char(next_char);
        if (sym_num != -1)
          {
            /* found one -- advance past it and return a Symbol for it */
            advance();
            return new Symbol(sym_num);
          }

        /* look for : or ::= */
        if (next_char == ':')
          {
            /* if we don't have a second ':' return COLON */
            if (next_char2 != ':') 
            {
              advance();
              return new Symbol(sym.COLON);
            }

            /* move forward and look for the '=' */
            advance();
            if (next_char2 == '=') 
            {
              advance(); advance();
              return new Symbol(sym.COLON_COLON_EQUALS);
            }
            else
            {
              /* return just the colon (already consumed) */
              return new Symbol(sym.COLON);
            }
          }

        /* find a "%prec" string and return it.  otherwise, a '%' was found,
           which has no right being in the specification otherwise */
        if (next_char == '%') {
          advance();
          if ((next_char == 'p') && (next_char2 == 'r') && (next_char3 == 'e') && 
            (next_char4 == 'c')) {
            advance();
            advance();
            advance();
            advance();
            return new Symbol(sym.PERCENT_PREC);
          } else {
            emit_error("Found extraneous percent sign");
          }
        }

        /* look for a comment */
        if (next_char == '/' && (next_char2 == '*' || next_char2 == '/'))
          {
            /* swallow then continue the scan */
            swallow_comment();
            continue;
          }

        /* look for start of code string */
        if (next_char == '{' && next_char2 == ':')
          return do_code_string();

        /* look for an id or keyword */
        if (id_start_char(next_char)) return do_id();

        /* look for EOF */
        if (next_char == EOF_CHAR) return new Symbol(sym.EOF);

        /* if we get here, we have an unrecognized character */
        emit_warn("Unrecognized character '" + 
          new Character((char)next_char) + "'(" + next_char + 
          ") -- ignored");

        /* advance past it */
        advance();
      }
    }


Generated by  Doxygen 1.6.0   Back to index