Re: Source for compiler using yacc/lex wanted

pjj@cs.man.ac.uk (Pete Jinks)
8 Mar 1996 00:10:47 -0500

          From comp.compilers

Related articles
Source for compiler using yacc/lex wanted platon!fauzan@uunet.uu.net (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 pjj@cs.man.ac.uk (1996-03-08)
Re: Source for compiler using yacc/lex wanted nandu@longs.att.com214) (1996-03-15)
Re: Source for compiler using yacc/lex wanted theedge@sun11.rbg.informatik.th-darmstadt.de (1996-03-22)
Re: pretty-printing with yacc and lex scooter@mccabe.com (Scott Stanchfield) (1996-03-22)
| List of all articles for this month |

From: pjj@cs.man.ac.uk (Pete Jinks)
Newsgroups: comp.compilers
Date: 8 Mar 1996 00:10:47 -0500
Organization: Dept of Computer Science, University of Manchester, U.K.
References: 96-03-042
Keywords: yacc, lex

Fauzan Mirza <fauzan@dcs.rhbnc.ac.uk> 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:


http://www.cs.man.ac.uk/~pjj/cs2112/lab211_96_2.html


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]


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.