On 2011-09-22 11:47, Regan Heath wrote:
At one time (2+ years back) I started writing a C lexer, and then C
preprocessor in D. In part to learn about how compilers work and in part
to convert C headers to D (there was no .di at that stage) so I could
interface C. The lexer was no trouble, I even managed to make it
flexible by having it read a C grammar file but when I got to the
preprocessor I lost steam/momentum and it all fell by the way side.

Something I discovered, which may help bootstrap your plans, is that
most C compilers will preprocess source for you and give you the
resulting stream of text, which you can then lex/parse/etc. However,
this results in the C compiler processing macros and following includes,
which you often don't actually want it to do - as you're likely trying
to replicate the file tree (so want to see includes) and trying to
replace macros with CTFE or similar.

So, perhaps a combined approach, tame a compiler and have it preprocess
a file at a time and then use that output, plus the original file to
produce some D replacement code.. not sure if that would work but it
might be worth investigating.

R



I've done something similar using Clang: https://github.com/jacob-carlborg/clang

--
/Jacob Carlborg

Reply via email to