diff -r a1d9c206409e -r e53b93cd90e4 stage1_2/iec.flex --- a/stage1_2/iec.flex Mon May 16 11:57:41 2011 +0200 +++ b/stage1_2/iec.flex Mon May 16 12:36:21 2011 +0200 @@ -179,16 +179,33 @@ result = YY_NULL;\ } + +/* A counter to track the order by which each token is processed. + * NOTE: This counter is not exactly linear (i.e., it does not get incremented by 1 for each token). + * i.e.. it may get incremented by more than one between two consecutive tokens. + * This is due to the fact that the counter gets incremented every 'user action' in flex, + * however not every user action will result in a token being passed to bison. + * Nevertheless this is still OK, as we are only interested in the relative + * ordering of tokens... + */ +static long int current_order = 0; + + /* Macro that is executed for every action. * We use it to pass the location of the token * back to the bison parser... */ #define YY_USER_ACTION {\ - yylloc.first_line = current_tracking->lineNumber;\ - yylloc.first_column = current_tracking->currentTokenStart;\ - yylloc.last_line = current_tracking->lineNumber;\ - yylloc.last_column = current_tracking->currentChar - 1;\ - current_tracking->currentTokenStart = current_tracking->currentChar;\ + yylloc.first_line = current_tracking->lineNumber; \ + yylloc.first_column = current_tracking->currentTokenStart; \ + yylloc.first_file = current_filename; \ + yylloc.first_order = current_order; \ + yylloc.last_line = current_tracking->lineNumber; \ + yylloc.last_column = current_tracking->currentChar - 1; \ + yylloc.last_file = current_filename; \ + yylloc.last_order = current_order; \ + current_tracking->currentTokenStart = current_tracking->currentChar; \ + current_order++; \ } @@ -858,7 +875,13 @@ * the first one (i.e. the one that gets stored in include_stack[0], * which is never free'd! */ - free((char *)current_filename); + /* NOTE: We do __NOT__ free the malloc()'d memory since + * pointers to this filename will be kept by many objects + * in the abstract syntax tree. + * This will later be used to provide correct error + * messages during semantic analysis (stage 3) + */ + /* free((char *)current_filename); */ current_filename = include_stack[include_stack_ptr].filename; yy_push_state(include_end); }