Re: A Readable C Code without #DEFINEs ...



On Wed, 19 Oct 2005 18:01:26 +0000, Bahram wrote:

> Folks,
>
> I am using LEX and YACC and they produce this grossly unreadable C code
> that is infested with #define this and #define that.
>

So don't read it. It was produced for the compiler to read, not for
humans.

> The code is unreadable and I need to make changes to it for the
> particular project I am working on.
>

Hopefully the input files are readable, and you can change those.

If the output was a true one off, modifying it might be acceptable, but
that is a very rare case. Imagine if you modified the output and someone
else then changed the input files and reran lex/yacc. How would you fix
the resulting mess?

If you read up on lex/yacc you will probably find a way to get it to do
what you want. E.g. you can put in declarations of variables/functions of
your own at the top of the files and refer to them in rules later on.

> Is there a switch is C, or, if you know about a hidden switch in either
> lex or yacc, that would produce a final human readable code that I can
> make sense out of, PLEASE.
>

If you really want to eliminate the pre-processor parts, you could look at
your compiler documentation. gcc (and others IIRC)offer a -E switch to do
this. But it is unlikely the results would qualify as human readable.

HTH

Simon Bone
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.



Relevant Pages

  • Re: How to generate parser from *.l and *.y files?
    ... I have input files for lex and yacc. ... Perl code from these files? ...
    (comp.lang.perl.misc)
  • Re: Redirect stdin ?
    ... get a workaround (as of I wouldn't be aware of Lex & Yacc a bit) ... generated code from lex and yacc". ... One interpretation is that you do not want to hand-modify the C code ... yacc would generate would take the supplied input routine into account. ...
    (comp.lang.c)
  • 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: 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)