VPR-6.0

vpr/SRC/util/token.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_token

Typedefs

typedef struct s_token t_token

Enumerations

enum  e_token_type {
  TOKEN_NULL, TOKEN_STRING, TOKEN_INT, TOKEN_OPEN_SQUARE_BRACKET,
  TOKEN_CLOSE_SQUARE_BRACKET, TOKEN_OPEN_SQUIG_BRACKET, TOKEN_CLOSE_SQUIG_BRACKET, TOKEN_COLON,
  TOKEN_DOT
}

Functions

t_tokenGetTokensFromString (INP const char *inString, OUTP int *num_tokens)
void freeTokens (INP t_token *tokens, INP int num_tokens)
boolean checkTokenType (INP t_token token, OUTP enum e_token_type token_type)
void my_atof_2D (INOUTP float **matrix, INP int max_i, INP int max_j, INP char *instring)

Detailed Description

Jason Luu July 22, 2009 Tokenizer

Definition in file token.h.


Typedef Documentation

typedef struct s_token t_token

Definition at line 22 of file token.h.


Enumeration Type Documentation

Enumerator:
TOKEN_NULL 
TOKEN_STRING 
TOKEN_INT 
TOKEN_OPEN_SQUARE_BRACKET 
TOKEN_CLOSE_SQUARE_BRACKET 
TOKEN_OPEN_SQUIG_BRACKET 
TOKEN_CLOSE_SQUIG_BRACKET 
TOKEN_COLON 
TOKEN_DOT 

Definition at line 12 of file token.h.


Function Documentation

boolean checkTokenType ( INP t_token  token,
OUTP enum e_token_type  token_type 
)

Definition at line 128 of file token.c.

                                                                             {
        if(token.type != token_type) {
                return FALSE;
        }
        return TRUE;
}

Here is the caller graph for this function:

void freeTokens ( INP t_token tokens,
INP int  num_tokens 
)

Definition at line 95 of file token.c.

                                                         {
        int i;
        for(i = 0; i < num_tokens; i++) {
                free(tokens[i].data);
        }
        free(tokens);
}

Here is the caller graph for this function:

t_token* GetTokensFromString ( INP const char *  inString,
OUTP int *  num_tokens 
)

Returns a token list of the text for a given string.

Definition at line 19 of file token.c.

{
        const char *cur;
        t_token * tokens;
        int i, in_string_index, prev_in_string_index;
        boolean has_null;
        enum e_token_type cur_token_type, new_token_type;

        *num_tokens = i = 0;
        cur_token_type = TOKEN_NULL;

        if(inString == NULL) { return NULL; };

        cur = inString; 

        /* Count number of tokens */
        while(*cur)
        {
                new_token_type = GetTokenTypeFromChar(cur_token_type, *cur);
                if(new_token_type != cur_token_type) {
                        cur_token_type = new_token_type;
                        if(new_token_type != TOKEN_NULL) {
                                i++;
                        }
                }
            ++cur;
        }
        *num_tokens = i;

        if(*num_tokens > 0) {
                tokens = my_calloc(*num_tokens + 1, sizeof(t_token));
        } else {
                return NULL;
        }

        /* populate tokens */
        i = 0;
        in_string_index = 0;
        has_null = TRUE;
        prev_in_string_index = 0;
        cur_token_type = TOKEN_NULL;

        cur = inString; 

        while(*cur)
        {
            
                new_token_type = GetTokenTypeFromChar(cur_token_type, *cur);
                if(new_token_type != cur_token_type) {
                        if(!has_null) {
                                tokens[i-1].data[in_string_index - prev_in_string_index] = '\0'; /* NULL the end of the data string */
                                has_null = TRUE;
                        }
                        if(new_token_type != TOKEN_NULL) {
                                tokens[i].type = new_token_type;
                                tokens[i].data = my_strdup(inString + in_string_index);
                                prev_in_string_index = in_string_index;
                                has_null = FALSE;                               
                                i++;
                        }
                        cur_token_type = new_token_type;
                }
                ++cur;
                in_string_index++;
        }

        assert(i == *num_tokens);

        tokens[*num_tokens].type = TOKEN_NULL;
        tokens[*num_tokens].data = NULL;

    
        /* Return the list */ 
        return tokens;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void my_atof_2D ( INOUTP float **  matrix,
INP int  max_i,
INP int  max_j,
INP char *  instring 
)

Definition at line 138 of file token.c.

                                                                                         {
        int i, j;
        char *cur, *cur2, *copy, *final;
        int string_count;

        copy = my_strdup(instring);
        final = copy;
        while(*final != '\0') {
                final++;
        }


        cur = copy;
        i = j = 0;
        while(cur != final) {
                string_count = 0;
                while(IsWhitespace(*cur) && cur != final) {
                        if(j == max_j) {
                                i++;
                                j = 0;
                        }
                        cur++;
                }
                if(cur == final) {
                        break;
                }
                cur2 = cur;
                while(!IsWhitespace(*cur2) && cur2 != final) {
                        cur2++;
                }
                *cur2 = '\0';
                assert(i < max_i && j < max_j);
                matrix[i][j] = atof(cur);
                j++;
                cur = cur2;
                *cur = ' ';
        }

        assert ((i == max_i && j == 0) || (i == max_i - 1 && j == max_j));
        
        free(copy);
}

Here is the call graph for this function:

Here is the caller graph for this function: