Building a compiler

I finally decided to embark on the journey of building a real compiler to better understand how various pieces work under the hood. I'm particularly interested in error reporting, intermediate representation and code optimization.

I'll be following the guidance from Crafting Interpreters online book which so far proved to be quite easy to follow and full of fascinating facts from programming history.

I'm planning not to follow the steps in the book too closely but rather pick the way that I feel makes most sense to optimize my learning and venture deeper into the topics I consider interesting. The first such change is using Python instead of Java for the interpreter implementation. As far as I can tell, this shouldn't be a big deal, but I hope it will help me to get a bit more familiar with Py3 and modern tooling like static type checking.

As I go through it, I want to share some of the detours I'll be taking on this blog, so stay tuned!

Neat tmux alias

Trying to streamline my workflow with tmux I've built a useful bash alias tmx. This alias takes a single argument - name of the session, and connects to the session if it already exists, or creates a new session with this name. The motivation behind it is that it is shorter (no need to remember and type attach -t or new-session -s), and also involves less cognitive overhead (no conditional thinking).

Here is a snippet of shell code that you can add to your .bashrc/.zshrc/etc:

function tmx {
    name=$1
    if tmux list-sessions | grep -q "^${name}:"; then
        tmux attach -t "${name}"
    else
        tmux new-session -s "${name}"
    fi
}

First, we list all available tmux sessions and then use grep to look for the one, that has provided name. If this search succeeds, the return code of grep is zero and we go to the first branch of the if statement and connect to the existing session. Otherwise, the return code is non-zero and we go to the second branch that creates a new session.

There is one tricky corner-case that needs to be considered, and I leave it to readers to discover it :) (what happens if there are currently no sessions?)

With this alias, connecting to a tmux session Blog is as easy as:

tmx Blog

One additional big plus of this alias comes if you're using tmux over ssh connection (and who doesn't? :)). To connect or create a tmux session Blog on the remote machine you can use:

ssh <hostname> -t tmx Blog

For this to work don't forget to put tmx alias to the top of .bashrc if you're using bash or to .zshenv if you're using zsh.

Next step would be to extend tmx to take arbitrary number of arguments, but honestly, I haven't yet encountered situation when I need it.

This and other useful aliases that I'm using everyday can be found in my dotfiles repository on Github.

Thank you for reading, stay tuned!