Joel Reymont <······@gmail.com> writes:
> Does anyone have an example of using the Lisp pretty printer to
> display C, C++ or C# code?
At a previous employer I implemented a limited JavaBean-to-PHP compiler
using ABCL. Unfortunately I'm under NDA and I don't have access to the
code regardless. But the basic steps were:
I used the Reflections API to create internal representations of all the
Java classes, slots, etc. Then for all the CLOS classes, I defined
PRINT-OBJECT methods which called the pretty-printer to output PHP code
implementing classes, accessors, and the like (PHP front-end was using
XML-RPC to talk to the Java layer, so it generated a lot of XML-RPC stub
code). I used PPRINT-LOGICAL-BLOCK and related functions a lot.
Finally I just called FORMAT on the top-level construct (i.e., class
definition instance).
In your case, if you're working with existing code rather than
generating it, you probably won't have to write a complete parser, but
enough of one to recognize the important bits (e.g., #\", #\', "/*").
You can break the code up into nested lists based on the block
delimiters (#\{ and #\}) and use PPRINT-LOGICAL-BLOCK to handle
indentation for you.
That's probably a little bit simpler than writing a full parser and
representation of every C construct. Then you can add indentation
functionality for new constructs as you need them (ternary operators,
argument lists, whatever).
Sorry to be so vague but hope this points you in a good starting
direction.
http://www.franz.com/support/documentation/6.0/ansicl/section/thelispp.htm
--
vsync
http://quadium.net/~vsync/
The beauty of Amendment II is that it protects the ability to deal
with both a tyrannical government and a zombie apocalypse.
-- Eochada,
http://forums.fark.com/cgi/fark/comments.pl?IDLink=2749371
Joel Reymont wrote:
> Does anyone have an example of using the Lisp pretty printer to
> display C, C++ or C# code?
Chapter one of this paper may be helpful:
http://www.merl.com/reports/docs/TR93-17.pdf
On Apr 25, 1:22 am, Joel Reymont <······@gmail.com> wrote:
> Does anyone have an example of using the Lisp pretty printer to
> display C, C++ or C# code?
CLPython contains a pretty printer for Python code (file pprint.lisp).
- Willem