示例#1
0
 bool lookahead_newline() {
     while (m_curr_char == ' ') {
         save_and_next();
     }
     if (m_curr_char == '\n') {
         next();
         m_line++;
         m_buffer.reset();
         return true;
     }
     if (m_curr_char == '#') {
         m_buffer.reset();
         m_prev_char = 0;
         read_comment();
         return true;
     }
     return false;
 }
示例#2
0
 dtoken next_token() {
     for(;;) {
         if (eos()) {
             return TK_EOS;
         }
         
         m_buffer.reset();
         switch (m_curr_char) {
         case '#': // comment
             read_comment();
             break;
         case '\n':
             next();
             m_line++;
             return TK_NEWLINE;
         case '\\':
             // here we ignore a newline if it is preceded by a backslash.
             // We need to take care, since anywhere else backshlash is used
             // as a regular character
             next();
             save_char('\\');
             if (lookahead_newline()) {
                 break;
             }
             return read_id();
         case '(':
             m_tok_pos = m_pos;
             next();
             return TK_LP;
         case ')':
             m_tok_pos = m_pos;
             next();
             return TK_RP;               
         case ',':
             m_tok_pos = m_pos;
             next();
             return TK_COMMA; 
         case '=':
             m_tok_pos = m_pos;
             next();
             return TK_EQ; 
         case '!':
             m_tok_pos = m_pos;
             next();
             if(m_curr_char == '=') {
                 next();
                 return TK_NEQ;
             }
             return TK_NEG; 
         case ':':
             m_tok_pos = m_pos;
             next();
             if (m_curr_char == '-') {
                 next();
                 return TK_LEFT_ARROW;
             }
             return TK_COLON;
         case '\"':
             return read_string();
         case '|':
             next();
             return read_bid();
         default:
             if (iswspace(m_curr_char)) {
                 next();
                 break;
             }
             else if (iswdigit(m_curr_char)) {
                 m_tok_pos = m_pos;
                 save_and_next();
                 return read_num();
             }
             else {
                 char old = m_curr_char;
                 m_tok_pos = m_pos;
                 save_and_next();
                 if (old == '-' && iswdigit(m_curr_char)) {
                     return read_num();
                 }
                 else {
                     return read_id();
                 }
             }
         }
     }
 }