Ejemplo n.º 1
0
int main( )
{


	char string_test[5] = "TeSt";
	Token *token = malloc(sizeof(Token));

	//valid test
	downshift_word(string_test);
	//invalid test
	downshift_word(token);
    return 0;
}
Ejemplo n.º 2
0
static char* get_word(Token* theToken, char token_string[MAX_TOKEN_STRING_LENGTH],char *token_ptr)
{
    /*
     Write some code to Extract the word
     */
     int charCount = 0;
     while((char_table[(*(token_ptr))] == LETTER || char_table[(*(token_ptr))] == DIGIT) && charCount < (MAX_TOKEN_STRING_LENGTH-1))
     {
        token_string[charCount] = *(token_ptr);
        token_string[charCount+1] = '\0';
        charCount++;
        token_ptr++;
     }

    theToken->literal_value = downshift_word(token_string); //Downshift the word, to make it lower case

    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */
     if(is_reserved_word(theToken))
     {
         theToken->literal_type = STRING_LIT;
     }else
     {
         theToken->literal_type = STRING_LIT;
         theToken->token_code = IDENTIFIER;
         theToken->nextToken = NULL;
     }



     return token_ptr;
}
Ejemplo n.º 3
0
static Token *get_word(char token_string[], Token *token2) {
	/*
	 Write some code to Extract the word

	 Downshift the word, to make it lower case

	 Write some code to Check if the word is a reserved word.
	 if it is not a reserved word its an identifier.
	 */

	downshift_word(token_string);

	token2->nextptr = NULL;
	token2->type = STRING_LIT;

	strcpy(token2->token_string, token_string);

	/*
	 >> Write some code to Check if the word is a reserved word.  if it is not a reserved word its an identifier
	 >> use the arrays provided in the source code I gave out to find out if something is a reserved word or not. If not then this token is an identifier
	 */

	is_reserved_word(token_string, token2);

	return token2;
}
Ejemplo n.º 4
0
static struct Token* get_word(char stringwithuppercase[], struct Token *addtoken)
{
    /*
     Write some code to Extract the word
     */
    
    //Downshift the word, to make it lower case
    
    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */ int settokencode;
        LiteralType setliteraltype = STRING_LIT;
		int i,j;
        char stringwithoutuppercase[80];
        strcpy(stringwithoutuppercase, stringwithuppercase);
	downshift_word(stringwithoutuppercase);
       
    
       // int i,j;
        for (i = 0; i < 9; i++)
        {
            for(j = 0; j < 1-0; j++)
            {
                if(strcmp(stringwithoutuppercase,rw_table[i][j].string) == 0)
                    settokencode = rw_table[i][j].token_code;
            }
        }
        addtoken->tokenCode = settokencode;
        addtoken->typeOfLiteral = setliteraltype;
        strcpy((addtoken->LiteralValue),stringwithoutuppercase);
        return addtoken;
}
Ejemplo n.º 5
0
char* get_word(char** original, char ch[], char* ch_ptr, Token* t)
{
    /*
     Write some code to Extract the word
     */
    ch_ptr = ch;
    int i = 1;
    while(isalpha(get_char(original))){
		ch[i] = get_char(original);
		i++;
    }
    ch[i] = '\0';
	
    //Downshift the word, to make it lower case
    downshift_word(ch);
    /*
     Write some code to Check if the word is a reserved word.
     if it is not a reserved word its an identifier.
     */
	if(is_reserved_word(ch, t) == FALSE){
		t -> token_code = IDENTIFIER;
	}
	return ch_ptr;
}
Ejemplo n.º 6
0
struct Token get_word(char c)
{
    struct Token token;
    TokenCode code;
    int i = 1;

    token.literalType = STRING_LIT;
    token.literalValue.valString[0] = c;
    while(char_table[peek_char()] == LETTER || char_table[peek_char()] == NUMBER) {
        c = get_char();
        token.literalValue.valString[i] = c;
        i++;
    }
    while(i < MAX_TOKEN_STRING_LENGTH) {
        token.literalValue.valString[i] = '\0';
        i++;
    }

    downshift_word(token.literalValue.valString);
    code = is_reserved_word(token.literalValue.valString);
    token.tokenCode = (code == NO_TOKEN)? IDENTIFIER : code;

    return token;
}