Parsing PHP in Go
stephensearles.com
stephensearles.com
It's not in Go, but it does a lot of the interesting things you asked about: static analysis, dead code elimination, transpiling. It also compiles to (pretty poor) C code.
For static analysis, there's a lot to do. Here's my PhD on the topic: http://paulbiggar.com/research/#phd-dissertation
I worked on this for about 4 years, and if my experience is indicative of working on PHP compilers is general, you have a lot of fun, and a massive amount of frustration in front of you.
Anthony Ferrara used it to implement PHP in PHP: https://github.com/ircmaxell/PHPPHP
[0] http://www.confreaks.com/videos/3432-gophercon2014-go-from-c...
Ruby in Go: https://github.com/grubby/grubby
Javascript in Go: https://github.com/robertkrimen/otto
It seems like the authors of Golang believe that a lot of problems with languages (refactoring, updating code to work with new libraries / versions, etc) can be solved as parsing problems. Hence, Golang has a lot of good tools for parsing text.
They even ported yacc to Go (via Plan9). http://golang.org/cmd/yacc/
Yacc clones exit for almost every language out there, and there are better ways to do parsing than yacc with its stone age error reporting.
I certainly couldn't find any better tools in Golang when I started, but I wouldn't be surprised if someone had started one since.
Parser generators based in attribute grammars is another example.
The language is called Go.
try ./pfff -dump_php /path/to/file.php
C++ (well Hack->C++), .NET, Java, Python and now Go (probably others).
All in various states of incompleteness, though HHVM isn't going away anytime soon.
Not that it would be faster or better than say, HHVM or any other of a number of compilers for PHP [1] but my knowledge of that space is quite limited.
[1] http://stackoverflow.com/questions/1408417/can-you-compile-p...
("Bug-for-bug" here does not mean that PHP has a lot of bugs per se. What it is is the highest level of compatibility. An emulator of a game console strives to be "bug-for-bug" compatible, for instance. Programming and programming languages being what they are, anything less often turns out to be surprisingly non-linearly less useful, i.e., "80% compatible" isn't anywhere near "80% useful".)
But I admit, I read the Ocaml and haskell compilers source code, and it was pretty nice.
This could be a crucial tool for companies backporting legacy PHP code into a new language.
However I will say that the VB6->VB.Net transpiler which Microsoft produced (and clearly spent significant amounts of effort on) was pretty terrible. And that is one of the most "complete" transpilers I know of...
The problem is that for a transpiler to produce "good" output code it needs to have a deep understanding of both context but also intent. This is particularly important when converting from one language to another with slightly different underlying concepts (like VB5-6 Vs. VB.Net). Without that understanding it just produces spaghetti code, that will technically compile (*although often it didn't in the VB6->VB.net example) but is unmaintable.
I liken it to Microsoft Word's HTML engine. Word can produce websites, and those websites technically looked correct in most browsers, but they became an unmaintainable mess in the medium to long term. A lot of transpilers have the same issue.
The best thing I can say about transpilers is that they're very good for a starting point (assume 100% refactoring anyway) and converting simplistic data storage vehicles (e.g. classes with tons of constants).
Word and Frontpage used the same COM code based on trident (IE). Frontpage is dead, the successor Expression Web used a new HTML engine and is dead as well. The second Frontpage successor that still used the trident engine was Sharepoint Designer 2007. Version 2010+ lacks most layout features as the old Frontpage based code generated ugly HTML4. Word 2010 (and probably also 2013) still generates (ugly) HTML4 with inlined VML (graphics, WordArt) based on older trident.
And there is also InfoPath 2003-2013 (dead as of 2014) that is based on a modified Frontpage/trident code. It uses CAB based archive format to store XML and XSD files that resemble the user defined form data. The InfoPath WebForms are generated server side based on the XML stylesheet and XML data. Microsoft is working on a successor to InfoPath merged with other Office products and mobile compatible.