I'm writing a code beautifier program (ie, something similar to indent(1))
and thought that the best approach to take would be to use yacc and lex.
I have figured out how they work and what inputs they take, but I don't
know enough about the details to be able to write the beautifier.

So far I have got some sample code for a simple C language parser (using
cgram.y and scan.l) but I need to be able to, somehow, convert one stream
of tokens to another. For example:

Convert the token sequence:
if ( <Expr> ) <Statement>
To ...
if ( <Expr> ) <Indent> <Statement> <Outdent>
Where Indent and Outdent are special kind of tokens.

Questions:
1. Can anyone explain how this could be done using yacc or lex?
2. If lex = Tokeniser and yacc = Parser, what is the Code Generator?
3. Does anyone know where I can find a simple compiler built using yacc/lex?

Fauzan

======================================================
Fauzan Mirza Department of Computer Science
fauzan@dcs.rhbnc.ac.uk Royal Holloway, Univ of London
======================================================
[I actually think that lex and yacc are lousy tools to use for a pretty
printer, because they throw too much information away. It's not really
a compiling problem, it's more of a pattern matching problem. -John]
--