Re: Redirect stdin ?



In article <e4bcc6d9-3b30-46af-875d-e4a44a18a8db@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Lothar Behrens <lothar.behrens@xxxxxxxxxxxx> wrote:

My requirements were not to modify the generated code from lex and
yacc to
get a workaround (as of I wouldn't be aware of Lex & Yacc a bit)

There are two different interpretations to "not to modify the
generated code from lex and yacc".

One interpretation is that you do not want to hand-modify the C code
that lex and yacc generate: if that is the interpretation, then you can
solve the problem along the lines James gave, by altering the input
macros (or, alternately, by supplying your own yyin() routine).
You supply lex and yacc with an input routine and the code lex and
yacc would generate would take the supplied input routine into account.
This is the interpretation of your requirements if the emphasis
in your requirement is on "modify".

The second possible interpretation of your requirement is that
for some reason or other you require that whatever solution is
arrived at must have the lex and yacc sections compile to exactly
the same object code as would be the case if you were working with
a regular file instead of a string. This is the interpretation of
your requirements if the emphasis in your requirements is on
"generated" -- that the *generated* code must be exactly the same.
This might be the case if, for example, you intended to call the same
lex and yacc routines, sometimes supplying input from a string
and sometimes providing input from a file. James noted that
his suggestion did not technically meet your requirements because
if you modify the input macros then even though the C source output
by lex and yacc might look the same (except perhaps a line or two),
when the compiler got through with it, the object code generated
would be different, in violation of your constraint to not modify
the *generated* code: modifying the macros before running lex and
yacc would result in different code being generated. Anyhow, if this
is your requirement, then I believe you could meet the those
terms by supplying your own yyin() function; if I recall, yyin()
is function which is linked against, so the object code would not
change.
--
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth
.



Relevant Pages

  • Re: A Readable C Code without #DEFINEs ...
    ... you feel the need to actually modify the lex or yacc ... your design that prevent you from using these tools correctly. ...
    (comp.lang.c.moderated)
  • Re: A Readable C Code without #DEFINEs ...
    ... > I am using LEX and YACC and they produce this grossly unreadable C code ... Hopefully the input files are readable, ... > Is there a switch is C, or, if you know about a hidden switch in either ...
    (comp.lang.c.moderated)
  • Re: How is a compiler written
    ... >> The Dragon Book is a good one suggestion, ... >> best way to write a compiler is with lex and yacc is not. ...
    (comp.lang.c)
  • Re: A Readable C Code without #DEFINEs ...
    ... either Lex or Yacc. ... Or, yet again, you can obtain the source for various open source ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)