Hacker News new | ask | show | jobs
by jerf 4007 days ago
"It's just that the difference between wisdom and intelligence is in knowing when not to use that brilliant technique you know."

Which is precisely why I've never written a full compiler, even though I've written all the pieces many times.

For instance, instead of writing a parser, could you perhaps get away with just a direct JSON serialization of some AST? Do you really need to emit something, or will an interpreter do? So far I've never been so backed against the wall that I've actually needed a full compiler.

2 comments

Yeah, one of the compilers I wrote just used JSON as the AST, with it being generated by a GUI interface. Another used HTML with annotations (although go figure, I wrote an HTML parser [1] for it, because there weren't any C++ options at the time that didn't bring along a browser engine). A third had a custom front-end but then emitted Java source code as the back-end.

The interesting thing is that the more experience you get, the more alternatives you find to writing your own language. Could you use Ruby or Python as the front-end, much like Rails [2], Rake [3], or Bazel [4]? Could you build up a data-structure to express the computation, and then walk that data-structure with the Interpreter pattern? [5] Could you get away with a class library or framework, much like how Sawzall has been replaced by Flume [6] and Go libraries within Google?

In general, you want to use the tool with the least power that actually accomplishes your goals, because every increase in power is usually accompanied by an increase in complexity. There are a bunch of solutions with less power than a full programming language that can still get you most of the way there.

[1] https://github.com/google/gumbo-parser

[2] http://rubyonrails.org/

[3] http://rake.rubyforge.org/

[4] http://bazel.io/

[5] https://en.wikipedia.org/?title=Interpreter_pattern

[6] http://pages.cs.wisc.edu/~akella/CS838/F12/838-CloudPapers/F...

I'm doing this now, for a crappy language and a crappy processor. It's been a nightmarish hellscape of a project, but also very expanding. Highly recommend.

(If you're interested in goofing around with Starfighter, you're going to get an opportunity to get handheld through a lot of this stuff.)