コード例 #1
0
ファイル: Scanner.cpp プロジェクト: CSE220Team21/Lab5
void Scanner::getWord(char *str, char *token_ptr, Token *tok)
{
    /*
     Write some code to Extract the word
     */
    char ch = *line_ptr;
    while ((char_table[ch] == LETTER) || (char_table[ch] == DIGIT))
    {
        *token_ptr++ = *line_ptr++;
        ch = *line_ptr;
    }
    *token_ptr = '\0';
    
    //Downshift the word, to make it lower case
    downshiftWord(str);
    
    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */
    if (!isReservedWord(str, tok))
    {
        //set token to identifier
        tok->setCode(IDENTIFIER);
    }
    tok->setTokenString(string(str));
}
コード例 #2
0
ファイル: Scanner.cpp プロジェクト: achasse/Lab5
void Scanner::getWord(char *str, char *token_ptr, Token **tok)
{
    /*
     Write some code to Extract the word
     */
    char ch = *line_ptr;
    while ((char_table[ch] == LETTER) || (char_table[ch] == DIGIT))
    {
        *token_ptr++ = *line_ptr++;
        ch = *line_ptr;
    }
    *token_ptr = '\0';
    
    //Downshift the word, to make it lower case
    downshiftWord(str);
    
    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */
     
    //This is not working properly. 
    TokenCode code;
    if (isReservedWord(str, &code))
    {
        //NOT an identifier
	*tok = new Token(code);
        (*tok)->setTokenString(string(str));
    }
    else
    {
    	*tok = new IdentifierToken(string(str));
    }
}
コード例 #3
0
ファイル: Scanner.cpp プロジェクト: jcurless/CSE220
void Scanner::getWord(char *str, char *token_ptr, Token **tok)
{
    /*
     Write some code to Extract the word
     */
    char ch = *theLinePtr;
    while ((char_table[ch] == LETTER) || (char_table[ch] == DIGIT))
    {
        *token_ptr++ = *theLinePtr++;
        ch = *theLinePtr;
    }
    *token_ptr = '\0';
    
    //Downshift the word, to make it lower case
    downshiftWord(str);
    
    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */
    const RwStruct *rw_ptr = reservedWord(str);
    if (rw_ptr == NULL)
    {
        //set token to identifier
        *tok = new Identify();
    }
    else
    {
        *tok = new Token();
        (*tok)->setCode(rw_ptr->token_code);
    }
    (*tok)->setTokenString(string(str));
}