|Source for compiler using yacc/lex wanted email@example.com (1996-03-05)|
|Re: Source for compiler using yacc/lex wanted Steve_Kilbane@cegelecproj.co.uk (1996-03-08)|
|Re: Source for compiler using yacc/lex wanted firstname.lastname@example.org (1996-03-08)|
|Re: Source for compiler using yacc/lex wanted email@example.com) (1996-03-15)|
|Re: Source for compiler using yacc/lex wanted firstname.lastname@example.org (1996-03-22)|
|Re: pretty-printing with yacc and lex email@example.com (Scott Stanchfield) (1996-03-22)|
|From:||firstname.lastname@example.org (Pete Jinks)|
|Date:||8 Mar 1996 00:10:47 -0500|
|Organization:||Dept of Computer Science, University of Manchester, U.K.|
Fauzan Mirza <email@example.com> wrote:
>I'm writing a code beautifier program (ie, something similar to indent(1))
>1. Can anyone explain how this could be done using yacc or lex?
I use something similar to this as a lab exercise, introducing
undergraduates to lex. Maybe you would like to take a look at:
This doesn't contain the answer, but it does contain some very big
hints as to what to do.
I tell my students very clearly that lex is not sufficient by itself,
and to do a good job they would really need to use something extra,
such as yacc.
Our moderator writes:
>[I actually think that lex and yacc are lousy tools to use for a pretty
>printer, because they throw too much information away.
If you have some actions in the lex (e.g. doing things with newlines
and comments) as well as in the yacc (e.g. spotting the ends of
control structures that don't have an explicit terminating keyword),
and as long as you are careful about lookahead, then surely you should
be able to do just about anything you want?
[Not really, for the reasons outlined in the previous message on this topic.
C has a two-level grammar, and the techniques you use to parse it don't lend
themselves to recreating the source code. -John]
Return to the
Search the comp.compilers archives again.