Re: Redirect stdin ?
- From: jameskuyper@xxxxxxxxxxx
- Date: Mon, 31 Dec 2007 10:00:39 -0800 (PST)
Lothar Behrens wrote:
Hi,
I have a c application (Lex&Yacc based) that parses from stdin. I want
to rewrite the code
a bit to allow reading the source from a char array instead from stdin
without touching the
lex and yacc generated source code.
How could I do that ?
lex uses three macros that can be #defined by the user named 'input',
'unput' and 'output'. It is designed with the intention that you can
override those macros as needed to define different input sources. I
don't know if that meets your needs; it requires a change in the
source code you give to lex, which means that lex will generate
different output code, which is technically a violation of your
requirements. Depending upon the reasons for your requirements, it
might be better to modify your requirements than to use the more
complicated approaches needed to conform to those requirements.
What is about the problem when the buffer is too big to feed the
source to the parser at once ?
Your 'input' macro could refer to a function that stores only as much
of the file as can actually fit into your buffer at any given time. As
long as your buffer is a least big enough to hold the longest look-
ahead required by your grammar, that shouldn't be a problem.
.
- Follow-Ups:
- Re: Redirect stdin ?
- From: Lothar Behrens
- Re: Redirect stdin ?
- References:
- Redirect stdin ?
- From: Lothar Behrens
- Redirect stdin ?
- Prev by Date: Re: How to deal with big-size files??
- Next by Date: Re: Redirect stdin ?
- Previous by thread: Re: Redirect stdin ?
- Next by thread: Re: Redirect stdin ?
- Index(es):
Relevant Pages
|