Search code examples
prologdecompilingdecompiler

If you write a compiler in pure Prolog, will it work as a decompiler also?


If you write a compiler in pure Prolog (no extra-logical bits), will it work as a decompiler also?

(A book I was reading opined on this, but I wonder if anyone has actually tried it)


Solution

  • I once wrote the equivalent of cdecl.org as a reversible program. It was a bit tricky, but I demonstrated that it could be done. (Somewhere in a pile of papers is the source code; one of these days, I hope to publish it on github.) The code was 2 or 3 times as compact at some existing code that used tools such as yacc/lex (bison/flex).

    For something like cdecl -- where you're translating between char ** const * const x and declare x as const pointer to const pointer to pointer to char, compiling/decompiling makes sense. But what does it mean to translate from arbitrary machine code to source code? Even translating between some IR and source code doesn't seem to make a lot of sense.