VPR-7.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
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)
 

Typedef Documentation

typedef struct s_token t_token

Definition at line 26 of file token.h.

Enumeration Type Documentation

Jason Luu July 22, 2009 Tokenizer

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 10 of file token.h.

Function Documentation

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

Definition at line 126 of file token.c.

126  {
127  if (token.type != token_type) {
128  return FALSE;
129  }
130  return TRUE;
131 }
Definition: util.h:12
Definition: util.h:12

+ Here is the caller graph for this function:

void freeTokens ( INP t_token tokens,
INP int  num_tokens 
)

Definition at line 93 of file token.c.

93  {
94  int i;
95  for (i = 0; i < num_tokens; i++) {
96  free(tokens[i].data);
97  }
98  free(tokens);
99 }

+ Here is the caller graph for this function:

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

Definition at line 18 of file token.c.

18  {
19  const char *cur;
20  t_token * tokens;
21  int i, in_string_index, prev_in_string_index;
22  boolean has_null;
23  enum e_token_type cur_token_type, new_token_type;
24 
25  *num_tokens = i = 0;
26  cur_token_type = TOKEN_NULL;
27 
28  if (inString == NULL) {
29  return NULL;
30  };
31 
32  cur = inString;
33 
34  /* Count number of tokens */
35  while (*cur) {
36  new_token_type = GetTokenTypeFromChar(cur_token_type, *cur);
37  if (new_token_type != cur_token_type) {
38  cur_token_type = new_token_type;
39  if (new_token_type != TOKEN_NULL) {
40  i++;
41  }
42  }
43  ++cur;
44  }
45  *num_tokens = i;
46 
47  if (*num_tokens > 0) {
48  tokens = (t_token*)my_calloc(*num_tokens + 1, sizeof(t_token));
49  } else {
50  return NULL;
51  }
52 
53  /* populate tokens */
54  i = 0;
55  in_string_index = 0;
56  has_null = TRUE;
57  prev_in_string_index = 0;
58  cur_token_type = TOKEN_NULL;
59 
60  cur = inString;
61 
62  while (*cur) {
63 
64  new_token_type = GetTokenTypeFromChar(cur_token_type, *cur);
65  if (new_token_type != cur_token_type) {
66  if (!has_null) {
67  tokens[i - 1].data[in_string_index - prev_in_string_index] =
68  '\0'; /* NULL the end of the data string */
69  has_null = TRUE;
70  }
71  if (new_token_type != TOKEN_NULL) {
72  tokens[i].type = new_token_type;
73  tokens[i].data = my_strdup(inString + in_string_index);
74  prev_in_string_index = in_string_index;
75  has_null = FALSE;
76  i++;
77  }
78  cur_token_type = new_token_type;
79  }
80  ++cur;
81  in_string_index++;
82  }
83 
84  assert(i == *num_tokens);
85 
86  tokens[*num_tokens].type = TOKEN_NULL;
87  tokens[*num_tokens].data = NULL;
88 
89  /* Return the list */
90  return tokens;
91 }
enum e_token_type GetTokenTypeFromChar(INP enum e_token_type cur_token_type, INP char cur)
Definition: token.c:101
void * my_calloc(size_t nelem, size_t size)
Definition: util.c:132
e_token_type
Definition: token.h:10
Definition: util.h:12
char * data
Definition: token.h:24
Definition: token.h:22
enum e_token_type type
Definition: token.h:23
char * my_strdup(const char *str)
Definition: util.c:101
Definition: util.h:12

+ 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 133 of file token.c.

134  {
135  int i, j;
136  char *cur, *cur2, *copy, *final;
137 
138  copy = my_strdup(instring);
139  final = copy;
140  while (*final != '\0') {
141  final++;
142  }
143 
144  cur = copy;
145  i = j = 0;
146  while (cur != final) {
147  while (IsWhitespace(*cur) && cur != final) {
148  if (j == max_j) {
149  i++;
150  j = 0;
151  }
152  cur++;
153  }
154  if (cur == final) {
155  break;
156  }
157  cur2 = cur;
158  while (!IsWhitespace(*cur2) && cur2 != final) {
159  cur2++;
160  }
161  *cur2 = '\0';
162  assert(i < max_i && j < max_j);
163  matrix[i][j] = atof(cur);
164  j++;
165  cur = cur2;
166  *cur = ' ';
167  }
168 
169  assert((i == max_i && j == 0) || (i == max_i - 1 && j == max_j));
170 
171  free(copy);
172 }
boolean IsWhitespace(char c)
char * my_strdup(const char *str)
Definition: util.c:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function: