Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would recommend against Ruby and Javascript (R I don't know enough about) for a first attempt.

I'm working on a Ruby compiler (http://hokstad.com/compiler). An interpreter is far easier, but still a huge amount of work. I'm sure it'd be fun, but I'd suggest trying a smaller/simpler project first and then revisit Ruby or JS.

Ruby is an absolute nightmare to parse. Both Ruby and Javascript have complex execution models that seem deceptively simple at first glance. They're quagmire's.

If you do want to do something Ruby-like, define a cut-down version. E.g. write down a grammar that covers the most important subset of Ruby that you use, and similarly define a small set of the core functionality. Parsing 80% of Ruby is easy. Chances are you've never used or seen most of the remaining 20% outside of rants about the complexity of the Ruby grammar. E.g. the plethora of ridiculous supported mechanisms for quoting text that allows you to do criminally unreadable stuff like "% x " (which, excluding the double-quotes parses as the string "x", as "%" introduces a quoted sequence started and terminated by the character after "%", except if the character is one of a set of exceptions of various kinds; this of course only when it occurs in a context when it can't be parsed as the infix modulo operator....)

You can write a full compiler for a simpler language in the space it takes to just parse Ruby.

You could probably define a suitably small cut-down version of Ruby that'd still be fun/usable relatively easily, especially if you're not concerned about actually being compatible.



Lua might be a decent language to write an interpreter or compiler for.

It's a fairly small language and I've seen enough re-implementations of it that there some is evidence that writing a new version is reasonably doable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: