The Jack Programming Language

Compiler and Virtual Machine

The Jack Language

Jack is an educational programming language created by Shimon Schocken and Noam Nisan for the course The Elements of Computing Systems, also known as Nand2Tetris, offered by The Hebrew University of Jerusalem. Students are asked to build their own compilers for this object-oriented language.

Compilation

The Jack language is compiled in a two-tier process: Two tier compilation process. from the book *Compilers: Principles, Techniques and tools*

The code is first translated to an intermediate program (like Java's bytecode and C#'s Intermediate Language) and then a Virtual Machine Translator finishes the compilation process either by interpreting the VM code or by translating to the target's machine assembly language.

Build (Linux Only)

On the parent directory:

Compilation

Compile from Jack to VM

Interpret the VM code

Hello, World

Hello world program in Jack

Save the file as Main.jack and run

This will compile all source files in the current folder. Run

To interpret the VM files produced in the current folder

Output:

Features

Jack is a Turing-complete, object-oriented language, with most of the features that any modern language has, such as branching, loops, assignments, arrays, classes, methods, arithmetic operations and more.

Syntax

Jack has a C-like syntax. Reserved words in Jack are:

  
thisfield
staticconstructor
methodfunction
intchar
booleanvar
letdo
whileif
elsereturn
truefalse
nullvoid

Arrays

Output

Object Oriented features

In Dog.jack:

In Main.jack:

Compile && Run

Output