Re: How to get at the entire input buffer string from inside lexer?

m.helvensteijn@gmail.com
Sun, 29 Mar 2009 11:38:20 -0700 (PDT)

          From comp.compilers

Related articles
How to get at the entire input buffer string from inside lexer? eric.fowler@gmail.com (Eric Fowler) (2009-03-28)
Re: How to get at the entire input buffer string from inside lexer? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-03-29)
Re: How to get at the entire input buffer string from inside lexer? m.helvensteijn@gmail.com (2009-03-29)
Re: How to get at the entire input buffer string from inside lexer? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2009-03-29)
Re: How to get at the entire input buffer string from inside lexer? eric.fowler@gmail.com (Eric Fowler) (2009-03-30)
| List of all articles for this month |

From: m.helvensteijn@gmail.com
Newsgroups: comp.compilers
Date: Sun, 29 Mar 2009 11:38:20 -0700 (PDT)
Organization: Compilers Central
References: 09-03-105
Keywords: lex
Posted-Date: 29 Mar 2009 18:40:28 EDT

> [Assuming you're using flex, redefining YYINPUT is almost never the
> right thing to do. My suggestion would be to read the string
> yourself, compute the checksum, then feed the string to flex with
> yy_scan_bytes or yy_scan_buffer. -John]


Agreed. The checksum thing has nothing to do with flex. So you need to
feed flex the string (rather than the filename) after you've checked
it yourself. If I may make a suggestion, you can make flex read from a
C++ input stream you provide with a parameter. From the outside, that
can be a file stream or a string stream, whatever you want. This is,
perhaps, preferable to the C alternative.


#define YY_INPUT(buf, result, max_size) { \
        yyextra->get(buf, max_size, EOF); \
        result = yyextra->gcount(); \
}


yyextra is a pointer to the stream object, which is passed to the
scanner using (%option extra-type="istream*"). For more info, visit:


http://flex.sourceforge.net/manual/Extra-Data.html


I use this in my own compiler. Well, in fact, my yyextra is a struct
which also contains an object to report errors to and an entry point
token that flex is instructed to send out first:


http://www.gnu.org/software/bison/manual/html_mono/bison.html#Multiple-start_
002dsymbols


I guess that's a bit off-topic, but still interesting, I think.



Post a followup to this message

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