in reply to Re: Language Conversion
in thread Language Conversion

...for further reading i.e. as the exercise for the interested reader, Steve_BZ could do worse than get a copy of the O'Reilly lex & yacc nutshell reference - IMO, most enlightening.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^3: Language Conversion
by almut (Canon) on Sep 09, 2009 at 17:10 UTC

    ...for even further reading, the next step would be the classical Dragon book on compiler design...

    Essentially, a compiler translates from one language into another — typically from a higher level language to a lower one, but there's no reason (in theory) it couldn't convert from Perl to C++ source. It's just that compilers are usually non-trivial to write, so no one may have done it yet...

    In this particular case (as parsing Perl is a particularly non-trivial task), it would probably be a good idea to reuse existing code (such as the regular source of the Perl interpreter, or PPI) for the side of parsing and constructing a syntax tree.  You'd "just" :) have to add code generation for the target language from the syntax tree, paying particular attention on how to realize the highly dynamic facilities which Perl provides in a more "static" language like C/C++.

      In fact, "The Dragon Book" is the book I refer to in the opening lines of the link I posted earlier (but by it's proper name, "Compilers: Tool Tips and Techniques"). It's great. Huge. Dense. But well written. I will never finish it...

      There's some pretty in depth stuff on lex and yacc in there, too.