Lothar Behrens said:
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.