Last problem is solved

Eric Fowler <>
Sun, 29 Mar 2009 13:32:34 -0700

          From comp.compilers

Related articles
How to get at the entire input buffer string from inside lexer? (Eric Fowler) (2009-03-28)
Last problem is solved (Eric Fowler) (2009-03-29)
| List of all articles for this month |

From: Eric Fowler <>
Newsgroups: comp.compilers
Date: Sun, 29 Mar 2009 13:32:34 -0700
Organization: Compilers Central
References: 09-03-105
Keywords: lex
Posted-Date: 29 Mar 2009 18:41:27 EDT

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);



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.