Jack Compiler

There are 10 types of programmers in the world, those who have written a compiler and those who can’t read binary.

I’ve never written a compiler. At college, I had to drop the class because of a conflict and have always wanted to write one ever since. Even if just to say that I can.

The Elements of Computing Systems has a chapter focusing on building a compiler for the computer that is built throughout the book. The compiler is for an object oriented language called Jack.

Jack, the language, is designed to be simple enough to make the compilation process easier, but that doesn’t mean that it’s not an expressive language. In later chapters in the book, Jack is used to implement parts of the OS and other applications.

The grammar is easy enough and the author claims that it’s almost an LL(0) requiring only a look-ahead token in parsing expressions. The parser for it is a simple recursive descent parser.

I tried to conform to how the book does things, but preferred to do my own thing if it made more sense. It’s also still a work-in-progress and I’ll keep on working on it as time allows.

This is not a full compiler and is definitely no where near real compilers, but it’s a start. And I’d like to dedicate it to my muse without whom I would’ve given up a long time ago.

You can find the code over at my github repository at https://github.com/alaasalman/jackcompiler.

Book Review: From Program To Product

Two years ago, I learned that you can be a brilliant programmer and write awesome code but if your code doesn’t help solve some problem or doesn’t ease someone’s pain, then you’re not really doing your part.

This is exactly the lesson that this book tries to drive home. It goes through the different aspects of creating a product from the programming and support to the licensing and legal side. The book also includes several interviews with people who have already done that. Personally, I found the interviews the most enjoyable part of it all.

The interesting part, to me, in all of this is the applications described in those interviews were really boring. As a programmer, they’re not exactly the kind of work that we love to do. I mean come on, a product to manage a stable? Tracking horses and lessons? Zzzzzz…. Not exactly the kind of work that would keep you up coding all night long. However, the applications were a success because they helped people to do their job better. They eased the pain of doing those things manually and, who knows, maybe gave someone less stress and more time to spend with their family. That is certainly what computers and programs are meant to do. To help us do what we’re supposed to do. And we’re all here to do what we’re all here to do.(The Matrix reference)

It took me a while to learn that lesson. I first noticed it when, as a freelancer, I had to work on a few jobs just to pay the bills. The tasks weren’t enjoyable to me as a programmer, I was just doing it for the money. And as a programmer, a lot of those tasks were very simple to do. Yet the people who I worked with were very grateful that I helped. And, as a business and a person, there’s nothing like a happy customer.

On the cons side of things, this wasn’t exactly a page-turner. Don’t get me wrong, the book is interesting. But recently I’ve been reading a lot of books about entrepreneurship and starting a business. And aside from the inspiration, once you’ve read one, you’ve read them all.

Overall, I give this book 3/5 stars. You can get the book from From Program to Product: Turning Your Code into a Saleable Product (Expert’s Voice).

Ugly code

Was writing some code today and ended up with “Dictionary<string, List<Dictionary<string, string>>> resultDictionary”

Does anyone else think that this is hideous? It’s a dictionary keyed by strings and holding lists of dictionaries keyed by strings and holding strings. And it is what you get when you have a statically typed language(C#) and no native dictionaries.

The code is trying to build a tree to encode as JSON to pass to javascript to represent as a tree widget…try saying that ten times.

I know what you’re thinking…and no, the code is no longer there, it only survived for a few mins before another iteration replaced it with something less icky..I tend to use evolutionary steps and refactor as i go.

Joining SpringerLink pdfs

My workplace has a subscription to SpringerLink. So I’ve been having a blast looking at the different books over there. I found lots of books that are on my Amazon wish list and so i was like a child at a candy store.

The problem is that the books are provided via separate pdf files for chapters. I am not sure why they do that, I think to make it tougher to pirate the files? Although that doesn’t really make any sense. Regardless, it is a bit annoying and I’d like to have the books as one pdf to transfer over to my trusty Sony Reader(more about it later) to read them while on the go.

So i hacked up a python script to rename the individual files by their chapter number making it easier to join. I then hacked up another script that reads these files and joins them in correct order into one file. Sadly, the scripts are only tested on Linux and will probably only run there. The first version used pyPDF and was probably cross-platform, but it had some problems with the pdfs so i reverted to using pdftotext that, as far as i know, only runs under a GNU Linux system.

This is what the code looks like for the script that does the renaming.

This is what the code looks like for the script that does the joining. pyPDF is needed for this to function.

You can download the scripts from the My Projects section. The code will be licensed under the GNU GPL.

You can check the code in its updated glory at my github account.

Note to publishers, you really should step into the 21st century. Especially for the technical books, I really don’t want to pay shipping costs that are more than the price of the book, the printing costs and all the other unneeded crap…I just want the content. This is especially true for technical books that get outdated very quickly such as books about frameworks.

#barcamp-lebanon Conclusion

BarCamp-Lebanon was great yesterday. Met some interesting people. Attended some interesting sessions(except for the 3rd one which was a waste of my time, notice no coverage) and was surprised at the abundance of geeks and geekets attending. And speaking of things that were good, that veggie pizza was great….

We also all agreed that we need more barcamps, more meet ups and more gatherings like this. To facilitate collaboration between entrepreneurs, hackers, and geeks in general. Very exciting indeed…

I feel like a 90 year old today and I’m paying the price of all of yesterday’s excitement. So forgive me my uploading speed….next up, the photos.

I’d like to thank the organizers of BarCamp-Lebanon, especially David and Sami. If you’d like to know more about the barcamp, you can visit the wiki page at BarCamp-Lebanon.

Session2 at #barcamp-lebanon, organizing hacker meetup

Just 4 people in attendance…oooh, not a lot of people want to meet up, what does that mean?
Would like to organize hacker meet ups for coding challenges, general coding….

Gathering ideas about this issue and getting feedback. Interesting. Presenter saying, “programming sucks”…really? I don’t think so.

Also talking that we should have meet ups for sharing knowledge…completely agree. Building up tech meet ups that are fun.

Somebody pitching something called lebgeeks in this session to get more feedback.
I am all in for it.