177 result = GetNextChar(buf, max_size);\ |
177 result = GetNextChar(buf, max_size);\ |
178 if ( result <= 0 )\ |
178 if ( result <= 0 )\ |
179 result = YY_NULL;\ |
179 result = YY_NULL;\ |
180 } |
180 } |
181 |
181 |
|
182 |
|
183 /* A counter to track the order by which each token is processed. |
|
184 * NOTE: This counter is not exactly linear (i.e., it does not get incremented by 1 for each token). |
|
185 * i.e.. it may get incremented by more than one between two consecutive tokens. |
|
186 * This is due to the fact that the counter gets incremented every 'user action' in flex, |
|
187 * however not every user action will result in a token being passed to bison. |
|
188 * Nevertheless this is still OK, as we are only interested in the relative |
|
189 * ordering of tokens... |
|
190 */ |
|
191 static long int current_order = 0; |
|
192 |
|
193 |
182 /* Macro that is executed for every action. |
194 /* Macro that is executed for every action. |
183 * We use it to pass the location of the token |
195 * We use it to pass the location of the token |
184 * back to the bison parser... |
196 * back to the bison parser... |
185 */ |
197 */ |
186 #define YY_USER_ACTION {\ |
198 #define YY_USER_ACTION {\ |
187 yylloc.first_line = current_tracking->lineNumber;\ |
199 yylloc.first_line = current_tracking->lineNumber; \ |
188 yylloc.first_column = current_tracking->currentTokenStart;\ |
200 yylloc.first_column = current_tracking->currentTokenStart; \ |
189 yylloc.last_line = current_tracking->lineNumber;\ |
201 yylloc.first_file = current_filename; \ |
190 yylloc.last_column = current_tracking->currentChar - 1;\ |
202 yylloc.first_order = current_order; \ |
191 current_tracking->currentTokenStart = current_tracking->currentChar;\ |
203 yylloc.last_line = current_tracking->lineNumber; \ |
|
204 yylloc.last_column = current_tracking->currentChar - 1; \ |
|
205 yylloc.last_file = current_filename; \ |
|
206 yylloc.last_order = current_order; \ |
|
207 current_tracking->currentTokenStart = current_tracking->currentChar; \ |
|
208 current_order++; \ |
192 } |
209 } |
193 |
210 |
194 |
211 |
195 /* Since this lexical parser we defined only works in ASCII based |
212 /* Since this lexical parser we defined only works in ASCII based |
196 * systems, we might as well make sure it is being compiled on |
213 * systems, we might as well make sure it is being compiled on |
856 /* removing constness of char *. This is safe actually, |
873 /* removing constness of char *. This is safe actually, |
857 * since the only real const char * that is stored on the stack is |
874 * since the only real const char * that is stored on the stack is |
858 * the first one (i.e. the one that gets stored in include_stack[0], |
875 * the first one (i.e. the one that gets stored in include_stack[0], |
859 * which is never free'd! |
876 * which is never free'd! |
860 */ |
877 */ |
861 free((char *)current_filename); |
878 /* NOTE: We do __NOT__ free the malloc()'d memory since |
|
879 * pointers to this filename will be kept by many objects |
|
880 * in the abstract syntax tree. |
|
881 * This will later be used to provide correct error |
|
882 * messages during semantic analysis (stage 3) |
|
883 */ |
|
884 /* free((char *)current_filename); */ |
862 current_filename = include_stack[include_stack_ptr].filename; |
885 current_filename = include_stack[include_stack_ptr].filename; |
863 yy_push_state(include_end); |
886 yy_push_state(include_end); |
864 } |
887 } |
865 } |
888 } |
866 |
889 |