Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.compilers    |    Compiler construction, theory, etc. (Mod    |    2,753 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 1,615 of 2,753    |
|    Eric Fowler to All    |
|    Last problem is solved    |
|    29 Mar 09 13:32:34    |
   
   From: eric.fowler@gmail.com   
      
   I wrote recently with a question about mapping from a found token back   
   to that token's point in the input stream. I solved it on my own in   
   the meantime.   
      
   The solution was basically as follows:   
      
   - Maintain a pointer to the head of the string to be parsed (I am   
   using an API that inputs string data, not a file), "s_input"   
   - Maintain a running total of bytes, "n_offset", fed to the lexer as a   
   static variable updated within the input() function   
   - Use the variables in YY_CURRENT_BUFFER and do a little pointer   
   arithmetic to extract the desired information, as follows:   
      
   inline const char * buf_offset()   
   {   
   return s_input + (in_offset - (YY_CURRENT_BUFFER)->yy_n_chars) +   
   (yytext - (YY_CURRENT_BUFFER)->yy_ch_buf);   
   }   
      
   Thanks   
      
   Eric   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca