LispVal* parse_string(FILE* f) { int length = 0; char data[4096]; char c = peek(f); if (c != '"') return NULL; c = get_peek(f); while ((c != '"') && (!feof(f))) { data[length] = c; length++; c = get_peek(f); } fgetc(f); return lisp_val_string(length, data); }
LispVal* parse_atom(FILE* f) { int length = 0; char data[100]; char c = peek(f); while (isalpha(c) && (!feof(f))) { data[length] = c; length++; c = get_peek(f); } return lisp_val_atom(length, data); }
LispVal* parse_number(FILE* f) { int num = 0; char c = peek(f); if (!isdigit(c)) return NULL; while (isdigit(c)) { num = (num*10) + (c-'0'); c = get_peek(f); } return lisp_val_num(num); }
void eat_space(FILE* f) { char c = peek(f); while (isspace(c)) c = get_peek(f); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // class CTokenizer next_var_token method // get a var token, and return it's type // Input: // none // Output: // none // Return: // enum var_token_type // int CTokenizer::next_var_token( bool is_key ) { signed char ch; int len = 0; // skim over space if exist if ( !m_nPrevChar ) { skim_over_space(ch); } else { ch = m_nPrevChar; m_nPrevChar = 0; } if ( ch == '[' )return VT_LSQR; if ( ch == ':' )return VT_COLON; if ( ch == ']' )return VT_RSQR; // is this a decimal number, begin with 1~9 // sequence of digits if ( ch <= '9' && ch >= '0') { do { put_char( ch, len ); ch = get_char(); if ( ch <= ' ' || ch == ':' || ch == ']') // the legal postfix of decimal number { m_nPrevChar = ch > ' ' ? ch : 0; // record the character as prev char in next var token m_strTokenWord[len] = 0; // put end character into token word m_nTokenLen = len; // get the length of token return VT_DECIMAL; } } while ( ch <= '9' && ch >= '0' ); return VT_NONE; // illegal postfix of decimal number } // is this an identifier or keyword, // begin with letters or underscore characters(_) // any sequence of letters, digits, dollars($) and underscore characters(_) signed char ch2; do { put_char( ch, len ); if ( (ch2 = get_peek()) == '[' ) { m_nPrevChar = get_char(); break; } else ch = get_char(); } while ( ch > ' ' ); m_strTokenWord[len] = 0; if ( !is_key ) { m_nTokenLen = len; return VT_IDENTIFER; } int index = map_var_tokens( m_strTokenWord ); return index < NUM_VAR_TOKENS ? index : VT_NONE; }