Re: Using FLEX to do macro processing - enhancement to include ... (Vern Paxson)
Fri, 24 Jul 1992 05:35:51 GMT

          From comp.compilers

Related articles
Using FLEX to do macro processing - enhancement to include processing (1992-07-23)
Re: Using FLEX to do macro processing - enhancement to include ... (1992-07-24)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Vern Paxson)
Organization: Lawrence Berkeley Laboratory, Berkeley
Date: Fri, 24 Jul 1992 05:35:51 GMT
Summary: use unput()
Keywords: flex, macros
References: 92-07-077 (Charles D Havener) writes:
> Has there been any discussion about using FLEX to handle macro expansion
> as opposed to just #include type processing as descriobed in the Flex
> manual?
> For example, can I use yy_create_buffer(FILE *file,int size) with a NIL
> FILE * and merely unput() the macro text into this buffer?

This should work as long as you redefine YY_INPUT, too, to not try to read
from yyin. You could instead just use unput() directly with the current
buffer (this is how flex itself expands {name} definitions).

> [Plain unput() might work, though I imagine it'd be more robust to
> redefine YY_INPUT to copy in expanded text when it's reading from a
> buffer corresponding to expanded text. -John]

I'm not sure what's meant here by "more robust". The amount of text that
can be pushed back will be limited to the amount of free space in the
buffer. Except for pathological cases, this will be at least 8KB, as the
buffer is by default 16KB and is filled 8KB at a time.

In general it's hard solving this problem with YY_INPUT instead of
unput(), because the scanner will have already loaded its internal buffer
with quite a bit of data and will have to work its way through it before
it gets around to calling YY_INPUT again. If there are difficulties I'm
missing with just using unput() I'd like to hear about them ...


Vern Paxson
Computer Systems Engineering ucbvax!!vern
Lawrence Berkeley Laboratory (510) 486-7504
[Some PC versions of flex have a much smaller input buffer, on the order
of 256 bytes, which won't always be enough unput space. Agreed, with the
standard 8K buffers unput is perfectly adequate. -John]

Post a followup to this message

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