29
Jan

< Part 4

Up until now, I have been doing a near direct translation of Crenshaws tutorial to Haskell. After reading Andersons paper Parsing with Haskell I realised that Haskell has a very powerful Type system for a reason.

Defining the Types

So let's take a step back and rework what has been done so far using Types and we'll see how much easier, extensible and safer it is to use.

First of all a recap of our language elements we have defined so far.

<expression> ::= <term>[<addop><term>]*
<term> ::= <factor>[<mulop><factor>]*
<factor> ::= <number>

And translating that into ...

0 comments

27
Jan

< Part 3

Operator Precedence

Introducing multiplication and division into out compiler means that we have to think about operator precedence if we want our language implementation to adhere to the general conventions of math.

As it turns out, there is a rather simple trick to this - define term in terms of multiplication.

<term> := <factor>[<mulop><factor>]*

Now we call a single digit a factor, and a term is any result of a multiplication operation involving these factors. What this effectively means is that all multiplication has happened before we get to addition, and thus operator precedence is preserved ...

0 comments

21
Jan

< Part 2

Binary addition and subtraction

Now that we can successfully detect single digits, the next challenge is to extend this to simple addition and subtraction with only two terms. i.e.

<expression> ::= <term>+/-<term>

A term in our compiler, at least at this stage, is just a single digit, so we can rename the existing expression to term. Next we define the add and minus operations. As you can see, they are very simple instructions.

add = emitLn "ADD eax, ebx"
sub = emitLn "SUB eax, ebx" ++ emitLn "NEG eax"

Crenshaws notes that an extra operation to negate the ...

0 comments

12
Jan

< Part 1

Crenshaw starts off with a simple collection of utility functions: error handler; a routine to read from standard in; some simple matching functions for digits and letters; and some routines to emit assembly.

There is an assumption here that you will start off using the command line to test your compiler. However GHC has an interactive mode that I will be using. This makes it easier to experiment and also means we don't really need to worry about IO just yet.

The Cradle

This is the basic framework of utility functions that Crenshaw calls the ...

2 comments

12
Jan

Part 2 >

When looking for information on getting started with learning how to build an interpreter or compiler, inevitably two resources come up. First, the canonical compiler resource, the Dragon Book, and second, the noob guide, Let's Build a Compiler (LBaC) by Jack W. Crenshaw.

So rather than spending time and money diving into the deep end, I decided to start with LBaC. I don't have a CompSci degree so I need to start at the very beginning and LBaC seems to fit the bill.

However there was one problem with LBaC:

This is a "learn-by-doing" series. In ...

0 comments

12
Oct

Site-specific browsers (SSB) have made a bit of a stir recently due to programs like Fluid and Prism. These tools customize a very thin layer over a browser to provide something that looks a like a standard desktop application, complete with a nice icon and entry in the dock or start menu.

SSBs can be used for a variety of sites, but I find they are particularly useful for social networking (Yammer, Twitter etc) and project management sites (Unfuddle, Basecamp etc). This is because these sites tend to present themeselves as applications, with virtually no dependancy on the standard browser ...

0 comments

04
Oct

The Secret to Github at work

You've been able to clone github repositories using http for a while now which allows you to get around proxies at work. But using this method won't allow you to push any changes back, which is a major pain point to using Github behind at my workplace.

Today, a co-worker brought this article from Justin Bailey to my attention, which describes how to use an ssh tunnel over port 443 to get push access to github.

The steps in the above are pretty clear and consice, however I added a few minor changes. Here are the steps I ...

0 comments

01
Oct

It happened. Everybody thinks it won't happen, at least not to them. My hard drive failed. Completely. As in not even able to see it in any recovery tools.

I was happily doing my thing, when everything froze on screen and I got a SBoD. A quick restart later and I got a terrible clicky sound from the hard drive followed by this:

We lost it all. All our photos, the most impossible to replace, our home movies from our travels, our documents like resumes etc., my side projects, the lot. The funny thing is, I have an external ...

0 comments

20
Aug

The Rule of the Second Card

I came across this article by Phillip Calçado wherin he introduces The Rule of the Second Card.

The first card played on a given area of the code base is expected to take a long time. The second card should take at most half of the first card’s time.

This obviously only applies to the first and second card in a new area of work. Because the first card will need some time an planning, possibly some spiking to evaluate potentional solutions, it is expected that the first card in a new feature is going to take longer ...

0 comments

06
Aug

Small Outage Yesterday

UPDATE: Turns out it was an update to 1.2.4 that had

Enhancement to SearchableModel allowing multiple properties to be indexed.

Yesterday my blog was throwing an error and only returning the 'Oops' page for every request.

Turns out somehow the SearchableModel modifications I was using suddenly stopped working.

The dev_appserver still works as expected, but I was getting this error:

File "/base/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1455, in fetch
    raw = self._get_query().Get(limit, offset)
  File "/base/python_lib/versions/1/google/appengine/api/datastore.py", line 981, in Get
    prefetch_count=limit)._Get ...

2 comments